1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-14 03:35:37 +02:00

Detect MSYS2 UCRT64 toolchains for CDT Core Build

This commit is contained in:
John Dallaway 2024-08-16 15:02:05 +01:00
parent 54ebddc01c
commit c4c11ad964
2 changed files with 44 additions and 43 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.build.gcc.core;singleton:=true
Bundle-Version: 2.1.400.qualifier
Bundle-Version: 2.1.500.qualifier
Bundle-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime,

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2023 QNX Software Systems and others.
* Copyright (c) 2016, 2024 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -9,6 +9,7 @@
* SPDX-License-Identifier: EPL-2.0
* Contributors:
* John Dallaway - Support multiple MSYS2 64-bit registry names (#237)
* John Dallaway - Detect UCRT64 toolchains (#887)
*******************************************************************************/
package org.eclipse.cdt.build.gcc.core.internal;
@ -16,8 +17,10 @@ import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
import org.eclipse.cdt.build.gcc.core.GCCToolChain;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
@ -78,30 +81,26 @@ public class Msys2ToolChainProvider implements IToolChainProvider {
private boolean addToolChain64(IToolChainManager manager, WindowsRegistry registry, String key) {
String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
Path msysPath = Paths.get(installLocation);
Path gccPath = msysPath.resolve("mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
if (Files.exists(gccPath)) {
StringBuilder pathVar = new StringBuilder();
pathVar.append(msysPath);
pathVar.append("\\mingw64\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\bin"); //$NON-NLS-1$
IEnvironmentVariable[] vars = new IEnvironmentVariable[] {
new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
File.pathSeparator) };
GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars);
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
manager.addToolChain(toolChain);
return true;
} else {
return addToolChain32(manager, registry, key);
boolean found = false;
for (String variant : List.of("mingw64", "ucrt64")) { //$NON-NLS-1$ //$NON-NLS-2$
Path gccPath = msysPath.resolve(variant + "\\bin\\gcc.exe"); //$NON-NLS-1$
if (Files.exists(gccPath)) {
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars);
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
manager.addToolChain(toolChain);
found = true;
}
Path clangPath = msysPath.resolve(variant + "\\bin\\clang.exe"); //$NON-NLS-1$
if (Files.exists(clangPath)) {
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, clangPath.getParent());
IToolChain toolChain = new ClangToolChain(this, clangPath, Platform.ARCH_X86_64, vars);
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
manager.addToolChain(toolChain);
found = true;
}
}
return found || addToolChain32(manager, registry, key);
}
private boolean addToolChain32(IToolChainManager manager, WindowsRegistry registry, String key) {
@ -109,28 +108,30 @@ public class Msys2ToolChainProvider implements IToolChainProvider {
Path msysPath = Paths.get(installLocation);
Path gccPath = msysPath.resolve("mingw32\\bin\\gcc.exe"); //$NON-NLS-1$
if (Files.exists(gccPath)) {
StringBuilder pathVar = new StringBuilder();
pathVar.append(msysPath);
pathVar.append("\\mingw32\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\bin"); //$NON-NLS-1$
IEnvironmentVariable[] vars = new IEnvironmentVariable[] {
new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
File.pathSeparator) };
GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars);
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars);
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
manager.addToolChain(toolChain);
return true;
} else {
return false;
}
return false;
}
private IEnvironmentVariable[] createEnvironmentVariables(Path msysPath, Path toolPath) {
StringBuilder pathVar = new StringBuilder();
pathVar.append(toolPath);
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar);
pathVar.append(msysPath);
pathVar.append("\\bin"); //$NON-NLS-1$
EnvironmentVariable pathVariable = new EnvironmentVariable("PATH", pathVar.toString(), //$NON-NLS-1$
IEnvironmentVariable.ENVVAR_PREPEND, File.pathSeparator);
return new IEnvironmentVariable[] { pathVariable };
}
}