Skip to content

Commit

Permalink
Detect MSYS2 UCRT64 toolchains for CDT Core Build
Browse files Browse the repository at this point in the history
  • Loading branch information
jld01 committed Aug 17, 2024
1 parent 54ebddc commit c4c11ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build/org.eclipse.cdt.build.gcc.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,15 +9,18 @@
* 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;

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;
Expand Down Expand Up @@ -78,59 +81,57 @@ 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) {
String installLocation = registry.getCurrentUserValue(key, "InstallLocation"); //$NON-NLS-1$
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 };
}

}

0 comments on commit c4c11ad

Please sign in to comment.