Skip to content

Commit ea47f35

Browse files
committed
[GR-47698] Support building language launchers as multitarget projects.
PullRequest: graal/21753
2 parents 6fbc693 + d096790 commit ea47f35

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def needsBuild(self, newestInput) -> Tuple[bool, str]:
473473
ts = TimeStampFile(self.subject.output_file())
474474
if not ts.exists():
475475
return True, f"{ts.path} does not exist"
476-
if ts.isOlderThan(newestInput):
476+
if newestInput and ts.isOlderThan(newestInput):
477477
return True, f"{ts} is older than {newestInput}"
478478
previous_build_args = []
479479
command_file = self._get_command_file()
@@ -565,9 +565,14 @@ def __init__(self, suite, name, deps, workingSets, theLicense=None, **kw_args):
565565
self.relative_extracted_lib_paths = {k: v.replace('/', os.sep) for k, v in kw_args.pop('relative_extracted_lib_paths', {}).items()}
566566
self.liblang_relpath = _pop_path(kw_args, 'relative_liblang_path', None)
567567
self.setup_relative_resources = kw_args.pop('setup_relative_resources', None)
568-
# We use our LLVM toolchain on Linux because we want to statically link the C++ standard library,
569-
# and the system toolchain rarely has libstdc++.a installed (it would be an extra CI & dev dependency).
570-
toolchain = 'sdk:LLVM_NINJA_TOOLCHAIN' if mx.is_linux() else 'mx:DEFAULT_NINJA_TOOLCHAIN'
568+
569+
if not kw_args.get('multitarget'):
570+
# We use our LLVM toolchain on Linux by default because we want to statically link the C++ standard library,
571+
# and the system toolchain rarely has libstdc++.a installed (it would be an extra CI & dev dependency).
572+
toolchain = 'sdk:LLVM_NINJA_TOOLCHAIN' if mx.is_linux() else 'mx:DEFAULT_NINJA_TOOLCHAIN'
573+
else:
574+
toolchain = None
575+
571576
super().__init__(
572577
suite,
573578
name,
@@ -598,6 +603,15 @@ def isJDKDependent(self):
598603
# This must always be False, the compiled thin launchers need to work on both latest LTS JDK and jdk-latest
599604
return False
600605

606+
@property
607+
def uses_llvm_toolchain(self):
608+
return len(self.toolchains) == 1 and mx.dependency('LLVM_NINJA_TOOLCHAIN', fatalIfMissing=False) == self.toolchains[0].toolchain_dist
609+
610+
@property
611+
def uses_musl_swcfi_toolchain(self):
612+
# once GR-67435 is fixed we can revisit if we can statically link just like in the branches guarded by uses_llvm_toolchain
613+
return len(self.toolchains) == 1 and mx.dependency('BOOTSTRAP_MUSL_SWCFI_NINJA_TOOLCHAIN', fatalIfMissing=False) == self.toolchains[0].toolchain_dist
614+
601615
@property
602616
def cflags(self):
603617
_dynamic_cflags = [
@@ -610,7 +624,7 @@ def cflags(self):
610624
if not mx.is_windows():
611625
_dynamic_cflags += ['-pthread']
612626
_dynamic_cflags += ['-Werror=undef'] # fail on undefined macro used in preprocessor
613-
if mx.is_linux():
627+
if mx.is_linux() and self.uses_llvm_toolchain:
614628
_dynamic_cflags += ['-stdlib=libc++'] # to link libc++ statically, see ldlibs
615629
if mx.is_darwin():
616630
_dynamic_cflags += ['-ObjC++']
@@ -719,12 +733,18 @@ def ldflags(self):
719733
_dynamic_ldflags = []
720734
if not mx.is_windows():
721735
_dynamic_ldflags += ['-pthread']
736+
if self.uses_musl_swcfi_toolchain:
737+
# Use $$ to escape the $ from expansion by mx. If we use musl swcfi
738+
# and their libc, the libc++, libc++abi and libunwind must be
739+
# either in the LD_LIBRARY_PATH (which takes precedence) or in the
740+
# lib folder of the standalone.
741+
_dynamic_ldflags.append(r"-Wl,-rpath,'$$ORIGIN/../lib'")
722742
return super().ldflags + _dynamic_ldflags
723743

724744
@property
725745
def ldlibs(self):
726746
_dynamic_ldlibs = []
727-
if mx.is_linux():
747+
if mx.is_linux() and self.uses_llvm_toolchain:
728748
# Link libc++ statically
729749
_dynamic_ldlibs += [
730750
'-stdlib=libc++',

sdk/mx.sdk/suite.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,12 @@ class UniversalDetector {
15471547
"LLVM_NINJA_TOOLCHAIN": {
15481548
"native": True,
15491549
"platformDependent": True,
1550+
"native_toolchain": {
1551+
"kind": "ninja",
1552+
"compiler": "llvm-toolchain",
1553+
# empty, so it defaults everything to host properties
1554+
"target": {},
1555+
},
15501556
"os": {
15511557
"linux": {
15521558
"layout": {

0 commit comments

Comments
 (0)