Skip to content

Commit 277902c

Browse files
eregonrschatz
authored andcommitted
[GR-63547] Adopt the new unchained standalones for Sulong
PullRequest: graal/20381
2 parents 98dface + c2a721a commit 277902c

File tree

20 files changed

+660
-218
lines changed

20 files changed

+660
-218
lines changed

sdk/mx.sdk/mx_sdk_vm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# The Universal Permissive License (UPL), Version 1.0
@@ -263,7 +263,8 @@ def __init__(self,
263263
extra_installable_qualifiers=None,
264264
has_relative_home=True,
265265
jvm_configs=None,
266-
extra_native_targets=None):
266+
extra_native_targets=None,
267+
final_stage_only=False):
267268
"""
268269
:param suite mx.Suite: the suite this component belongs to
269270
:type name: str
@@ -281,6 +282,7 @@ def __init__(self,
281282
'priority': -1, # 0 is invalid; < 0 prepends to the default configs; > 0 appends
282283
}
283284
:param extra_native_targets: list of str, enables extra targets in multi-target projects.
285+
:param final_stage_only: bool, this component should be only included in the final GraalVM, not in stage1
284286
:type license_files: list[str]
285287
:type third_party_license_files: list[str]
286288
:type polyglot_lib_build_args: list[str]
@@ -305,6 +307,7 @@ def __init__(self,
305307
:type extra_installable_qualifiers: list[str] | None
306308
:type has_relative_home: bool
307309
:type jvm_configs: list[dict] or None
310+
:type final_stage_only: bool
308311
"""
309312
if dependencies is None:
310313
mx.logv('Component {} does not specify dependencies'.format(name))
@@ -343,6 +346,7 @@ def __init__(self,
343346
self.has_relative_home = has_relative_home
344347
self.jvm_configs = jvm_configs or []
345348
self.extra_native_targets = extra_native_targets
349+
self.final_stage_only = final_stage_only
346350

347351
if supported is not None or early_adopter:
348352
if stability is not None:

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# The Universal Permissive License (UPL), Version 1.0
@@ -166,6 +166,8 @@ def add_dependencies(dependencies, excludes=True):
166166
components = dependencies[:]
167167
while components:
168168
component = components.pop(0)
169+
if component.final_stage_only and stage1:
170+
continue
169171
if component not in components_to_build and not (excludes and is_excluded(component)):
170172
components_to_build.append(component)
171173
components.extend(component.direct_dependencies())
@@ -495,11 +497,7 @@ def _add_link(_dest, _target, _component=None, _dest_base_name=None):
495497
if _linkname != dest_base_name:
496498
if mx.is_windows():
497499
if _target.endswith('.exe') or _target.endswith('.cmd'):
498-
link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd')
499-
with open(link_template_name, 'r') as template:
500-
_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
501-
_template_subst.register_no_arg('target', normpath(_linkname))
502-
contents = _template_subst.substitute(template.read())
500+
contents = mx_sdk_vm_ng._make_windows_link(_linkname)
503501
full_dest = _dest + dest_base_name[:-len('.exe')] + '.cmd'
504502
_add(layout, full_dest, 'string:{}'.format(contents), _component)
505503
return full_dest
@@ -2753,11 +2751,7 @@ def add_files_from_component(comp, path_prefix, excluded_paths):
27532751
link_target = relpath(launcher_dest, start=dirname(link_dest))
27542752
if mx.is_windows():
27552753
if link_target.endswith('.exe') or link_target.endswith('.cmd'):
2756-
link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd')
2757-
with open(link_template_name, 'r') as template:
2758-
_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
2759-
_template_subst.register_no_arg('target', normpath(link_target))
2760-
contents = _template_subst.substitute(template.read())
2754+
contents = mx_sdk_vm_ng._make_windows_link(link_target)
27612755
full_dest = link_dest[:-len('.exe')] + '.cmd'
27622756
layout.setdefault(full_dest, []).append({
27632757
'source_type': 'string',

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# The Universal Permissive License (UPL), Version 1.0
@@ -44,7 +44,7 @@
4444
import sys
4545
from abc import ABCMeta, abstractmethod
4646
from os import listdir, linesep
47-
from os.path import join, exists, isfile, basename, relpath, isdir, isabs, dirname
47+
from os.path import join, exists, isfile, basename, relpath, isdir, isabs, dirname, normpath
4848
from typing import Tuple
4949

5050
import mx
@@ -381,6 +381,9 @@ def __init__(self, args, project: NativeImageProject):
381381
max_parallelism = 12
382382
super().__init__(project, args, min(max_parallelism, mx.cpu_count()))
383383

384+
def newestOutput(self):
385+
return mx.TimeStampFile.newest([_path for _path, _ in self.subject.getArchivableResults()])
386+
384387
def get_build_args(self):
385388
experimental_build_args = [
386389
'-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json'
@@ -931,14 +934,57 @@ def witness_contents(self):
931934
return f"roots: {', '.join(self.subject.root_components)}\nignored: {', '.join(self.subject.ignore_components)}"
932935

933936

937+
def _make_windows_link(link_target):
938+
link_template_name = join(_suite.mxDir, 'vm', 'exe_link_template.cmd')
939+
with open(link_template_name, 'r') as template:
940+
_template_subst = mx_subst.SubstitutionEngine(mx_subst.string_substitutions)
941+
_template_subst.register_no_arg('target', normpath(link_target))
942+
return _template_subst.substitute(template.read())
943+
944+
945+
class ToolchainToolDistribution(mx.LayoutDirDistribution):
946+
def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, defaultBuild=True, **kw_args):
947+
self.tool_project = _require(kw_args, 'tool_project', suite, name)
948+
self.tool_links = _require(kw_args, 'tool_links', suite, name)
949+
950+
layout = {
951+
'./': [{
952+
"source_type": "dependency",
953+
"dependency": self.tool_project,
954+
}]
955+
}
956+
957+
super().__init__(suite, name=name, deps=[], layout=layout, path=None, theLicense=theLicense, platformDependent=True, defaultBuild=defaultBuild)
958+
959+
def resolveDeps(self):
960+
self.tool_project = mx.project(self.tool_project)
961+
_, main_tool_name = next(self.tool_project.getArchivableResults(single=True))
962+
963+
def _add_link(name, target):
964+
if mx.is_windows():
965+
# ignore indirect symlinks on windows and link everything directly to the main tool
966+
# otherwise we lose the original program name
967+
self.layout[f'./{name}.cmd'] = f'string:{_make_windows_link(main_tool_name)}'
968+
else:
969+
self.layout[f'./{name}'] = f'link:{target}'
970+
971+
for tool in self.tool_links:
972+
_add_link(tool, main_tool_name)
973+
alt_names = self.tool_links[tool]
974+
for alt_name in alt_names:
975+
_add_link(alt_name, tool)
976+
977+
super().resolveDeps()
978+
979+
934980
if mx.is_windows():
935981
DeliverableArchiveSuper = mx.LayoutZIPDistribution
936982
else:
937983
DeliverableArchiveSuper = mx.LayoutTARDistribution
938984

939985

940986
class DeliverableStandaloneArchive(DeliverableArchiveSuper):
941-
def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, **kw_args):
987+
def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDependent=True, theLicense=None, defaultBuild=True, **kw_args):
942988
standalone_dir_dist = _require(kw_args, 'standalone_dist', suite, name)
943989
community_archive_name = _require(kw_args, 'community_archive_name', suite, name)
944990
enterprise_archive_name = _require(kw_args, 'enterprise_archive_name', suite, name)
@@ -959,11 +1005,16 @@ def __init__(self, suite, name=None, deps=None, excludedLibs=None, platformDepen
9591005
dist_name = 'STANDALONE_' + community_archive_name.upper().replace('-', '_')
9601006

9611007
layout = {
962-
f'{dir_name}/': f'dependency:{standalone_dir_dist}/*'
1008+
f'{dir_name}/': {
1009+
"source_type": "dependency",
1010+
"dependency": standalone_dir_dist,
1011+
"path": "*",
1012+
"dereference": "never",
1013+
}
9631014
}
9641015
self.standalone_dir_dist = standalone_dir_dist
9651016
maven = { 'groupId': 'org.graalvm', 'tag': 'standalone' }
966-
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)
1017+
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)
9671018
self.buildDependencies.append(standalone_dir_dist)
9681019

