diff --git a/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF index b96def9e1e5..839158309c0 100644 --- a/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF @@ -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, diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java index 38a95bbf118..1b9c3c7ef6c 100644 --- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java +++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java @@ -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.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 void init(IToolChainManager manager) { 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 @@ private boolean addToolChain32(IToolChainManager manager, WindowsRegistry regist 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 }; } }