1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-16 04:35:45 +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-ManifestVersion: 2
Bundle-Name: %pluginName Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.build.gcc.core;singleton:=true 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-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator
Bundle-Vendor: %providerName Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime, 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 * This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0 * are made available under the terms of the Eclipse Public License 2.0
@ -9,6 +9,7 @@
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
* Contributors: * Contributors:
* John Dallaway - Support multiple MSYS2 64-bit registry names (#237) * John Dallaway - Support multiple MSYS2 64-bit registry names (#237)
* John Dallaway - Detect UCRT64 toolchains (#887)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.build.gcc.core.internal; 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.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
import org.eclipse.cdt.build.gcc.core.GCCToolChain; import org.eclipse.cdt.build.gcc.core.GCCToolChain;
import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager; 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) { private boolean addToolChain64(IToolChainManager manager, WindowsRegistry registry, String key) {
String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$ String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
Path msysPath = Paths.get(installLocation); Path msysPath = Paths.get(installLocation);
Path gccPath = msysPath.resolve("mingw64\\bin\\gcc.exe"); //$NON-NLS-1$ boolean found = false;
if (Files.exists(gccPath)) { for (String variant : List.of("mingw64", "ucrt64")) { //$NON-NLS-1$ //$NON-NLS-2$
StringBuilder pathVar = new StringBuilder(); Path gccPath = msysPath.resolve(variant + "\\bin\\gcc.exe"); //$NON-NLS-1$
pathVar.append(msysPath); if (Files.exists(gccPath)) {
pathVar.append("\\mingw64\\bin"); //$NON-NLS-1$ IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
pathVar.append(File.pathSeparatorChar); IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars);
pathVar.append(msysPath); toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$ manager.addToolChain(toolChain);
pathVar.append(File.pathSeparatorChar); found = true;
pathVar.append(msysPath); }
pathVar.append("\\usr\\bin"); //$NON-NLS-1$ Path clangPath = msysPath.resolve(variant + "\\bin\\clang.exe"); //$NON-NLS-1$
pathVar.append(File.pathSeparatorChar); if (Files.exists(clangPath)) {
pathVar.append(msysPath); IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, clangPath.getParent());
pathVar.append("\\bin"); //$NON-NLS-1$ IToolChain toolChain = new ClangToolChain(this, clangPath, Platform.ARCH_X86_64, vars);
IEnvironmentVariable[] vars = new IEnvironmentVariable[] { toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$ manager.addToolChain(toolChain);
File.pathSeparator) }; found = true;
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);
} }
return found || addToolChain32(manager, registry, key);
} }
private boolean addToolChain32(IToolChainManager manager, WindowsRegistry registry, String 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 msysPath = Paths.get(installLocation);
Path gccPath = msysPath.resolve("mingw32\\bin\\gcc.exe"); //$NON-NLS-1$ Path gccPath = msysPath.resolve("mingw32\\bin\\gcc.exe"); //$NON-NLS-1$
if (Files.exists(gccPath)) { if (Files.exists(gccPath)) {
StringBuilder pathVar = new StringBuilder(); IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
pathVar.append(msysPath); IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars);
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);
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$ toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
manager.addToolChain(toolChain); manager.addToolChain(toolChain);
return true; 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 };
} }
} }