9691020
def resolveDeps(self):

sulong/ci/ci.jsonnet

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ local sc = (import "ci_common/sulong-common.jsonnet");
3939
"<graal>/regex/**",
4040
"<graal>/java-benchmarks/**",
4141
] + (if standalone then [
42+
# tools suite (included in standalone)
43+
"<graal>/tools/**",
4244
# substratevm and its dependencies
4345
"<graal>/substratevm/**",
4446
# vm and its dependencies
@@ -56,21 +58,21 @@ local sc = (import "ci_common/sulong-common.jsonnet");
5658
run+: [
5759
["mx", "build", "--dependencies", "SULONG_TEST"],
5860
["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=SULONG_BOOTSTRAP_TOOLCHAIN", "ToolchainAPITest"],
59-
["mx", "--env", "toolchain-only", "build"],
60-
["set-export", "SULONG_BOOTSTRAP_GRAALVM", ["mx", "--quiet", "--no-warning", "--env", "toolchain-only", "graalvm-home"]],
61-
["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=GRAALVM_TOOLCHAIN_ONLY", "ToolchainAPITest"],
61+
["mx", "--env", "ce-llvm-standalones", "build", "--dependencies", "SULONG_JVM_STANDALONE"],
62+
["set-export", "SULONG_BOOTSTRAP_STANDALONE", ["mx", "--quiet", "--no-warning", "--env", "ce-llvm-standalones", "path", "--output", "SULONG_JVM_STANDALONE"]],
63+
["mx", "unittest", "--verbose", "-Dsulongtest.toolchainPathPattern=SULONG_JVM_STANDALONE", "ToolchainAPITest"],
6264
],
6365
},
6466

6567
regular_builds:: [
6668
$.sulong + $.gate(style=true) + sc.labsjdkLatest + sc.linux_amd64 + sc.style + { name: "gate-sulong-style-fullbuild-jdk-latest-linux-amd64" },
67-
$.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" },
69+
$.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" },
6870
$.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" },
6971
$.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" },
7072

7173
$.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"] },
7274

73-
$.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" },
75+
$.sulong + $.gate() + sc.labsjdkLatest + sc.linux_amd64 + sc.llvmBundled + sc.requireGMP + sc.gateTags(basicTags) + { name: "gate-sulong-basic-nwcc-llvm-jdk-latest-linux-amd64" },
7476

7577
$.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" },
7678

sulong/ci/ci_common/sulong-common.jsonnet

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ local sulong_deps = common.deps.sulong;
158158
extra_gate_args+:: ["--strict-mode"],
159159
},
160160

161-
coverage(builds):: $.llvmBundled + $.requireGMP + $.optionalGCC + $.mxGate + {
161+
coverage(builds):: $.llvmBundled + $.requireGMP + $.mxGate + {
162162
local sameArchBuilds = std.filter(function(b) b.os == self.os && b.arch == self.arch, builds),
163163
local allTags = std.set(std.flattenArrays([b.gateTags for b in sameArchBuilds if std.objectHasAll(b, "gateTags")])),
164164
local coverageTags = std.setDiff(allTags, ["build", "build-all", "fullbuild", "style"]),
@@ -184,17 +184,6 @@ local sulong_deps = common.deps.sulong;
184184

185185
llvmBundled:: {},
186186

187-
requireGCC:: {
188-
packages+: {
189-
gcc: "==6.1.0",
190-
},
191-
},
192-
193-
# like requireGCC, but only on linux/amd64, ignored otherwise
194-
optionalGCC:: {
195-
packages+: if self.os == "linux" && self.arch == "amd64" then $.requireGCC.packages else {},
196-
},
197-
198187
requireGMP:: {
199188
packages+: if self.os == "darwin" && self.arch == "aarch64" then {
200189
libgmp: "==6.2.1",

sulong/docs/contributor/TOOLCHAIN.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ On the implementation side, _the toolchain_ consists of multiple ingredients:
159159
The goal is to produce a GraalVM LLVM runtime executable result by simply pointing any build system to those wrappers,
160160
for example via `CC`/`CXX` environment variables or by setting `PATH`.
161161

162-
## Using a Prebuilt GraalVM as a Bootstrapping Toolchain
162+
## Using a Prebuilt standalone as a Bootstrapping Toolchain
163163

164-
To speed up toolchain compilation during development, the `SULONG_BOOTSTRAP_GRAALVM` environment variable can be set
165-
to a _prebuilt_ GraalVM. Sulong comes with a configuration file that makes building a bootstrapping GraalVM easy:
164+
To speed up toolchain compilation during development, the `SULONG_BOOTSTRAP_STANDALONE` environment variable can be set
165+
to a _prebuilt_ standalone.
166166

167167
```bash
168-
$ mx --env toolchain-only build
169-
$ export SULONG_BOOTSTRAP_GRAALVM=`mx --env toolchain-only graalvm-home`
168+
$ mx --env ce-llvm-standalones build --dependencies SULONG_JVM_STANDALONE
169+
$ export SULONG_BOOTSTRAP_STANDALONE=`mx --env ce-llvm-standalones path --output SULONG_JVM_STANDALONE`
170170
```
171171
> **WARNING**: *The bootstrapping GraalVM will not be rebuilt automatically. You are responsible for keeping it up-to-date.*
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
DYNAMIC_IMPORTS=/substratevm,/vm
2-
COMPONENTS=llp,llrl,llrlf,llrn,lg,svmnfi,tflm,tflsm
3-
BUILD_TARGETS=GRAALVM_STANDALONES
1+
DYNAMIC_IMPORTS=/tools,/compiler,/substratevm
2+
COMPONENTS=SubstrateVM,Truffle SVM Macro,LibGraal
3+
NATIVE_IMAGES=true
4+
BUILD_TARGETS=SULONG_NATIVE_STANDALONE,SULONG_JVM_STANDALONE
5+
GRAALVM_SKIP_ARCHIVE=true

sulong/mx.sulong/mx_sulong.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import mx_sulong_gate
4848
import mx_sulong_unittest #pylint: disable=unused-import
4949
import mx_sulong_llvm_config
50+
import mx_truffle
5051

5152
# re-export custom mx project classes so they can be used from suite.py
5253
from mx_cmake import CMakeNinjaProject #pylint: disable=unused-import
@@ -58,6 +59,7 @@
5859
from mx_sulong_suite_constituents import DocumentationProject #pylint: disable=unused-import
5960
from mx_sulong_suite_constituents import HeaderProject #pylint: disable=unused-import
6061
from mx_sulong_suite_constituents import CopiedNativeProject #pylint: disable=unused-import
62+
from mx_sdk_vm_ng import StandaloneLicenses, ThinLauncherProject, NativeImageLibraryProject, NativeImageExecutableProject, LanguageLibraryProject, DynamicPOMDistribution, DeliverableStandaloneArchive, ToolchainToolDistribution # pylint: disable=unused-import
6163

6264
if sys.version_info[0] < 3:
6365
def _decode(x):
@@ -102,6 +104,36 @@ def sulong_prefix_path(name):
102104

103105
mx_subst.results_substitutions.register_with_arg('sulong_prefix', sulong_prefix_path)
104106

107+
# Functions called from suite.py
108+
109+
def has_suite(name):
110+
return mx.suite(name, fatalIfMissing=False)
111+
112+
def is_ee():
113+
return has_suite('sulong-managed')
114+
115+
def sulong_standalone_deps():
116+
deps = mx_truffle.resolve_truffle_dist_names()
117+
if is_ee():
118+
# SULONG_ENTERPRISE and SULONG_MANAGED do not belong in the EE standalone of SULONG_NATIVE, but we want a single definition of libllvmvm.
119+
# So we compromise here by including them. We do not use or distribute the EE standalone of SULONG_NATIVE so it does not matter.
120+
# See also the comments in suite.py, in SULONG_*_STANDALONE_RELEASE_ARCHIVE.
121+
deps += [
122+
'sulong-managed:SULONG_ENTERPRISE',
123+
'sulong-managed:SULONG_MANAGED',
124+
'sulong-managed:SULONG_ENTERPRISE_NATIVE',
125+
]
126+
return deps
127+
128+
def libllvmvm_build_args():
129+
if is_ee() and not mx.is_windows():
130+
return [
131+
'-H:+AuxiliaryEngineCache',
132+
'-H:ReservedAuxiliaryImageBytes=2145482548',
133+
]
134+
else:
135+
return []
136+
105137
def testLLVMImage(image, imageArgs=None, testFilter=None, libPath=True, test=None, unittestArgs=None):
106138
mx_sulong_gate.testLLVMImage(image, imageArgs, testFilter, libPath, test, unittestArgs)
107139

@@ -281,7 +313,11 @@ def get_lli_path(fatalIfMissing=True):
281313
useJvm = False
282314
else:
283315
mx.abort(f"Unknown standalone type {standaloneMode}.")
284-
path = mx_sdk_vm_impl.standalone_home("llvm", useJvm)
316+
if is_ee():
317+
dist = "SULONG_MANAGED_JVM_STANDALONE" if useJvm else "SULONG_MANAGED_NATIVE_STANDALONE"
318+
else:
319+
dist = "SULONG_JVM_STANDALONE" if useJvm else "SULONG_NATIVE_STANDALONE"
320+
path = mx.distribution(dist).output
285321
return os.path.join(path, 'bin', mx_subst.path_substitutions.substitute('<exe:lli>'))
286322

287323

@@ -387,13 +423,9 @@ def _get_toolchain_tool(name_tool):
387423

388424
def create_toolchain_root_provider(name, dist):
389425
def provider():
390-
bootstrap_graalvm = mx.get_env('SULONG_BOOTSTRAP_GRAALVM')
391-
if bootstrap_graalvm:
392-
ret = os.path.join(bootstrap_graalvm, 'jre', 'languages', 'llvm', name)
393-
if os.path.exists(ret): # jdk8 based graalvm
394-
return ret
395-
else: # jdk11+ based graalvm
396-
return os.path.join(bootstrap_graalvm, 'languages', 'llvm', name)
426+
bootstrap_standalone = mx.get_env('SULONG_BOOTSTRAP_STANDALONE')
427+
if bootstrap_standalone:
428+
return os.path.join(bootstrap_standalone, 'lib', 'sulong', name)
397429
return mx.distribution(dist).get_output()
398430
return provider
399431

@@ -408,7 +440,8 @@ def _lib_sub(program):
408440
return mx_subst.path_substitutions.substitute("<lib:{}>".format(program))
409441

410442
class ToolchainConfig(object):
411-
# Please keep this list in sync with Toolchain.java (method documentation) and ToolchainImpl.java (lookup switch block).
443+
# Please keep this list in sync with Toolchain.java (method documentation) and ToolchainImpl.java (lookup switch block)
444+
# and NativeToolchainWrapper.
412445
_llvm_tool_map = ["ar", "nm", "objcopy", "objdump", "ranlib", "readelf", "readobj", "strip"]
413446
_tool_map = {
414447
"CC": ["graalvm-{name}-clang", "graalvm-clang", "clang", "cc", "gcc"],

0 commit comments

Comments
 (0)