From 14651f422e5ee063ce91a81b5bf249763ee51d26 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 24 Mar 2025 15:44:06 +0100 Subject: [PATCH 01/26] [GR-63253] Adopt the new unchained standalones for Sulong --- sulong/mx.sulong/mx_sulong.py | 26 +++++++ sulong/mx.sulong/suite.py | 140 +++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 1 deletion(-) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index 8a80739664e6..afa9fa27c0cc 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -47,6 +47,7 @@ import mx_sulong_gate import mx_sulong_unittest #pylint: disable=unused-import import mx_sulong_llvm_config +import mx_truffle # re-export custom mx project classes so they can be used from suite.py from mx_cmake import CMakeNinjaProject #pylint: disable=unused-import @@ -58,6 +59,7 @@ from mx_sulong_suite_constituents import DocumentationProject #pylint: disable=unused-import from mx_sulong_suite_constituents import HeaderProject #pylint: disable=unused-import from mx_sulong_suite_constituents import CopiedNativeProject #pylint: disable=unused-import +from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import if sys.version_info[0] < 3: def _decode(x): @@ -102,6 +104,30 @@ def sulong_prefix_path(name): mx_subst.results_substitutions.register_with_arg('sulong_prefix', sulong_prefix_path) +# Functions called from suite.py + +def has_suite(name): + return mx.suite(name, fatalIfMissing=False) + +def is_ee(): + return has_suite('graal-enterprise') + +def sulong_standalone_deps(): + deps = mx_truffle.resolve_truffle_dist_names() + if is_ee(): + deps += ['sulong-managed:SULONG_ENTERPRISE_NATIVE'] + # TODO + return deps + +def libllvmvm_build_args(): + if is_ee() and not mx.is_windows(): + return [ + '-H:+AuxiliaryEngineCache', + '-H:ReservedAuxiliaryImageBytes=2145482548', + ] + else: + return [] + def testLLVMImage(image, imageArgs=None, testFilter=None, libPath=True, test=None, unittestArgs=None): mx_sulong_gate.testLLVMImage(image, imageArgs, testFilter, libPath, test, unittestArgs) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index a24e6e3170ed..b30607f8463f 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1,5 +1,5 @@ suite = { - "mxversion": "7.33.0", + "mxversion": "7.42.3", "name" : "sulong", "version" : "25.0.0", "release" : False, @@ -1649,6 +1649,42 @@ "testProject" : True, "defaultBuild" : False, }, + + "sulong_licenses": { + "class": "StandaloneLicenses", + "community_license_file": "LICENSE", + "community_3rd_party_license_file": "THIRD_PARTY_LICENSE.txt", + }, + + "sulong_thin_launcher": { + "class": "ThinLauncherProject", + "mainClass": "com.oracle.truffle.llvm.launcher.LLVMLauncher", + "jar_distributions": ["sulong:SULONG_LAUNCHER"], + "relative_home_paths": { + "llvm": "..", + }, + "relative_jre_path": "../jvm", + "relative_module_path": "../modules", + "relative_extracted_lib_paths": { + "truffle.attach.library": "../jvmlibs/", + "truffle.nfi.library": "../jvmlibs/", + }, + "liblang_relpath": "../lib/", + }, + + "libllvmvm": { + "class": "LanguageLibraryProject", + "dependencies": [ + "SULONG_STANDALONE_DEPENDENCIES", + ], + "build_args": [ + # From mx.sulong/native-image.properties + "-H:+AddAllCharsets", + # Configure launcher + "-Dorg.graalvm.launcher.class=com.oracle.truffle.llvm.launcher.LLVMLauncher", + ], + "dynamicBuildArgs": "libllvmvm_build_args", + }, }, "distributions" : { @@ -1765,6 +1801,7 @@ "SULONG_CORE", "truffle:TRUFFLE_NFI", "truffle:TRUFFLE_NFI_LIBFFI", + "truffle:TRUFFLE_NFI_PANAMA", ], "maven" : { "artifactId" : "llvm-language-native", @@ -1938,6 +1975,107 @@ "license" : "BSD-new", }, + "SULONG_STANDALONE_DEPENDENCIES": { + "description": "Sulong standalone dependencies", + "class": "DynamicPOMDistribution", + "distDependencies": [ + "sulong:SULONG_LAUNCHER", + "sulong:SULONG_CORE", + "sulong:SULONG_API", + "sulong:SULONG_NFI", + "sulong:SULONG_NATIVE", + "sdk:TOOLS_FOR_STANDALONE", + ], + "dynamicDistDependencies": "sulong_standalone_deps", + "maven": False, + }, + + "SULONG_STANDALONE_COMMON": { + "description": "Common layout for Native and JVM standalones", + "type": "dir", + "platformDependent": True, + "layout": { + "./": [ + "dependency:sulong_licenses/*", + ], + "bin/": "dependency:sulong_thin_launcher", + "lib/llvm-toolchain/": "extracted-dependency:sdk:LLVM_TOOLCHAIN", + "lib/sulong/": [ + "extracted-dependency:SULONG_CORE_HOME", + "extracted-dependency:SULONG_GRAALVM_DOCS", + "extracted-dependency:SULONG_BITCODE_HOME", + "extracted-dependency:SULONG_NATIVE_HOME", + ], + "release": "dependency:sdk:STANDALONE_JAVA_HOME/release", + }, + }, + + "SULONG_NATIVE_STANDALONE": { + "description": "Sulong Native standalone", + "type": "dir", + "platformDependent": True, + "layout": { + "./": [ + "dependency:SULONG_STANDALONE_COMMON/*", + ], + }, + }, + + "SULONG_JVM_STANDALONE": { + "description": "Sulong JVM standalone", + "type": "dir", + "platformDependent": True, + "layout": { + "./": [ + "dependency:SULONG_STANDALONE_COMMON/*", + ], + "jvm/": { + "source_type": "dependency", + "dependency": "sdk:STANDALONE_JAVA_HOME", + "path": "*", + "exclude": [ + # Native Image-related + "bin/native-image*", + "lib/static", + "lib/svm", + "lib/", + "lib/", + # Unnecessary and big + "lib/src.zip", + "jmods", + ], + }, + "jvmlibs/": [ + "extracted-dependency:truffle:TRUFFLE_ATTACH_GRAALVM_SUPPORT", + "extracted-dependency:truffle:TRUFFLE_NFI_NATIVE_GRAALVM_SUPPORT", + ], + "modules/": [ + { + "source_type": "classpath-dependencies", + "dependencies": [ + "SULONG_STANDALONE_DEPENDENCIES", + ], + }, + ], + }, + }, + + "SULONG_NATIVE_STANDALONE_RELEASE_ARCHIVE": { + "class": "DeliverableStandaloneArchive", + "platformDependent": True, + "standalone_dist": "SULONG_NATIVE_STANDALONE", + "community_archive_name": "llvm-community", + "enterprise_archive_name": "llvm", + }, + + "SULONG_JVM_STANDALONE_RELEASE_ARCHIVE": { + "class": "DeliverableStandaloneArchive", + "platformDependent": True, + "standalone_dist": "SULONG_JVM_STANDALONE", + "community_archive_name": "llvm-community-jvm", + "enterprise_archive_name": "llvm-jvm", + }, + "SULONG_NATIVE_BITCODE_RESOURCES" : { "description" : "Contains the runtime dependencies needed by the LLVM runtime in native mode.", "type" : "dir", From b9f1f57afeb36e829f552d63da66094cfa0d0b36 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 24 Mar 2025 16:42:19 +0100 Subject: [PATCH 02/26] Use thin launchers for toolchain wrappers --- sulong/mx.sulong/mx_sulong.py | 5 +- sulong/mx.sulong/suite.py | 109 ++++++++++++++++-- .../truffle/llvm/runtime/ToolchainImpl.java | 4 +- .../launchers/NativeToolchainWrapper.java | 91 +++++++++++++++ .../toolchain/launchers/common/Driver.java | 7 +- 5 files changed, 204 insertions(+), 12 deletions(-) create mode 100644 sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index afa9fa27c0cc..d3bd8236ea17 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -59,7 +59,7 @@ from mx_sulong_suite_constituents import DocumentationProject #pylint: disable=unused-import from mx_sulong_suite_constituents import HeaderProject #pylint: disable=unused-import from mx_sulong_suite_constituents import CopiedNativeProject #pylint: disable=unused-import -from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import +from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import if sys.version_info[0] < 3: def _decode(x): @@ -434,7 +434,8 @@ def _lib_sub(program): return mx_subst.path_substitutions.substitute("".format(program)) class ToolchainConfig(object): - # Please keep this list in sync with Toolchain.java (method documentation) and ToolchainImpl.java (lookup switch block). + # Please keep this list in sync with Toolchain.java (method documentation) and ToolchainImpl.java (lookup switch block) + # and NativeToolchainWrapper. _llvm_tool_map = ["ar", "nm", "objcopy", "objdump", "ranlib", "readelf", "readobj", "strip"] _tool_map = { "CC": ["graalvm-{name}-clang", "graalvm-clang", "clang", "cc", "gcc"], diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index b30607f8463f..d4a7073f45a2 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1672,6 +1672,18 @@ "liblang_relpath": "../lib/", }, + "native_toolchain_wrapper": { + "class": "ThinLauncherProject", + "mainClass": "com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", + "jar_distributions": ["sulong:SULONG_TOOLCHAIN_LAUNCHERS"], + "relative_home_paths": { + "llvm-toolchain": "../../../llvm-toolchain", + }, + "relative_jre_path": "../../../../jvm", + "relative_module_path": "../../../../modules", + "liblang_relpath": "../lib/", + }, + "libllvmvm": { "class": "LanguageLibraryProject", "dependencies": [ @@ -1685,6 +1697,20 @@ ], "dynamicBuildArgs": "libllvmvm_build_args", }, + + "libnativetoolchainwrappers": { + "class": "NativeImageLibraryProject", + "dependencies": [ + "SULONG_TOOLCHAIN_LAUNCHERS", + ], + "build_args": [ + # From mx.sulong/mx_sulong.py + "--initialize-at-build-time=com.oracle.truffle.llvm.toolchain.launchers", + "--gc=epsilon", + # Configure launcher + "-Dorg.graalvm.launcher.class=com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", + ], + }, }, "distributions" : { @@ -1975,6 +2001,70 @@ "license" : "BSD-new", }, + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { + "description": "Layout for Sulong native toolchain and llvm-toolchain", + "type": "dir", + "platformDependent": True, + "layout": { + "lib/llvm-toolchain/": "extracted-dependency:sdk:LLVM_TOOLCHAIN", + + "lib/sulong/": [ + "extracted-dependency:SULONG_CORE_HOME", + "extracted-dependency:SULONG_GRAALVM_DOCS", + "extracted-dependency:SULONG_BITCODE_HOME", + "extracted-dependency:SULONG_NATIVE_HOME", + ], + + "lib/sulong/native/lib/": "dependency:libnativetoolchainwrappers", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", + }, + }, + "SULONG_STANDALONE_DEPENDENCIES": { "description": "Sulong standalone dependencies", "class": "DynamicPOMDistribution", @@ -1984,6 +2074,7 @@ "sulong:SULONG_API", "sulong:SULONG_NFI", "sulong:SULONG_NATIVE", + "sulong:SULONG_TOOLCHAIN_LAUNCHERS", "sdk:TOOLS_FOR_STANDALONE", ], "dynamicDistDependencies": "sulong_standalone_deps", @@ -1997,15 +2088,9 @@ "layout": { "./": [ "dependency:sulong_licenses/*", + "dependency:SULONG_NATIVE_AND_LLVM_TOOLCHAIN/*", ], "bin/": "dependency:sulong_thin_launcher", - "lib/llvm-toolchain/": "extracted-dependency:sdk:LLVM_TOOLCHAIN", - "lib/sulong/": [ - "extracted-dependency:SULONG_CORE_HOME", - "extracted-dependency:SULONG_GRAALVM_DOCS", - "extracted-dependency:SULONG_BITCODE_HOME", - "extracted-dependency:SULONG_NATIVE_HOME", - ], "release": "dependency:sdk:STANDALONE_JAVA_HOME/release", }, }, @@ -2018,6 +2103,9 @@ "./": [ "dependency:SULONG_STANDALONE_COMMON/*", ], + "lib/": [ + "dependency:libllvmvm", + ], }, }, @@ -2122,6 +2210,13 @@ }, "SULONG_TOOLCHAIN_LAUNCHERS": { + "moduleInfo" : { + "name" : "org.graalvm.llvm.native_toolchain_wrappers", + "exports" : [ + "com.oracle.truffle.llvm.toolchain.launchers to org.graalvm.launcher", + ], + }, + "useModulePath" : True, "subDir" : "projects", "dependencies" : ["com.oracle.truffle.llvm.toolchain.launchers"], "distDependencies" : ["sdk:LAUNCHER_COMMON"], diff --git a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/ToolchainImpl.java b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/ToolchainImpl.java index 11ea673d30bb..fd8ab4fdce03 100644 --- a/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/ToolchainImpl.java +++ b/sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/ToolchainImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. * * All rights reserved. * @@ -73,7 +73,7 @@ public TruffleFile getToolPath(String tool) { /** * Please keep this list in sync with Toolchain.java (method documentation) and mx_sulong.py's - * ToolchainConfig::_tool_map. + * ToolchainConfig::_tool_map and NativeToolchainWrapper. */ private TruffleFile getToolPathImpl(String tool) { diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java new file mode 100644 index 000000000000..ab00c4f680f8 --- /dev/null +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.truffle.llvm.toolchain.launchers; + +import java.util.List; +import java.util.Map; + +import org.graalvm.launcher.AbstractLanguageLauncher; +import org.graalvm.options.OptionCategory; +import org.graalvm.polyglot.Context.Builder; + +public final class NativeToolchainWrapper extends AbstractLanguageLauncher { + + @Override + protected List preprocessArguments(List arguments, Map polyglotOptions) { + /* + * We do everything here and not in launch() to avoid making more of + * AbstractLanguageLauncher/Truffle reachable, such as + * com.oracle.truffle.polyglot.PolyglotLanguageDispatch. + */ + + String[] args = arguments.toArray(new String[0]); + + String toolName = AbstractBinUtil.getProcessName(); + if (toolName == null) { + System.err.println("Error: Could not figure out process name"); + System.exit(1); + } + + if (toolName.startsWith("graalvm-native-")) { + toolName = toolName.substring("graalvm-native-".length()); + } else if (toolName.startsWith("graalvm-")) { + toolName = toolName.substring("graalvm-".length()); + } + + switch (toolName) { + case "clang", "cc", "gcc" -> Clang.main(args); + case "clang++", "c++", "g++" -> ClangXX.main(args); + case "clang-cl", "cl" -> ClangCL.main(args); + case "ld", "ld.lld", "lld", "lld-link", "ld64" -> Linker.main(args); + case "flang-new", "flang" -> Flang.main(args); + default -> BinUtil.main(args); + } + + System.exit(0); + throw new Error("unreachable"); + } + + @Override + protected void launch(Builder contextBuilder) { + throw new UnsupportedOperationException(); + } + + @Override + protected String getLanguageId() { + return ""; + } + + @Override + protected void printHelp(OptionCategory maxCategory) { + throw new UnsupportedOperationException(); + } + +} diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java index 621427f0de61..2c9171793679 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. * * All rights reserved. * @@ -127,6 +127,11 @@ public static Path getLLVMBinDir() { return Paths.get(property); } + final String homeProperty = System.getProperty("org.graalvm.language.llvm-toolchain.home"); + if (homeProperty != null) { + return Paths.get(homeProperty).resolve("bin"); + } + // TODO (GR-18389): Set only for standalones currently Path toolchainHome = HomeFinder.getInstance().getLanguageHomes().get("llvm-toolchain"); if (toolchainHome != null) { From 88dffc2424f0c4ee96114b4dd34fc4f855c1f850 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 24 Mar 2025 18:20:50 +0100 Subject: [PATCH 03/26] Update env file to use the new standalones --- sulong/mx.sulong/ce-llvm-standalones | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sulong/mx.sulong/ce-llvm-standalones b/sulong/mx.sulong/ce-llvm-standalones index d0561b261efe..447a685a5d39 100644 --- a/sulong/mx.sulong/ce-llvm-standalones +++ b/sulong/mx.sulong/ce-llvm-standalones @@ -1,3 +1,5 @@ -DYNAMIC_IMPORTS=/substratevm,/vm -COMPONENTS=llp,llrl,llrlf,llrn,lg,svmnfi,tflm,tflsm -BUILD_TARGETS=GRAALVM_STANDALONES +DYNAMIC_IMPORTS=/tools,/compiler,/substratevm +COMPONENTS=SubstrateVM,Truffle SVM Macro,LibGraal +NATIVE_IMAGES=true +BUILD_TARGETS=SULONG_NATIVE_STANDALONE,SULONG_JVM_STANDALONE +GRAALVM_SKIP_ARCHIVE=true From bf96c47b098eaa7fc5a555e13004f62c1e88b308 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 25 Mar 2025 15:32:31 +0100 Subject: [PATCH 04/26] Handle sulong-managed --- sulong/mx.sulong/mx_sulong.py | 7 +- sulong/mx.sulong/suite.py | 65 +++++++++++-------- .../toolchain/launchers/common/Driver.java | 5 ++ 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index d3bd8236ea17..635b27951e3a 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -115,8 +115,11 @@ def is_ee(): def sulong_standalone_deps(): deps = mx_truffle.resolve_truffle_dist_names() if is_ee(): - deps += ['sulong-managed:SULONG_ENTERPRISE_NATIVE'] - # TODO + deps += [ + 'sulong-managed:SULONG_ENTERPRISE', + 'sulong-managed:SULONG_MANAGED', + 'sulong-managed:SULONG_ENTERPRISE_NATIVE', + ] return deps def libllvmvm_build_args(): diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index d4a7073f45a2..c9e12ee689d3 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1677,6 +1677,7 @@ "mainClass": "com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", "jar_distributions": ["sulong:SULONG_TOOLCHAIN_LAUNCHERS"], "relative_home_paths": { + "llvm": "../..", "llvm-toolchain": "../../../llvm-toolchain", }, "relative_jre_path": "../../../../jvm", @@ -1701,7 +1702,7 @@ "libnativetoolchainwrappers": { "class": "NativeImageLibraryProject", "dependencies": [ - "SULONG_TOOLCHAIN_LAUNCHERS", + "sulong:SULONG_TOOLCHAIN_LAUNCHERS", ], "build_args": [ # From mx.sulong/mx_sulong.py @@ -2001,6 +2002,22 @@ "license" : "BSD-new", }, + "SULONG_STANDALONE_DEPENDENCIES": { + "description": "Sulong standalone dependencies", + "class": "DynamicPOMDistribution", + "distDependencies": [ + "sulong:SULONG_LAUNCHER", + "sulong:SULONG_CORE", + "sulong:SULONG_API", + "sulong:SULONG_NFI", + "sulong:SULONG_NATIVE", + "sulong:SULONG_TOOLCHAIN_LAUNCHERS", + "sdk:TOOLS_FOR_STANDALONE", + ], + "dynamicDistDependencies": "sulong_standalone_deps", + "maven": False, + }, + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { "description": "Layout for Sulong native toolchain and llvm-toolchain", "type": "dir", @@ -2065,22 +2082,6 @@ }, }, - "SULONG_STANDALONE_DEPENDENCIES": { - "description": "Sulong standalone dependencies", - "class": "DynamicPOMDistribution", - "distDependencies": [ - "sulong:SULONG_LAUNCHER", - "sulong:SULONG_CORE", - "sulong:SULONG_API", - "sulong:SULONG_NFI", - "sulong:SULONG_NATIVE", - "sulong:SULONG_TOOLCHAIN_LAUNCHERS", - "sdk:TOOLS_FOR_STANDALONE", - ], - "dynamicDistDependencies": "sulong_standalone_deps", - "maven": False, - }, - "SULONG_STANDALONE_COMMON": { "description": "Common layout for Native and JVM standalones", "type": "dir", @@ -2095,6 +2096,17 @@ }, }, + "SULONG_LIBLLVMVM": { + "description": "libllvmvm as a layout, so it can be reused in sulong-managed", + "type": "dir", + "platformDependent": True, + "layout": { + "lib/": [ + "dependency:libllvmvm", + ], + }, + }, + "SULONG_NATIVE_STANDALONE": { "description": "Sulong Native standalone", "type": "dir", @@ -2102,9 +2114,7 @@ "layout": { "./": [ "dependency:SULONG_STANDALONE_COMMON/*", - ], - "lib/": [ - "dependency:libllvmvm", + "dependency:SULONG_LIBLLVMVM/*", ], }, }, @@ -2138,12 +2148,7 @@ "extracted-dependency:truffle:TRUFFLE_NFI_NATIVE_GRAALVM_SUPPORT", ], "modules/": [ - { - "source_type": "classpath-dependencies", - "dependencies": [ - "SULONG_STANDALONE_DEPENDENCIES", - ], - }, + "classpath-dependencies:SULONG_STANDALONE_DEPENDENCIES", ], }, }, @@ -2153,7 +2158,7 @@ "platformDependent": True, "standalone_dist": "SULONG_NATIVE_STANDALONE", "community_archive_name": "llvm-community", - "enterprise_archive_name": "llvm", + "enterprise_archive_name": "llvm", # should not be used as it lacks the managed toolchain }, "SULONG_JVM_STANDALONE_RELEASE_ARCHIVE": { @@ -2161,7 +2166,7 @@ "platformDependent": True, "standalone_dist": "SULONG_JVM_STANDALONE", "community_archive_name": "llvm-community-jvm", - "enterprise_archive_name": "llvm-jvm", + "enterprise_archive_name": "llvm-jvm", # should not be used as it lacks the managed toolchain }, "SULONG_NATIVE_BITCODE_RESOURCES" : { @@ -2214,6 +2219,10 @@ "name" : "org.graalvm.llvm.native_toolchain_wrappers", "exports" : [ "com.oracle.truffle.llvm.toolchain.launchers to org.graalvm.launcher", + # "com.oracle.truffle.llvm.toolchain.launchers.common to org.graalvm.llvm.managed_toolchain_wrappers", + # "com.oracle.truffle.llvm.toolchain.launchers to org.graalvm.llvm.managed_toolchain_wrappers", + "com.oracle.truffle.llvm.toolchain.launchers.common", # TODO ideally use the above but doesn't work + "com.oracle.truffle.llvm.toolchain.launchers", # TODO ideally use the above but doesn't work ], }, "useModulePath" : True, diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java index 2c9171793679..ba174ff8539f 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java @@ -142,6 +142,11 @@ public static Path getLLVMBinDir() { } public static Path getSulongHome() { + final String homeProperty = System.getProperty("org.graalvm.language.llvm.home"); + if (homeProperty != null) { + return Paths.get(homeProperty); + } + final Path sulongHome = HomeFinder.getInstance().getLanguageHomes().get("llvm"); if (sulongHome != null) { return sulongHome; From 6e9c1d06b1241442dfb38482dd311858713f7528 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 25 Mar 2025 17:47:56 +0100 Subject: [PATCH 05/26] [GR-63487] Mark the new dir layout distributions as no need to merge platforms --- sulong/mx.sulong/suite.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index c9e12ee689d3..e8f4737d9eac 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1,5 +1,5 @@ suite = { - "mxversion": "7.42.3", + "mxversion": "7.45.0", "name" : "sulong", "version" : "25.0.0", "release" : False, @@ -2022,6 +2022,7 @@ "description": "Layout for Sulong native toolchain and llvm-toolchain", "type": "dir", "platformDependent": True, + "platforms": "local", "layout": { "lib/llvm-toolchain/": "extracted-dependency:sdk:LLVM_TOOLCHAIN", @@ -2086,6 +2087,7 @@ "description": "Common layout for Native and JVM standalones", "type": "dir", "platformDependent": True, + "platforms": "local", "layout": { "./": [ "dependency:sulong_licenses/*", @@ -2100,6 +2102,7 @@ "description": "libllvmvm as a layout, so it can be reused in sulong-managed", "type": "dir", "platformDependent": True, + "platforms": "local", "layout": { "lib/": [ "dependency:libllvmvm", @@ -2111,6 +2114,7 @@ "description": "Sulong Native standalone", "type": "dir", "platformDependent": True, + "platforms": "local", "layout": { "./": [ "dependency:SULONG_STANDALONE_COMMON/*", @@ -2123,6 +2127,7 @@ "description": "Sulong JVM standalone", "type": "dir", "platformDependent": True, + "platforms": "local", "layout": { "./": [ "dependency:SULONG_STANDALONE_COMMON/*", From 613cc577f6ec6e8edb2cc605d60fa43de0a51f89 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 25 Mar 2025 17:59:56 +0100 Subject: [PATCH 06/26] Fix to let `mx --env ee-graalos build` work --- sulong/mx.sulong/mx_sulong.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index 635b27951e3a..10e491940a6d 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -114,7 +114,7 @@ def is_ee(): def sulong_standalone_deps(): deps = mx_truffle.resolve_truffle_dist_names() - if is_ee(): + if has_suite('sulong-managed'): deps += [ 'sulong-managed:SULONG_ENTERPRISE', 'sulong-managed:SULONG_MANAGED', From 86e0cc48db1258b30eaed8f4c9aef458c7a25e73 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 25 Mar 2025 18:56:01 +0100 Subject: [PATCH 07/26] Use the new standalones for get_lli_path() --- sulong/mx.sulong/mx_sulong.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index 10e491940a6d..8fa36fe648f9 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -310,7 +310,11 @@ def get_lli_path(fatalIfMissing=True): useJvm = False else: mx.abort(f"Unknown standalone type {standaloneMode}.") - path = mx_sdk_vm_impl.standalone_home("llvm", useJvm) + if is_ee(): + dist = "SULONG_MANAGED_JVM_STANDALONE" if useJvm else "SULONG_MANAGED_NATIVE_STANDALONE" + else: + dist = "SULONG_JVM_STANDALONE" if useJvm else "SULONG_NATIVE_STANDALONE" + path = mx.distribution(dist).output return os.path.join(path, 'bin', mx_subst.path_substitutions.substitute('')) From ed4355e0690274f830ae037d877799440349c2c5 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 26 Mar 2025 12:29:10 +0100 Subject: [PATCH 08/26] Add a layout for Sulong Native + LLVM toolchain + JVM toolchain wrappers * See usage in GraalPy. --- sulong/mx.sulong/suite.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index e8f4737d9eac..632bde6df803 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -2018,8 +2018,8 @@ "maven": False, }, - "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { - "description": "Layout for Sulong native toolchain and llvm-toolchain", + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS": { + "description": "Layout for Sulong native toolchain and llvm-toolchain, with JVM wrappers", "type": "dir", "platformDependent": True, "platforms": "local", @@ -2033,8 +2033,6 @@ "extracted-dependency:SULONG_NATIVE_HOME", ], - "lib/sulong/native/lib/": "dependency:libnativetoolchainwrappers", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", @@ -2083,6 +2081,17 @@ }, }, + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { + "description": "Layout for Sulong native toolchain and llvm-toolchain", + "type": "dir", + "platformDependent": True, + "platforms": "local", + "layout": { + "./": "dependency:SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS/*", + "lib/sulong/native/lib/": "dependency:libnativetoolchainwrappers", + }, + }, + "SULONG_STANDALONE_COMMON": { "description": "Common layout for Native and JVM standalones", "type": "dir", From bd4d4daca2e86a9e50418d78e248b0c6f50f8ba8 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 27 Mar 2025 12:25:35 +0100 Subject: [PATCH 09/26] Add mechanism to have GraalVM components excluded from STAGE1 builds. --- sdk/mx.sdk/mx_sdk_vm.py | 8 ++++++-- sdk/mx.sdk/mx_sdk_vm_impl.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm.py b/sdk/mx.sdk/mx_sdk_vm.py index 6117739003b0..1c0e288c37eb 100644 --- a/sdk/mx.sdk/mx_sdk_vm.py +++ b/sdk/mx.sdk/mx_sdk_vm.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -263,7 +263,8 @@ def __init__(self, extra_installable_qualifiers=None, has_relative_home=True, jvm_configs=None, - extra_native_targets=None): + extra_native_targets=None, + final_stage_only=False): """ :param suite mx.Suite: the suite this component belongs to :type name: str @@ -281,6 +282,7 @@ def __init__(self, 'priority': -1, # 0 is invalid; < 0 prepends to the default configs; > 0 appends } :param extra_native_targets: list of str, enables extra targets in multi-target projects. + :param final_stage_only: bool, this component should be only included in the final GraalVM, not in stage1 :type license_files: list[str] :type third_party_license_files: list[str] :type polyglot_lib_build_args: list[str] @@ -305,6 +307,7 @@ def __init__(self, :type extra_installable_qualifiers: list[str] | None :type has_relative_home: bool :type jvm_configs: list[dict] or None + :type final_stage_only: bool """ if dependencies is None: mx.logv('Component {} does not specify dependencies'.format(name)) @@ -343,6 +346,7 @@ def __init__(self, self.has_relative_home = has_relative_home self.jvm_configs = jvm_configs or [] self.extra_native_targets = extra_native_targets + self.final_stage_only = final_stage_only if supported is not None or early_adopter: if stability is not None: diff --git a/sdk/mx.sdk/mx_sdk_vm_impl.py b/sdk/mx.sdk/mx_sdk_vm_impl.py index b889c71427b5..df508ef143c6 100644 --- a/sdk/mx.sdk/mx_sdk_vm_impl.py +++ b/sdk/mx.sdk/mx_sdk_vm_impl.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -166,6 +166,8 @@ def add_dependencies(dependencies, excludes=True): components = dependencies[:] while components: component = components.pop(0) + if component.final_stage_only and stage1: + continue if component not in components_to_build and not (excludes and is_excluded(component)): components_to_build.append(component) components.extend(component.direct_dependencies()) From 97d33faa801ce6566c2c0851437f115b96f3ecde Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Mon, 7 Apr 2025 15:40:02 +0200 Subject: [PATCH 10/26] Standalone gates need tools suite. --- sulong/ci/ci.jsonnet | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sulong/ci/ci.jsonnet b/sulong/ci/ci.jsonnet index 6b66bc7f7dfa..6c8bb750494b 100644 --- a/sulong/ci/ci.jsonnet +++ b/sulong/ci/ci.jsonnet @@ -39,6 +39,8 @@ local sc = (import "ci_common/sulong-common.jsonnet"); "/regex/**", "/java-benchmarks/**", ] + (if standalone then [ + # tools suite (included in standalone) + "/tools/**", # substratevm and its dependencies "/substratevm/**", # vm and its dependencies From f2861320bfe00badc8fd3d8d91d689e55ffd2a8f Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Mon, 7 Apr 2025 18:10:50 +0200 Subject: [PATCH 11/26] Fix standalone builds in gate jobs. --- sulong/mx.sulong/mx_sulong_gate.py | 6 ++---- sulong/mx.sulong/suite.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/sulong/mx.sulong/mx_sulong_gate.py b/sulong/mx.sulong/mx_sulong_gate.py index 75970c6294fd..d35f898d6d1c 100644 --- a/sulong/mx.sulong/mx_sulong_gate.py +++ b/sulong/mx.sulong/mx_sulong_gate.py @@ -38,8 +38,6 @@ import mx_sulong_suite_constituents import mx_sulong_unittest -import mx_sdk_vm - _suite = mx.suite('sulong') def _sulong_gate_unittest(title, test_suite, tasks, args, tags=None, testClasses=None, unittestArgs=None): @@ -169,11 +167,11 @@ def _unittest(title, test_suite, tags=None, testClasses=None, unittestArgs=None, if standaloneMode == "native": with Task('Build Native LLVM Standalone', tasks, tags=['standalone']) as t: - if t: mx.command_function('build')(['--dependencies', f'LLVM_NATIVE_STANDALONE_SVM_JAVA{mx_sdk_vm.base_jdk_version()}']) + if t: mx.command_function('build')(['--dependencies', f'SULONG_NATIVE_STANDALONE']) if standaloneMode == "jvm": with Task('Build Java LLVM Standalone', tasks, tags=['standalone']) as t: - if t: mx.command_function('build')(['--dependencies', f'LLVM_JAVA_STANDALONE_SVM_JAVA{mx_sdk_vm.base_jdk_version()}']) + if t: mx.command_function('build')(['--dependencies', f'SULONG_JVM_STANDALONE']) # Folders not containing tests: options, services, util _unittest('Benchmarks', 'SULONG_SHOOTOUT_TEST_SUITE', description="Language Benchmark game tests", testClasses=['ShootoutsSuite'], tags=['benchmarks', 'sulongMisc']) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index 632bde6df803..00ad88dd6338 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1661,7 +1661,7 @@ "mainClass": "com.oracle.truffle.llvm.launcher.LLVMLauncher", "jar_distributions": ["sulong:SULONG_LAUNCHER"], "relative_home_paths": { - "llvm": "..", + "llvm": "../lib/sulong", }, "relative_jre_path": "../jvm", "relative_module_path": "../modules", From 77eb9f3b188ebc73df8ea4d13f230ca36b89bffa Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Tue, 8 Apr 2025 14:52:27 +0200 Subject: [PATCH 12/26] Add missing implementation of NativeImageBuildTask.newestOutput. --- sdk/mx.sdk/mx_sdk_vm_ng.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_ng.py b/sdk/mx.sdk/mx_sdk_vm_ng.py index 3698291e978a..a4ef8d924878 100644 --- a/sdk/mx.sdk/mx_sdk_vm_ng.py +++ b/sdk/mx.sdk/mx_sdk_vm_ng.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -381,6 +381,9 @@ def __init__(self, args, project: NativeImageProject): max_parallelism = 12 super().__init__(project, args, min(max_parallelism, mx.cpu_count())) + def newestOutput(self): + return mx.TimeStampFile.newest([_path for _path, _ in self.subject.getArchivableResults()]) + def get_build_args(self): experimental_build_args = [ '-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json' From 67cc242aa709ffb87c51913d19202383ec4f50bd Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Mon, 14 Apr 2025 14:11:03 +0200 Subject: [PATCH 13/26] Fix base class of PolyglotIsolateProject. --- truffle/mx.truffle/mx_truffle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/truffle/mx.truffle/mx_truffle.py b/truffle/mx.truffle/mx_truffle.py index 3fac072093e6..6b274682f275 100644 --- a/truffle/mx.truffle/mx_truffle.py +++ b/truffle/mx.truffle/mx_truffle.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -1611,7 +1611,7 @@ def _qualname(distribution_name): mx.add_argument('--polyglot-isolates', action='store', help='Comma-separated list of languages for which the polyglot isolate library should be built. Setting the value to `true` builds all polyglot isolate libraries.') -class PolyglotIsolateProject(mx_sdk_vm_ng.LanguageLibraryProject): +class PolyglotIsolateProject(mx_sdk_vm_ng.NativeImageLibraryProject): """ A language library project dedicated to construct a language polyglot isolate library. Instances are created by register_polyglot_isolate_distributions when a language From 641a1e7482d4d6cf740ec8297be81ff928a51faa Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Wed, 16 Apr 2025 15:20:23 +0200 Subject: [PATCH 14/26] Don't build Sulong standalones by default. --- sulong/mx.sulong/suite.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index 00ad88dd6338..18452cf34c1c 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1670,6 +1670,7 @@ "truffle.nfi.library": "../jvmlibs/", }, "liblang_relpath": "../lib/", + "defaultBuild": False, }, "native_toolchain_wrapper": { @@ -1683,6 +1684,7 @@ "relative_jre_path": "../../../../jvm", "relative_module_path": "../../../../modules", "liblang_relpath": "../lib/", + "defaultBuild": False, }, "libllvmvm": { @@ -1697,6 +1699,7 @@ "-Dorg.graalvm.launcher.class=com.oracle.truffle.llvm.launcher.LLVMLauncher", ], "dynamicBuildArgs": "libllvmvm_build_args", + "defaultBuild": False, }, "libnativetoolchainwrappers": { @@ -1711,6 +1714,7 @@ # Configure launcher "-Dorg.graalvm.launcher.class=com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", ], + "defaultBuild": False, }, }, @@ -2016,6 +2020,7 @@ ], "dynamicDistDependencies": "sulong_standalone_deps", "maven": False, + "defaultBuild": False, }, "SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS": { @@ -2079,6 +2084,7 @@ "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", }, + "defaultBuild": False, }, "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { @@ -2090,6 +2096,7 @@ "./": "dependency:SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS/*", "lib/sulong/native/lib/": "dependency:libnativetoolchainwrappers", }, + "defaultBuild": False, }, "SULONG_STANDALONE_COMMON": { @@ -2105,6 +2112,7 @@ "bin/": "dependency:sulong_thin_launcher", "release": "dependency:sdk:STANDALONE_JAVA_HOME/release", }, + "defaultBuild": False, }, "SULONG_LIBLLVMVM": { @@ -2117,6 +2125,7 @@ "dependency:libllvmvm", ], }, + "defaultBuild": False, }, "SULONG_NATIVE_STANDALONE": { @@ -2130,6 +2139,7 @@ "dependency:SULONG_LIBLLVMVM/*", ], }, + "defaultBuild": False, }, "SULONG_JVM_STANDALONE": { @@ -2165,6 +2175,7 @@ "classpath-dependencies:SULONG_STANDALONE_DEPENDENCIES", ], }, + "defaultBuild": False, }, "SULONG_NATIVE_STANDALONE_RELEASE_ARCHIVE": { @@ -2173,6 +2184,7 @@ "standalone_dist": "SULONG_NATIVE_STANDALONE", "community_archive_name": "llvm-community", "enterprise_archive_name": "llvm", # should not be used as it lacks the managed toolchain + "defaultBuild": False, }, "SULONG_JVM_STANDALONE_RELEASE_ARCHIVE": { @@ -2181,6 +2193,7 @@ "standalone_dist": "SULONG_JVM_STANDALONE", "community_archive_name": "llvm-community-jvm", "enterprise_archive_name": "llvm-jvm", # should not be used as it lacks the managed toolchain + "defaultBuild": False, }, "SULONG_NATIVE_BITCODE_RESOURCES" : { From 034f0a5dfb012c41318bbd488027ba3a85e23981 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 17 Apr 2025 12:37:05 +0200 Subject: [PATCH 15/26] Convert native toolchain wrapper to plain native-image. --- sulong/mx.sulong/mx_sulong.py | 2 +- sulong/mx.sulong/suite.py | 137 ++++++++---------- .../toolchain/launchers/AbstractBinUtil.java | 128 ---------------- .../launchers/AbstractToolchainWrapper.java | 124 ++++++++++++++++ .../llvm/toolchain/launchers/BinUtil.java | 57 +++++++- .../launchers/NativeToolchainWrapper.java | 64 ++------ .../toolchain/launchers/common/Driver.java | 31 ++-- 7 files changed, 263 insertions(+), 280 deletions(-) delete mode 100644 sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractBinUtil.java create mode 100644 sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index 8fa36fe648f9..6471d70d1c7f 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -59,7 +59,7 @@ from mx_sulong_suite_constituents import DocumentationProject #pylint: disable=unused-import from mx_sulong_suite_constituents import HeaderProject #pylint: disable=unused-import from mx_sulong_suite_constituents import CopiedNativeProject #pylint: disable=unused-import -from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import +from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, NativeImageExecutableProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import if sys.version_info[0] < 3: def _decode(x): diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index 18452cf34c1c..7b9c22fcf350 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1673,20 +1673,6 @@ "defaultBuild": False, }, - "native_toolchain_wrapper": { - "class": "ThinLauncherProject", - "mainClass": "com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", - "jar_distributions": ["sulong:SULONG_TOOLCHAIN_LAUNCHERS"], - "relative_home_paths": { - "llvm": "../..", - "llvm-toolchain": "../../../llvm-toolchain", - }, - "relative_jre_path": "../../../../jvm", - "relative_module_path": "../../../../modules", - "liblang_relpath": "../lib/", - "defaultBuild": False, - }, - "libllvmvm": { "class": "LanguageLibraryProject", "dependencies": [ @@ -1702,17 +1688,22 @@ "defaultBuild": False, }, - "libnativetoolchainwrappers": { - "class": "NativeImageLibraryProject", + "graalvm-native-tool": { + "class": "NativeImageExecutableProject", "dependencies": [ "sulong:SULONG_TOOLCHAIN_LAUNCHERS", ], "build_args": [ - # From mx.sulong/mx_sulong.py "--initialize-at-build-time=com.oracle.truffle.llvm.toolchain.launchers", "--gc=epsilon", - # Configure launcher - "-Dorg.graalvm.launcher.class=com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", + "-H:+UnlockExperimentalVMOptions", + "-H:-ParseRuntimeOptions", + "-H:-UnlockExperimentalVMOptions", + # configure LLVM path for toolchain wrapper + # the toolchain root is lib/sulong/native, LLVM is in lib/llvm-toolchain + "-Dorg.graalvm.llvm.relative.path=../../llvm-toolchain", + # the main class + "com.oracle.truffle.llvm.toolchain.launchers.NativeToolchainWrapper", ], "defaultBuild": False, }, @@ -2023,8 +2014,8 @@ "defaultBuild": False, }, - "SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS": { - "description": "Layout for Sulong native toolchain and llvm-toolchain, with JVM wrappers", + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { + "description": "Layout for Sulong native toolchain and llvm-toolchain", "type": "dir", "platformDependent": True, "platforms": "local", @@ -2038,63 +2029,53 @@ "extracted-dependency:SULONG_NATIVE_HOME", ], - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - "lib/sulong/native/bin/": "dependency:native_toolchain_wrapper", - }, - "defaultBuild": False, - }, - - "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { - "description": "Layout for Sulong native toolchain and llvm-toolchain", - "type": "dir", - "platformDependent": True, - "platforms": "local", - "layout": { - "./": "dependency:SULONG_NATIVE_AND_LLVM_TOOLCHAIN_JVM_WRAPPERS/*", - "lib/sulong/native/lib/": "dependency:libnativetoolchainwrappers", + "lib/sulong/native/bin/": "dependency:graalvm-native-tool", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-clang", + "lib/sulong/native/bin/": "link:graalvm-native-clang", + "lib/sulong/native/bin/": "link:clang", + "lib/sulong/native/bin/": "link:clang", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-clang++", + "lib/sulong/native/bin/": "link:graalvm-native-clang++", + "lib/sulong/native/bin/": "link:clang++", + "lib/sulong/native/bin/": "link:clang++", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-clang-cl", + "lib/sulong/native/bin/": "link:graalvm-native-clang-cl", + "lib/sulong/native/bin/": "link:clang-cl", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:graalvm-native-flang", + "lib/sulong/native/bin/": "link:graalvm-native-flang", + "lib/sulong/native/bin/": "link:graalvm-native-flang", + + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-ar", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-nm", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-objcopy", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-objdump", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-ranlib", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-readelf", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-readobj", + "lib/sulong/native/bin/": "link:graalvm-native-tool", + "lib/sulong/native/bin/": "link:llvm-strip", }, "defaultBuild": False, }, diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractBinUtil.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractBinUtil.java deleted file mode 100644 index 47edf86e1bbb..000000000000 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractBinUtil.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2024, 2024, Oracle and/or its affiliates. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.oracle.truffle.llvm.toolchain.launchers; - -import com.oracle.truffle.llvm.toolchain.launchers.common.Driver; -import org.graalvm.nativeimage.ProcessProperties; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Optional; - -public abstract class AbstractBinUtil { - - public final void run(String[] args) { - String toolName = getProcessName(); - - if (toolName == null) { - System.err.println("Error: Could not figure out process name"); - System.exit(1); - } - - if (!toolName.startsWith("llvm-")) { - toolName = "llvm-" + toolName; - } - - final Path toolPath = getTargetPath(toolName); - runTool(toolPath, args); - } - - public static void runTool(Path toolPath, String[] args) { - ArrayList utilArgs = new ArrayList<>(args.length + 1); - utilArgs.add(toolPath.toString()); - if (args.length > 0) { - utilArgs.addAll(Arrays.asList(args)); - } - ProcessBuilder pb = new ProcessBuilder(utilArgs).redirectError(ProcessBuilder.Redirect.INHERIT).redirectInput(ProcessBuilder.Redirect.INHERIT).redirectOutput(ProcessBuilder.Redirect.INHERIT); - Process p = null; - try { - p = pb.start(); - p.waitFor(); - System.exit(p.exitValue()); - } catch (IOException e) { - System.err.println("Error: " + e.getMessage()); - Driver.printMissingToolMessage(Optional.ofNullable(toolPath.getParent()).map(Path::getParent).map(Path::toString).orElse("")); - System.exit(1); - } catch (InterruptedException e) { - if (p != null) { - p.destroyForcibly(); - } - System.err.println("Error: Subprocess interrupted: " + e.getMessage()); - System.exit(1); - } - } - - private static boolean isWindows() { - return System.getProperty("os.name").startsWith("Windows"); - } - - public static String getProcessName() { - String binPathName = System.getProperty("org.graalvm.launcher.executablename"); - - if (binPathName == null) { - if (isWindows()) { - binPathName = System.getenv("GRAALVM_ARGUMENT_VECTOR_PROGRAM_NAME"); - if (binPathName == null) { - return null; - } - } else { - if (ProcessProperties.getArgumentVectorBlockSize() <= 0) { - return null; - } - binPathName = ProcessProperties.getArgumentVectorProgramName(); - - if (binPathName == null) { - return null; - } - } - } - - Path p = Paths.get(binPathName); - Path f = p.getFileName(); - - if (f == null) { - return null; - } - - String result = f.toString(); - - if (isWindows()) { - result = result.replace(".cmd", ".exe"); - } - - return result; - } - - protected abstract Path getTargetPath(String binUtilName); - -} diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java new file mode 100644 index 000000000000..235e807f2f12 --- /dev/null +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.truffle.llvm.toolchain.launchers; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; + +import org.graalvm.nativeimage.ProcessProperties; + +public abstract class AbstractToolchainWrapper { + + /** + * The path of the LLVM distribution, relative to the toolchain root. This is set at + * native-image build time. + */ + private static final String RELATIVE_LLVM_PATH = System.getProperty("org.graalvm.llvm.relative.path"); + + private static ToolchainWrapperConfig config; + + public static final ToolchainWrapperConfig getConfig() { + return config; + } + + public record ToolchainWrapperConfig(String toolName, Path toolchainPath, Path llvmPath) { + } + + public interface Tool { + + void run(String[] args); + } + + private static boolean isWindows() { + return System.getProperty("os.name").startsWith("Windows"); + } + + private static Path getCurrentExecutablePath() { + final String path = ProcessProperties.getExecutableName(); + return path == null ? null : Paths.get(path); + } + + private static String getFile(Path path) { + Path file = path.getFileName(); + return file != null ? file.toString() : null; + } + + protected void run(String[] args) { + Path executablePath = getCurrentExecutablePath(); + if (executablePath == null) { + System.err.println("Error: Could not find toolchain path"); + System.exit(1); + } + + // executablePath is /bin/tool + Path toolchainPath = executablePath.getParent(); + if (toolchainPath != null) { + toolchainPath = toolchainPath.getParent(); + } + if (toolchainPath == null) { + System.err.println("Error: Could not find toolchain path"); + System.exit(1); + } + Path llvmPath = toolchainPath.resolve(RELATIVE_LLVM_PATH).normalize(); + + String binPathName = ProcessProperties.getArgumentVectorProgramName(); + if (binPathName == null) { + binPathName = getFile(executablePath); + } else { + binPathName = getFile(Paths.get(binPathName)); + } + if (binPathName == null) { + System.err.println("Error: Could not figure out process name"); + System.exit(1); + } + if (isWindows()) { + binPathName = binPathName.replace(".exe", ""); + } + + String toolName = binPathName; + for (String prefix : getStrippedPrefixes()) { + if (toolName.startsWith(prefix)) { + toolName = toolName.substring(prefix.length()); + } + } + + assert config == null : "AbstractToolchainWrapper.run called twice?"; + config = new ToolchainWrapperConfig(toolName, toolchainPath, llvmPath); + + getTool(toolName).run(args); + } + + protected Iterable getStrippedPrefixes() { + return Collections.emptyList(); + } + + protected abstract Tool getTool(String toolName); +} diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java index 247dceccd195..75cffed9c969 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. * * All rights reserved. * @@ -29,18 +29,59 @@ */ package com.oracle.truffle.llvm.toolchain.launchers; -import com.oracle.truffle.llvm.toolchain.launchers.common.Driver; - +import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Optional; + +import com.oracle.truffle.llvm.toolchain.launchers.AbstractToolchainWrapper.ToolchainWrapperConfig; +import com.oracle.truffle.llvm.toolchain.launchers.common.Driver; -public final class BinUtil extends AbstractBinUtil { +public final class BinUtil { public static void main(String[] args) { - new BinUtil().run(args); + ToolchainWrapperConfig config = AbstractToolchainWrapper.getConfig(); + + String toolName; + if (config != null) { + toolName = config.toolName(); + } else { + // this is the boostrap toolchain + toolName = System.getProperty("org.graalvm.launcher.executablename"); + } + + if (!toolName.startsWith("llvm-")) { + toolName = "llvm-" + toolName; + } + + final Path toolPath = Driver.getLLVMBinDir().resolve(toolName); + runTool(toolPath, args); } - @Override - protected Path getTargetPath(String binUtilName) { - return Driver.getLLVMBinDir().resolve(binUtilName); + public static void runTool(Path toolPath, String[] args) { + ArrayList utilArgs = new ArrayList<>(args.length + 1); + utilArgs.add(toolPath.toString()); + if (args.length > 0) { + utilArgs.addAll(Arrays.asList(args)); + } + ProcessBuilder pb = new ProcessBuilder(utilArgs).redirectError(ProcessBuilder.Redirect.INHERIT).redirectInput(ProcessBuilder.Redirect.INHERIT).redirectOutput(ProcessBuilder.Redirect.INHERIT); + Process p = null; + try { + p = pb.start(); + p.waitFor(); + System.exit(p.exitValue()); + } catch (IOException e) { + System.err.println("Error: " + e.getMessage()); + Driver.printMissingToolMessage(Optional.ofNullable(toolPath.getParent()).map(Path::getParent).map(Path::toString).orElse("")); + System.exit(1); + } catch (InterruptedException e) { + if (p != null) { + p.destroyForcibly(); + } + System.err.println("Error: Subprocess interrupted: " + e.getMessage()); + System.exit(1); + } } + } diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java index ab00c4f680f8..908b2e7e63f2 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/NativeToolchainWrapper.java @@ -29,63 +29,29 @@ */ package com.oracle.truffle.llvm.toolchain.launchers; -import java.util.List; -import java.util.Map; +import java.util.Arrays; -import org.graalvm.launcher.AbstractLanguageLauncher; -import org.graalvm.options.OptionCategory; -import org.graalvm.polyglot.Context.Builder; +public final class NativeToolchainWrapper extends AbstractToolchainWrapper { -public final class NativeToolchainWrapper extends AbstractLanguageLauncher { - - @Override - protected List preprocessArguments(List arguments, Map polyglotOptions) { - /* - * We do everything here and not in launch() to avoid making more of - * AbstractLanguageLauncher/Truffle reachable, such as - * com.oracle.truffle.polyglot.PolyglotLanguageDispatch. - */ - - String[] args = arguments.toArray(new String[0]); - - String toolName = AbstractBinUtil.getProcessName(); - if (toolName == null) { - System.err.println("Error: Could not figure out process name"); - System.exit(1); - } - - if (toolName.startsWith("graalvm-native-")) { - toolName = toolName.substring("graalvm-native-".length()); - } else if (toolName.startsWith("graalvm-")) { - toolName = toolName.substring("graalvm-".length()); - } - - switch (toolName) { - case "clang", "cc", "gcc" -> Clang.main(args); - case "clang++", "c++", "g++" -> ClangXX.main(args); - case "clang-cl", "cl" -> ClangCL.main(args); - case "ld", "ld.lld", "lld", "lld-link", "ld64" -> Linker.main(args); - case "flang-new", "flang" -> Flang.main(args); - default -> BinUtil.main(args); - } - - System.exit(0); - throw new Error("unreachable"); - } - - @Override - protected void launch(Builder contextBuilder) { - throw new UnsupportedOperationException(); + public static void main(String[] args) { + new NativeToolchainWrapper().run(args); } @Override - protected String getLanguageId() { - return ""; + protected Iterable getStrippedPrefixes() { + return Arrays.asList("graalvm-native-", "graalvm-"); } @Override - protected void printHelp(OptionCategory maxCategory) { - throw new UnsupportedOperationException(); + protected Tool getTool(String toolName) { + return switch (toolName) { + case "clang", "cc", "gcc" -> Clang::main; + case "clang++", "c++", "g++" -> ClangXX::main; + case "clang-cl", "cl" -> ClangCL::main; + case "ld", "ld.lld", "lld", "lld-link", "ld64" -> Linker::main; + case "flang-new", "flang" -> Flang::main; + default -> BinUtil::main; + }; } } diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java index ba174ff8539f..e0dea32619e0 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java @@ -32,6 +32,9 @@ import org.graalvm.home.HomeFinder; import org.graalvm.home.Version; +import com.oracle.truffle.llvm.toolchain.launchers.AbstractToolchainWrapper; +import com.oracle.truffle.llvm.toolchain.launchers.AbstractToolchainWrapper.ToolchainWrapperConfig; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -113,40 +116,36 @@ public static Arch getCurrent() { } } - private static Path getRuntimeDir() { - Path runtimeDir = HomeFinder.getInstance().getHomeFolder(); - if (runtimeDir == null) { - throw new IllegalStateException("Could not find GraalVM home"); - } - return runtimeDir; - } - public static Path getLLVMBinDir() { + // allow manually overriding custom LLVM path final String property = System.getProperty("llvm.bin.dir"); if (property != null) { return Paths.get(property); } - final String homeProperty = System.getProperty("org.graalvm.language.llvm-toolchain.home"); - if (homeProperty != null) { - return Paths.get(homeProperty).resolve("bin"); + // look up LLVM path relative to the toolchain wrapper + ToolchainWrapperConfig config = AbstractToolchainWrapper.getConfig(); + if (config != null) { + return config.llvmPath().resolve("bin"); } - // TODO (GR-18389): Set only for standalones currently + // TODO (GR-18389): Set only for old-style standalones Path toolchainHome = HomeFinder.getInstance().getLanguageHomes().get("llvm-toolchain"); if (toolchainHome != null) { return toolchainHome.resolve("bin"); } - return getRuntimeDir().resolve("lib").resolve("llvm").resolve("bin"); + return null; } public static Path getSulongHome() { - final String homeProperty = System.getProperty("org.graalvm.language.llvm.home"); - if (homeProperty != null) { - return Paths.get(homeProperty); + ToolchainWrapperConfig config = AbstractToolchainWrapper.getConfig(); + if (config != null) { + // the toolchain root is /native + return config.toolchainPath().getParent(); } + // TODO (GR-18389): Set only for old-style standalones final Path sulongHome = HomeFinder.getInstance().getLanguageHomes().get("llvm"); if (sulongHome != null) { return sulongHome; From 75f00737158b5d4562ba724370afee185e3e1b7d Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 17 Apr 2025 13:04:53 +0200 Subject: [PATCH 16/26] Fix symlinks in Sulong standalone build. --- sulong/mx.sulong/suite.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index 7b9c22fcf350..9270d712bb0e 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -2016,7 +2016,7 @@ "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { "description": "Layout for Sulong native toolchain and llvm-toolchain", - "type": "dir", + "type": "tar", "platformDependent": True, "platforms": "local", "layout": { @@ -2082,13 +2082,18 @@ "SULONG_STANDALONE_COMMON": { "description": "Common layout for Native and JVM standalones", - "type": "dir", + "type": "tar", "platformDependent": True, "platforms": "local", "layout": { "./": [ "dependency:sulong_licenses/*", - "dependency:SULONG_NATIVE_AND_LLVM_TOOLCHAIN/*", + { + "source_type": "extracted-dependency", + "dependency": "SULONG_NATIVE_AND_LLVM_TOOLCHAIN", + "path": "*", + "dereference": "never", + }, ], "bin/": "dependency:sulong_thin_launcher", "release": "dependency:sdk:STANDALONE_JAVA_HOME/release", @@ -2116,8 +2121,13 @@ "platforms": "local", "layout": { "./": [ - "dependency:SULONG_STANDALONE_COMMON/*", "dependency:SULONG_LIBLLVMVM/*", + { + "source_type": "extracted-dependency", + "dependency": "SULONG_STANDALONE_COMMON", + "path": "*", + "dereference": "never", + }, ], }, "defaultBuild": False, @@ -2130,7 +2140,12 @@ "platforms": "local", "layout": { "./": [ - "dependency:SULONG_STANDALONE_COMMON/*", + { + "source_type": "extracted-dependency", + "dependency": "SULONG_STANDALONE_COMMON", + "path": "*", + "dereference": "never", + }, ], "jvm/": { "source_type": "dependency", From 8a64f20360df3803a19d66ed610492a3948ea481 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 17 Apr 2025 17:50:09 +0200 Subject: [PATCH 17/26] Fix broken is_ee check. --- sulong/mx.sulong/mx_sulong.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index 6471d70d1c7f..d10232b05de1 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -110,11 +110,11 @@ def has_suite(name): return mx.suite(name, fatalIfMissing=False) def is_ee(): - return has_suite('graal-enterprise') + return has_suite('sulong-managed') def sulong_standalone_deps(): deps = mx_truffle.resolve_truffle_dist_names() - if has_suite('sulong-managed'): + if is_ee(): deps += [ 'sulong-managed:SULONG_ENTERPRISE', 'sulong-managed:SULONG_MANAGED', From cf814e815f4c3b9fb6d6f346d8bf3ccb89485d84 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 17 Apr 2025 18:29:18 +0200 Subject: [PATCH 18/26] Respect defaultBuild: False in DeliverableStandaloneArchive. --- sdk/mx.sdk/mx_sdk_vm_ng.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_ng.py b/sdk/mx.sdk/mx_sdk_vm_ng.py index a4ef8d924878..64420f92a0a3 100644 --- a/sdk/mx.sdk/mx_sdk_vm_ng.py +++ b/sdk/mx.sdk/mx_sdk_vm_ng.py @@ -941,7 +941,7 @@ def witness_contents(self): class DeliverableStandaloneArchive(DeliverableArchiveSuper): - def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, **kw_args): + def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, defaultBuild=True, **kw_args): standalone_dir_dist = _require(kw_args, 'standalone_dist', suite, name) community_archive_name = _require(kw_args, 'community_archive_name', suite, name) enterprise_archive_name = _require(kw_args, 'enterprise_archive_name', suite, name) @@ -966,7 +966,7 @@ def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDepen } self.standalone_dir_dist = standalone_dir_dist maven = { 'groupId': 'org.graalvm', 'tag': 'standalone' } - super().__init__(suite, name=dist_name, deps=[], layout=layout, path=None, theLicense=theLicense, platformDependent=True, path_substitutions=path_substitutions, string_substitutions=string_substitutions, maven=maven) + super().__init__(suite, name=dist_name, deps=[], layout=layout, path=None, theLicense=theLicense, platformDependent=True, path_substitutions=path_substitutions, string_substitutions=string_substitutions, maven=maven, defaultBuild=defaultBuild) self.buildDependencies.append(standalone_dir_dist) def resolveDeps(self): From d2787ac8c28657405d07dee06e287cca0642c612 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Thu, 17 Apr 2025 19:22:06 +0200 Subject: [PATCH 19/26] Convert toolchain test to use the toolchain from a standalone build. --- sulong/ci/ci.jsonnet | 6 +++--- sulong/docs/contributor/TOOLCHAIN.md | 10 +++++----- sulong/mx.sulong/mx_sulong.py | 10 +++------- sulong/mx.sulong/toolchain-only | 4 ---- vm/mx.vm/mx_vm.py | 2 -- vm/mx.vm/toolchain-only | 4 ---- 6 files changed, 11 insertions(+), 25 deletions(-) delete mode 100644 sulong/mx.sulong/toolchain-only delete mode 100644 vm/mx.vm/toolchain-only diff --git a/sulong/ci/ci.jsonnet b/sulong/ci/ci.jsonnet index 6c8bb750494b..280abc0c4d5c 100644 --- a/sulong/ci/ci.jsonnet +++ b/sulong/ci/ci.jsonnet @@ -58,9 +58,9 @@ local sc = (import "ci_common/sulong-common.jsonnet"); run+: [ ["mx", "build", "--dependencies", "SULONG_TEST"], ["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=SULONG_BOOTSTRAP_TOOLCHAIN", "ToolchainAPITest"], - ["mx", "--env", "toolchain-only", "build"], - ["set-export", "SULONG_BOOTSTRAP_GRAALVM", ["mx", "--quiet", "--no-warning", "--env", "toolchain-only", "graalvm-home"]], - ["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=GRAALVM_TOOLCHAIN_ONLY", "ToolchainAPITest"], + ["mx", "--env", "ce-llvm-standalones", "build", "--dependencies", "SULONG_JVM_STANDALONE"], + ["set-export", "SULONG_BOOTSTRAP_STANDALONE", ["mx", "--quiet", "--no-warning", "--env", "ce-llvm-standalones", "path", "--output", "SULONG_JVM_STANDALONE"]], + ["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=SULONG_JVM_STANDALONE", "ToolchainAPITest"], ], }, diff --git a/sulong/docs/contributor/TOOLCHAIN.md b/sulong/docs/contributor/TOOLCHAIN.md index 8f24b651de7b..11bf84d3749d 100644 --- a/sulong/docs/contributor/TOOLCHAIN.md +++ b/sulong/docs/contributor/TOOLCHAIN.md @@ -159,13 +159,13 @@ On the implementation side, _the toolchain_ consists of multiple ingredients: The goal is to produce a GraalVM LLVM runtime executable result by simply pointing any build system to those wrappers, for example via `CC`/`CXX` environment variables or by setting `PATH`. -## Using a Prebuilt GraalVM as a Bootstrapping Toolchain +## Using a Prebuilt standalone as a Bootstrapping Toolchain -To speed up toolchain compilation during development, the `SULONG_BOOTSTRAP_GRAALVM` environment variable can be set -to a _prebuilt_ GraalVM. Sulong comes with a configuration file that makes building a bootstrapping GraalVM easy: +To speed up toolchain compilation during development, the `SULONG_BOOTSTRAP_STANDALONE` environment variable can be set +to a _prebuilt_ standalone. ```bash -$ mx --env toolchain-only build -$ export SULONG_BOOTSTRAP_GRAALVM=`mx --env toolchain-only graalvm-home` +$ mx --env ce-llvm-standalones build --dependencies SULONG_JVM_STANDALONE +$ export SULONG_BOOTSTRAP_STANDALONE=`mx --env ce-llvm-standalones path --output SULONG_JVM_STANDALONE` ``` > **WARNING**: *The bootstrapping GraalVM will not be rebuilt automatically. You are responsible for keeping it up-to-date.* diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index d10232b05de1..c7efe6a6e813 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -420,13 +420,9 @@ def _get_toolchain_tool(name_tool): def create_toolchain_root_provider(name, dist): def provider(): - bootstrap_graalvm = mx.get_env('SULONG_BOOTSTRAP_GRAALVM') - if bootstrap_graalvm: - ret = os.path.join(bootstrap_graalvm, 'jre', 'languages', 'llvm', name) - if os.path.exists(ret): # jdk8 based graalvm - return ret - else: # jdk11+ based graalvm - return os.path.join(bootstrap_graalvm, 'languages', 'llvm', name) + bootstrap_standalone = mx.get_env('SULONG_BOOTSTRAP_STANDALONE') + if bootstrap_standalone: + return os.path.join(bootstrap_standalone, 'lib', 'sulong', name) return mx.distribution(dist).get_output() return provider diff --git a/sulong/mx.sulong/toolchain-only b/sulong/mx.sulong/toolchain-only deleted file mode 100644 index 74d1db2875d3..000000000000 --- a/sulong/mx.sulong/toolchain-only +++ /dev/null @@ -1,4 +0,0 @@ -DYNAMIC_IMPORTS=/substratevm,/vm -COMPONENTS=GraalVM compiler,Truffle Macro,LLVM Runtime Native,LLVM.org toolchain -NATIVE_IMAGES=graalvm-native-clang,graalvm-native-clang-cl,graalvm-native-clang++,graalvm-native-flang,graalvm-native-ld,graalvm-native-binutil -DISABLE_POLYGLOT=true diff --git a/vm/mx.vm/mx_vm.py b/vm/mx.vm/mx_vm.py index de4e96cc27f7..5b36f6a7fac8 100644 --- a/vm/mx.vm/mx_vm.py +++ b/vm/mx.vm/mx_vm.py @@ -161,9 +161,7 @@ def local_path_to_url(args): mx_sdk_vm.register_vm_config('ce-fastr', ce_fastr_components, _suite) mx_sdk_vm.register_vm_config('ce-no_native', ce_no_native_components, _suite) mx_sdk_vm.register_vm_config('libgraal', ['cmp', 'lg', 'sdkc', 'tflc'], _suite) -mx_sdk_vm.register_vm_config('toolchain-only', ['antlr4', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'tflm', 'nfi-libffi', 'nfi', 'cmp', 'llp', 'llrc', 'llrlf', 'llrn'], _suite) mx_sdk_vm.register_vm_config('libgraal-bash', llvm_components + ['cmp', 'gvm', 'lg', 'nfi-libffi', 'nfi', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file=False) -mx_sdk_vm.register_vm_config('toolchain-only-bash', llvm_components + ['antlr4', 'tfl', 'tfla', 'tflc', 'tflm', 'gvm', 'llp', 'nfi-libffi', 'nfi', 'svml', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'llrc', 'llrlf', 'llrn', 'cmp'], _suite, env_file=False) mx_sdk_vm.register_vm_config('ce', llvm_components + ['antlr4', 'sjsvm', 'sllvmvm', 'bnative-image', 'srubyvm', 'pynl', 'spythonvm', 'pyn', 'cmp', 'gwa', 'gwal', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'llp', 'nfi-libffi', 'nfi', 'ni', 'nil', 'pbm', 'pmh', 'pbi', 'rby', 'rbyl', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'llrc', 'llrn', 'llrl', 'llrlf', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'swasmvm', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, env_file='polybench-ce') mx_sdk_vm.register_vm_config('ce', ['bnative-image', 'bpolybench', 'cmp', 'icu4j', 'xz', 'lg', 'nfi', 'ni', 'nil', 'pbi', 'pbm', 'pmh', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'snative-image-agent', 'snative-image-diagnostics-agent', 'svm', 'svmt', 'svmnfi', 'svmsl', 'tfl', 'tfla', 'tflc', 'tflm'], _suite, dist_name='ce', env_file='polybench-ctw-ce') mx_sdk_vm.register_vm_config('ce', ['pbm', 'pmh', 'pbi', 'ni', 'icu4j', 'xz', 'js', 'jsl', 'jss', 'lg', 'nfi-libffi', 'nfi', 'tfl', 'tfla', 'tflc', 'svm', 'svmt', 'nil', 'rgx', 'sdk', 'sdkni', 'sdkc', 'sdkl', 'cmp', 'tflm', 'svmnfi', 'svmsl', 'bnative-image', 'sjsvm', 'snative-image-agent', 'snative-image-diagnostics-agent'], _suite, env_file='polybench-nfi-ce') diff --git a/vm/mx.vm/toolchain-only b/vm/mx.vm/toolchain-only deleted file mode 100644 index 8f3f39a0b6ed..000000000000 --- a/vm/mx.vm/toolchain-only +++ /dev/null @@ -1,4 +0,0 @@ -DYNAMIC_IMPORTS=/compiler,/sdk,/substratevm,/sulong,/truffle -COMPONENTS=antlr4,cmp,llp,llrc,llrn,nfi-libffi,sdk,sdkl,tfl,tfla,tflc,tflm -NATIVE_IMAGES=graalvm-native-binutil,graalvm-native-clang,graalvm-native-clang-cl,graalvm-native-clang++,graalvm-native-flang,graalvm-native-ld -DISABLE_INSTALLABLES=False From 0363d1ad959945de12b883ad3543a9fbf3c12c74 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Fri, 18 Apr 2025 10:17:23 +0200 Subject: [PATCH 20/26] Stop requesting ancient GCC version in Sulong tests. No need for dragonegg compatibility anymore. --- sulong/ci/ci.jsonnet | 4 ++-- sulong/ci/ci_common/sulong-common.jsonnet | 13 +------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/sulong/ci/ci.jsonnet b/sulong/ci/ci.jsonnet index 280abc0c4d5c..c422f030782f 100644 --- a/sulong/ci/ci.jsonnet +++ b/sulong/ci/ci.jsonnet @@ -66,13 +66,13 @@ local sc = (import "ci_common/sulong-common.jsonnet"); regular_builds:: [ $.sulong + $.gate(style=true) + sc.labsjdkLatest + sc.linux_amd64 + sc.style + { name: "gate-sulong-style-fullbuild-jdk-latest-linux-amd64" }, - $.sulong + $.gate(standalone=true) + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.requireGCC + sc.gateTags("build,sulongMisc,parser") + $.sulong_test_toolchain + { name: "gate-sulong-misc-parser-jdk-latest-linux-amd64" }, + $.sulong + $.gate(standalone=true) + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.gateTags("build,sulongMisc,parser") + $.sulong_test_toolchain + { name: "gate-sulong-misc-parser-jdk-latest-linux-amd64" }, $.sulong + $.gate() + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.gateTags("build,gcc_c") + { name: "gate-sulong-gcc_c-jdk-latest-linux-amd64", timelimit: "45:00" }, $.sulong + $.gate() + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.gateTags("build,gcc_cpp") + { name: "gate-sulong-gcc_cpp-jdk-latest-linux-amd64", timelimit: "45:00" }, $.sulong + $.gate() + sc.labsjdkLatest + sc.darwin_amd64 + sc.llvmBundled + sc.gateTags(basicTags) + { name: "gate-sulong-basic-nwcc-llvm-jdk-latest-darwin-amd64", timelimit: "0:45:00", capabilities+: ["ram16gb"] }, - $.sulong + $.gate() + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.requireGCC + sc.gateTags(basicTags) + { name: "gate-sulong-basic-nwcc-llvm-jdk-latest-linux-amd64" }, + $.sulong + $.gate() + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.gateTags(basicTags) + { name: "gate-sulong-basic-nwcc-llvm-jdk-latest-linux-amd64" }, $.sulong + $.gate() + sc.labsjdkLatest + sc.linux_aarch64 + sc.llvmBundled + sc.requireGMP + sc.gateTags(basicTagsNoNWCC) + { name: "gate-sulong-basic-llvm-jdk-latest-linux-aarch64", timelimit: "30:00" }, diff --git a/sulong/ci/ci_common/sulong-common.jsonnet b/sulong/ci/ci_common/sulong-common.jsonnet index 0fecfc28b1b9..889883ccbc5c 100644 --- a/sulong/ci/ci_common/sulong-common.jsonnet +++ b/sulong/ci/ci_common/sulong-common.jsonnet @@ -158,7 +158,7 @@ local sulong_deps = common.deps.sulong; extra_gate_args+:: ["--strict-mode"], }, - coverage(builds):: $.llvmBundled + $.requireGMP + $.optionalGCC + $.mxGate + { + coverage(builds):: $.llvmBundled + $.requireGMP + $.mxGate + { local sameArchBuilds = std.filter(function(b) b.os == self.os && b.arch == self.arch, builds), local allTags = std.set(std.flattenArrays([b.gateTags for b in sameArchBuilds if std.objectHasAll(b, "gateTags")])), local coverageTags = std.setDiff(allTags, ["build", "build-all", "fullbuild", "style"]), @@ -184,17 +184,6 @@ local sulong_deps = common.deps.sulong; llvmBundled:: {}, - requireGCC:: { - packages+: { - gcc: "==6.1.0", - }, - }, - - # like requireGCC, but only on linux/amd64, ignored otherwise - optionalGCC:: { - packages+: if self.os == "linux" && self.arch == "amd64" then $.requireGCC.packages else {}, - }, - requireGMP:: { packages+: if self.os == "darwin" && self.arch == "aarch64" then { libgmp: "==6.2.1", From dca2ec11b62de88768961d0f491aa41d7a295c34 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Fri, 18 Apr 2025 11:20:04 +0200 Subject: [PATCH 21/26] Rename unused distribution to avoid confusion. --- sulong/mx.sulong/suite.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index 9270d712bb0e..cc614381eb75 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -2179,7 +2179,7 @@ "platformDependent": True, "standalone_dist": "SULONG_NATIVE_STANDALONE", "community_archive_name": "llvm-community", - "enterprise_archive_name": "llvm", # should not be used as it lacks the managed toolchain + "enterprise_archive_name": "llvm-unused", # should not be used as it lacks the managed toolchain "defaultBuild": False, }, @@ -2188,7 +2188,7 @@ "platformDependent": True, "standalone_dist": "SULONG_JVM_STANDALONE", "community_archive_name": "llvm-community-jvm", - "enterprise_archive_name": "llvm-jvm", # should not be used as it lacks the managed toolchain + "enterprise_archive_name": "llvm-unused-jvm", # should not be used as it lacks the managed toolchain "defaultBuild": False, }, From 589ed42544bb6422e4a647226da195e906e7284b Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Fri, 18 Apr 2025 12:07:00 +0200 Subject: [PATCH 22/26] Utilize mx fix "dereference: never" in "dependency:..." layout. --- sdk/mx.sdk/mx_sdk_vm_ng.py | 7 ++++++- sulong/mx.sulong/suite.py | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_ng.py b/sdk/mx.sdk/mx_sdk_vm_ng.py index 64420f92a0a3..eb41e852384a 100644 --- a/sdk/mx.sdk/mx_sdk_vm_ng.py +++ b/sdk/mx.sdk/mx_sdk_vm_ng.py @@ -962,7 +962,12 @@ def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDepen dist_name = 'STANDALONE_' + community_archive_name.upper().replace('-', '_') layout = { - f'{dir_name}/': f'dependency:{standalone_dir_dist}/*' + f'{dir_name}/': { + "source_type": "dependency", + "dependency": standalone_dir_dist, + "path": "*", + "dereference": "never", + } } self.standalone_dir_dist = standalone_dir_dist maven = { 'groupId': 'org.graalvm', 'tag': 'standalone' } diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index cc614381eb75..b8c453ae78da 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -1,5 +1,5 @@ suite = { - "mxversion": "7.45.0", + "mxversion": "7.48.0", "name" : "sulong", "version" : "25.0.0", "release" : False, @@ -2016,7 +2016,7 @@ "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { "description": "Layout for Sulong native toolchain and llvm-toolchain", - "type": "tar", + "type": "dir", "platformDependent": True, "platforms": "local", "layout": { @@ -2082,14 +2082,14 @@ "SULONG_STANDALONE_COMMON": { "description": "Common layout for Native and JVM standalones", - "type": "tar", + "type": "dir", "platformDependent": True, "platforms": "local", "layout": { "./": [ "dependency:sulong_licenses/*", { - "source_type": "extracted-dependency", + "source_type": "dependency", "dependency": "SULONG_NATIVE_AND_LLVM_TOOLCHAIN", "path": "*", "dereference": "never", @@ -2123,7 +2123,7 @@ "./": [ "dependency:SULONG_LIBLLVMVM/*", { - "source_type": "extracted-dependency", + "source_type": "dependency", "dependency": "SULONG_STANDALONE_COMMON", "path": "*", "dereference": "never", @@ -2141,7 +2141,7 @@ "layout": { "./": [ { - "source_type": "extracted-dependency", + "source_type": "dependency", "dependency": "SULONG_STANDALONE_COMMON", "path": "*", "dereference": "never", From 7b45a619051d5d6dc04e437e93cefcabe9dbc804 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Mon, 28 Apr 2025 16:43:43 +0200 Subject: [PATCH 23/26] Use "fake" symlinks on Windows for LLVM toolchain wrappers. --- sdk/mx.sdk/mx_sdk_vm_impl.py | 12 +-- sdk/mx.sdk/mx_sdk_vm_ng.py | 45 ++++++++++- sulong/mx.sulong/mx_sulong.py | 2 +- sulong/mx.sulong/suite.py | 81 ++++++++----------- .../launchers/AbstractToolchainWrapper.java | 22 +++-- 5 files changed, 97 insertions(+), 65 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_impl.py b/sdk/mx.sdk/mx_sdk_vm_impl.py index df508ef143c6..1a8da62bf1db 100644 --- a/sdk/mx.sdk/mx_sdk_vm_impl.py +++ b/sdk/mx.sdk/mx_sdk_vm_impl.py @@ -497,11 +497,7 @@ def _add_link(_dest, _target, _component=None, _dest_base_name=None): if _linkname != dest_base_name: if mx.is_windows(): if _target.endswith('.exe') or _target.endswith('.cmd'): - link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd') - with open(link_template_name, 'r') as template: - _template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions) - _template_subst.register_no_arg('target', normpath(_linkname)) - contents = _template_subst.substitute(template.read()) + contents = mx_sdk_vm_ng._make_windows_link(_linkname) full_dest = _dest + dest_base_name[:-len('.exe')] + '.cmd' _add(layout, full_dest, 'string:{}'.format(contents), _component) return full_dest @@ -2755,11 +2751,7 @@ def add_files_from_component(comp, path_prefix, excluded_paths): link_target = relpath(launcher_dest, start=dirname(link_dest)) if mx.is_windows(): if link_target.endswith('.exe') or link_target.endswith('.cmd'): - link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd') - with open(link_template_name, 'r') as template: - _template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions) - _template_subst.register_no_arg('target', normpath(link_target)) - contents = _template_subst.substitute(template.read()) + contents = mx_sdk_vm_ng._make_windows_link(link_target) full_dest = link_dest[:-len('.exe')] + '.cmd' layout.setdefault(full_dest, []).append({ 'source_type': 'string', diff --git a/sdk/mx.sdk/mx_sdk_vm_ng.py b/sdk/mx.sdk/mx_sdk_vm_ng.py index eb41e852384a..a7f5d76f372f 100644 --- a/sdk/mx.sdk/mx_sdk_vm_ng.py +++ b/sdk/mx.sdk/mx_sdk_vm_ng.py @@ -44,7 +44,7 @@ import sys from abc import ABCMeta, abstractmethod from os import listdir, linesep -from os.path import join, exists, isfile, basename, relpath, isdir, isabs, dirname +from os.path import join, exists, isfile, basename, relpath, isdir, isabs, dirname, normpath from typing import Tuple import mx @@ -934,6 +934,49 @@ def witness_contents(self): return f"roots: {', '.join(self.subject.root_components)}\nignored: {', '.join(self.subject.ignore_components)}" +def _make_windows_link(link_target): + link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd') + with open(link_template_name, 'r') as template: + _template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions) + _template_subst.register_no_arg('target', normpath(link_target)) + return _template_subst.substitute(template.read()) + + +class ToolchainToolDistribution(mx.LayoutDirDistribution): + def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, defaultBuild=True, **kw_args): + self.tool_project = _require(kw_args, 'tool_project', suite, name) + self.tool_links = _require(kw_args, 'tool_links', suite, name) + + layout = { + './': [{ + "source_type": "dependency", + "dependency": self.tool_project, + }] + } + + super().__init__(suite, name=name, deps=[], layout=layout, path=None, theLicense=theLicense, platformDependent=True, defaultBuild=defaultBuild) + + def resolveDeps(self): + self.tool_project = mx.project(self.tool_project) + _, main_tool_name = next(self.tool_project.getArchivableResults(single=True)) + + def _add_link(name, target): + if mx.is_windows(): + # ignore indirect symlinks on windows and link everything directly to the main tool + # otherwise we lose the original program name + self.layout[f'./{name}.cmd'] = f'string:{_make_windows_link(main_tool_name)}' + else: + self.layout[f'./{name}'] = f'link:{target}' + + for tool in self.tool_links: + _add_link(tool, main_tool_name) + alt_names = self.tool_links[tool] + for alt_name in alt_names: + _add_link(alt_name, tool) + + super().resolveDeps() + + if mx.is_windows(): DeliverableArchiveSuper = mx.LayoutZIPDistribution else: diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index c7efe6a6e813..c3e381ba2d2d 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -59,7 +59,7 @@ from mx_sulong_suite_constituents import DocumentationProject #pylint: disable=unused-import from mx_sulong_suite_constituents import HeaderProject #pylint: disable=unused-import from mx_sulong_suite_constituents import CopiedNativeProject #pylint: disable=unused-import -from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, NativeImageExecutableProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive # pylint: disable=unused-import +from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, NativeImageExecutableProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive, ToolchainToolDistribution # pylint: disable=unused-import if sys.version_info[0] < 3: def _decode(x): diff --git a/sulong/mx.sulong/suite.py b/sulong/mx.sulong/suite.py index b8c453ae78da..55a8e00c0078 100644 --- a/sulong/mx.sulong/suite.py +++ b/sulong/mx.sulong/suite.py @@ -2014,13 +2014,39 @@ "defaultBuild": False, }, + "SULONG_NATIVE_TOOLS": { + "class": "ToolchainToolDistribution", + "tool_project": "graalvm-native-tool", + "tool_links": { + "graalvm-native-clang": ["graalvm-clang", "clang", "gcc", "cc"], + "graalvm-native-clang++": ["graalvm-clang++", "clang++", "g++", "c++"], + "graalvm-native-clang-cl": ["graalvm-clang-cl", "clang-cl", "cl"], + "graalvm-native-flang": ["graalvm-flang", "flang-new", "flang"], + "graalvm-native-ld": ["lld", "lld-link", "ld.lld", "ld", "ld64"], + "llvm-ar": ["ar"], + "llvm-nm": ["nm"], + "llvm-objcopy": ["objcopy"], + "llvm-objdump": ["objdump"], + "llvm-ranlib": ["ranlib"], + "llvm-readelf": ["readelf"], + "llvm-readobj": ["readobj"], + "llvm-strip": ["strip"], + }, + "maven": False, + "defaultBuild": False, + }, + "SULONG_NATIVE_AND_LLVM_TOOLCHAIN": { "description": "Layout for Sulong native toolchain and llvm-toolchain", "type": "dir", "platformDependent": True, "platforms": "local", "layout": { - "lib/llvm-toolchain/": "extracted-dependency:sdk:LLVM_TOOLCHAIN", + "lib/llvm-toolchain/": { + "source_type": "extracted-dependency", + "dependency": "sdk:LLVM_TOOLCHAIN", + "dereference": "never", + }, "lib/sulong/": [ "extracted-dependency:SULONG_CORE_HOME", @@ -2029,53 +2055,12 @@ "extracted-dependency:SULONG_NATIVE_HOME", ], - "lib/sulong/native/bin/": "dependency:graalvm-native-tool", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-clang", - "lib/sulong/native/bin/": "link:graalvm-native-clang", - "lib/sulong/native/bin/": "link:clang", - "lib/sulong/native/bin/": "link:clang", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-clang++", - "lib/sulong/native/bin/": "link:graalvm-native-clang++", - "lib/sulong/native/bin/": "link:clang++", - "lib/sulong/native/bin/": "link:clang++", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-clang-cl", - "lib/sulong/native/bin/": "link:graalvm-native-clang-cl", - "lib/sulong/native/bin/": "link:clang-cl", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:graalvm-native-flang", - "lib/sulong/native/bin/": "link:graalvm-native-flang", - "lib/sulong/native/bin/": "link:graalvm-native-flang", - - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-ar", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-nm", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-objcopy", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-objdump", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-ranlib", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-readelf", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-readobj", - "lib/sulong/native/bin/": "link:graalvm-native-tool", - "lib/sulong/native/bin/": "link:llvm-strip", + "lib/sulong/native/bin/": { + "source_type": "dependency", + "dependency": "SULONG_NATIVE_TOOLS", + "path": "*", + "dereference": "never", + }, }, "defaultBuild": False, }, diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java index 235e807f2f12..db8447cac906 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java @@ -89,21 +89,33 @@ protected void run(String[] args) { } Path llvmPath = toolchainPath.resolve(RELATIVE_LLVM_PATH).normalize(); - String binPathName = ProcessProperties.getArgumentVectorProgramName(); - if (binPathName == null) { + String programName; + if (isWindows()) { + // set by the exe_link_template.cmd wrapper script + programName = System.getenv("GRAALVM_ARGUMENT_VECTOR_PROGRAM_NAME"); + } else { + programName = ProcessProperties.getArgumentVectorProgramName(); + } + + String binPathName; + if (programName == null) { binPathName = getFile(executablePath); } else { - binPathName = getFile(Paths.get(binPathName)); + binPathName = getFile(Paths.get(programName)); } + if (binPathName == null) { System.err.println("Error: Could not figure out process name"); System.exit(1); } + + String toolName = binPathName; if (isWindows()) { - binPathName = binPathName.replace(".exe", ""); + if (toolName.endsWith(".cmd") || toolName.endsWith(".exe")) { + toolName = toolName.substring(0, toolName.length() - 4); + } } - String toolName = binPathName; for (String prefix : getStrippedPrefixes()) { if (toolName.startsWith(prefix)) { toolName = toolName.substring(prefix.length()); From b0854d608e59bdb48f4e9ec8a22d916c4cabf43e Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Tue, 29 Apr 2025 19:21:34 +0200 Subject: [PATCH 24/26] Don't break monolithic GraalVM builds (still used by some test jobs). --- .../truffle/llvm/toolchain/launchers/BinUtil.java | 15 ++++++++++++++- .../llvm/toolchain/launchers/common/Driver.java | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java index 75cffed9c969..b967cdc94aae 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/BinUtil.java @@ -31,10 +31,13 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Optional; +import org.graalvm.nativeimage.ProcessProperties; + import com.oracle.truffle.llvm.toolchain.launchers.AbstractToolchainWrapper.ToolchainWrapperConfig; import com.oracle.truffle.llvm.toolchain.launchers.common.Driver; @@ -47,8 +50,18 @@ public static void main(String[] args) { if (config != null) { toolName = config.toolName(); } else { - // this is the boostrap toolchain + // this is the boostrap toolchain... toolName = System.getProperty("org.graalvm.launcher.executablename"); + + // ... or a legacy GraalVM + if (toolName == null) { + toolName = ProcessProperties.getArgumentVectorProgramName(); + } + + Path toolPath = Paths.get(toolName).getFileName(); + if (toolPath != null) { + toolName = toolPath.toString(); + } } if (!toolName.startsWith("llvm-")) { diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java index e0dea32619e0..bc0e7713ef58 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/common/Driver.java @@ -135,7 +135,8 @@ public static Path getLLVMBinDir() { return toolchainHome.resolve("bin"); } - return null; + // TODO: Set only for old-style monolithic GraalVM builds + return HomeFinder.getInstance().getHomeFolder().resolve("lib").resolve("llvm").resolve("bin"); } public static Path getSulongHome() { From 80749408509f4e839e94f3c392424e0d0902a712 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Tue, 6 May 2025 15:16:00 +0200 Subject: [PATCH 25/26] Disambiguate error message in toolchain wrappers. --- .../llvm/toolchain/launchers/AbstractToolchainWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java index db8447cac906..752e0d71418e 100644 --- a/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java +++ b/sulong/projects/com.oracle.truffle.llvm.toolchain.launchers/src/com/oracle/truffle/llvm/toolchain/launchers/AbstractToolchainWrapper.java @@ -74,7 +74,7 @@ private static String getFile(Path path) { protected void run(String[] args) { Path executablePath = getCurrentExecutablePath(); if (executablePath == null) { - System.err.println("Error: Could not find toolchain path"); + System.err.println("Error: Could not determine current executable path"); System.exit(1); } From c2a721a8ef2d80606467f14c86741f332f9a9396 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Tue, 6 May 2025 15:26:11 +0200 Subject: [PATCH 26/26] Add comment in mx_sulong.py. --- sulong/mx.sulong/mx_sulong.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sulong/mx.sulong/mx_sulong.py b/sulong/mx.sulong/mx_sulong.py index c3e381ba2d2d..e59cdfcf0bba 100644 --- a/sulong/mx.sulong/mx_sulong.py +++ b/sulong/mx.sulong/mx_sulong.py @@ -115,6 +115,9 @@ def is_ee(): def sulong_standalone_deps(): deps = mx_truffle.resolve_truffle_dist_names() if is_ee(): + # SULONG_ENTERPRISE and SULONG_MANAGED do not belong in the EE standalone of SULONG_NATIVE, but we want a single definition of libllvmvm. + # So we compromise here by including them. We do not use or distribute the EE standalone of SULONG_NATIVE so it does not matter. + # See also the comments in suite.py, in SULONG_*_STANDALONE_RELEASE_ARCHIVE. deps += [ 'sulong-managed:SULONG_ENTERPRISE', 'sulong-managed:SULONG_MANAGED',