Skip to content

Commit c4c11ad

Browse files
committed
Detect MSYS2 UCRT64 toolchains for CDT Core Build
1 parent 54ebddc commit c4c11ad

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-43
lines changed

build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.cdt.build.gcc.core;singleton:=true
5-
Bundle-Version: 2.1.400.qualifier
5+
Bundle-Version: 2.1.500.qualifier
66
Bundle-Activator: org.eclipse.cdt.build.gcc.core.internal.Activator
77
Bundle-Vendor: %providerName
88
Require-Bundle: org.eclipse.core.runtime,

build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/internal/Msys2ToolChainProvider.java

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2023 QNX Software Systems and others.
2+
* Copyright (c) 2016, 2024 QNX Software Systems and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -9,15 +9,18 @@
99
* SPDX-License-Identifier: EPL-2.0
1010
* Contributors:
1111
* John Dallaway - Support multiple MSYS2 64-bit registry names (#237)
12+
* John Dallaway - Detect UCRT64 toolchains (#887)
1213
*******************************************************************************/
1314
package org.eclipse.cdt.build.gcc.core.internal;
1415

1516
import java.io.File;
1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
1819
import java.nio.file.Paths;
20+
import java.util.List;
1921
import java.util.Set;
2022

23+
import org.eclipse.cdt.build.gcc.core.ClangToolChain;
2124
import org.eclipse.cdt.build.gcc.core.GCCToolChain;
2225
import org.eclipse.cdt.core.build.IToolChain;
2326
import org.eclipse.cdt.core.build.IToolChainManager;
@@ -78,59 +81,57 @@ public void init(IToolChainManager manager) {
7881
private boolean addToolChain64(IToolChainManager manager, WindowsRegistry registry, String key) {
7982
String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
8083
Path msysPath = Paths.get(installLocation);
81-
Path gccPath = msysPath.resolve("mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
82-
if (Files.exists(gccPath)) {
83-
StringBuilder pathVar = new StringBuilder();
84-
pathVar.append(msysPath);
85-
pathVar.append("\\mingw64\\bin"); //$NON-NLS-1$
86-
pathVar.append(File.pathSeparatorChar);
87-
pathVar.append(msysPath);
88-
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
89-
pathVar.append(File.pathSeparatorChar);
90-
pathVar.append(msysPath);
91-
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
92-
pathVar.append(File.pathSeparatorChar);
93-
pathVar.append(msysPath);
94-
pathVar.append("\\bin"); //$NON-NLS-1$
95-
IEnvironmentVariable[] vars = new IEnvironmentVariable[] {
96-
new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
97-
File.pathSeparator) };
98-
GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars);
99-
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
100-
manager.addToolChain(toolChain);
101-
return true;
102-
} else {
103-
return addToolChain32(manager, registry, key);
84+
boolean found = false;
85+
for (String variant : List.of("mingw64", "ucrt64")) { //$NON-NLS-1$ //$NON-NLS-2$
86+
Path gccPath = msysPath.resolve(variant + "\\bin\\gcc.exe"); //$NON-NLS-1$
87+
if (Files.exists(gccPath)) {
88+
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
89+
IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86_64, vars);
90+
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
91+
manager.addToolChain(toolChain);
92+
found = true;
93+
}
94+
Path clangPath = msysPath.resolve(variant + "\\bin\\clang.exe"); //$NON-NLS-1$
95+
if (Files.exists(clangPath)) {
96+
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, clangPath.getParent());
97+
IToolChain toolChain = new ClangToolChain(this, clangPath, Platform.ARCH_X86_64, vars);
98+
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
99+
manager.addToolChain(toolChain);
100+
found = true;
101+
}
104102
}
103+
return found || addToolChain32(manager, registry, key);
105104
}
106105

107106
private boolean addToolChain32(IToolChainManager manager, WindowsRegistry registry, String key) {
108107
String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
109108
Path msysPath = Paths.get(installLocation);
110109
Path gccPath = msysPath.resolve("mingw32\\bin\\gcc.exe"); //$NON-NLS-1$
111110
if (Files.exists(gccPath)) {
112-
StringBuilder pathVar = new StringBuilder();
113-
pathVar.append(msysPath);
114-
pathVar.append("\\mingw32\\bin"); //$NON-NLS-1$
115-
pathVar.append(File.pathSeparatorChar);
116-
pathVar.append(msysPath);
117-
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
118-
pathVar.append(File.pathSeparatorChar);
119-
pathVar.append(msysPath);
120-
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
121-
pathVar.append(File.pathSeparatorChar);
122-
pathVar.append(msysPath);
123-
pathVar.append("\\bin"); //$NON-NLS-1$
124-
IEnvironmentVariable[] vars = new IEnvironmentVariable[] {
125-
new EnvironmentVariable("PATH", pathVar.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
126-
File.pathSeparator) };
127-
GCCToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars);
111+
IEnvironmentVariable[] vars = createEnvironmentVariables(msysPath, gccPath.getParent());
112+
IToolChain toolChain = new GCCToolChain(this, gccPath, Platform.ARCH_X86, vars);
128113
toolChain.setProperty(IToolChain.ATTR_PACKAGE, "msys2"); //$NON-NLS-1$
129114
manager.addToolChain(toolChain);
130115
return true;
131-
} else {
132-
return false;
133116
}
117+
return false;
118+
}
119+
120+
private IEnvironmentVariable[] createEnvironmentVariables(Path msysPath, Path toolPath) {
121+
StringBuilder pathVar = new StringBuilder();
122+
pathVar.append(toolPath);
123+
pathVar.append(File.pathSeparatorChar);
124+
pathVar.append(msysPath);
125+
pathVar.append("\\usr\\local\\bin"); //$NON-NLS-1$
126+
pathVar.append(File.pathSeparatorChar);
127+
pathVar.append(msysPath);
128+
pathVar.append("\\usr\\bin"); //$NON-NLS-1$
129+
pathVar.append(File.pathSeparatorChar);
130+
pathVar.append(msysPath);
131+
pathVar.append("\\bin"); //$NON-NLS-1$
132+
EnvironmentVariable pathVariable = new EnvironmentVariable("PATH", pathVar.toString(), //$NON-NLS-1$
133+
IEnvironmentVariable.ENVVAR_PREPEND, File.pathSeparator);
134+
return new IEnvironmentVariable[] { pathVariable };
134135
}
135136

136137
}

0 commit comments

Comments
 (0)