Skip to content

Commit 32e7e93

Browse files
committed
sdk: Detect toolchains from BOOTSTRAP_GRAALVM and introduce <multitarget_libc_selection> path substitution
1 parent 5382a22 commit 32e7e93

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,17 @@ def _image_profiles(image):
35443544
profiles += arg[prefix_len:].split(',')
35453545
return profiles
35463546

3547+
def _multitarget_libc_selection():
3548+
full_spec = mx_native.TargetSelection.get_selection()
3549+
if len(full_spec) > 1:
3550+
mx.logv(f"Multiple targets selected: {full_spec} (first one wins)")
3551+
full_spec = full_spec[0]
3552+
ret = full_spec.libc
3553+
if full_spec.variant is not None:
3554+
ret = f"{ret}-{full_spec.variant}"
3555+
return ret
3556+
3557+
mx_subst.results_substitutions.register_no_arg('multitarget_libc_selection', _multitarget_libc_selection)
35473558

35483559
def _no_licenses():
35493560
return mx.get_opts().no_licenses or _env_var_to_bool('NO_LICENSES')

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,60 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
868868
register_distribution(mx_pomdistribution.POMDistribution(_suite, "TOOLS_FOR_STANDALONE", [], tools_dists, None, maven=False))
869869

870870

871+
# register toolchains shipped by BOOTSTRAP_GRAALVM, if any
872+
if _external_bootstrap_graalvm:
873+
toolchain_dir = join(_external_bootstrap_graalvm, "lib", "toolchains")
874+
if exists(toolchain_dir):
875+
for e in listdir(toolchain_dir):
876+
if not (e == "musl" or e.startswith("musl-")):
877+
# currently only variants of musl are detected
878+
continue
879+
880+
binpath = join(toolchain_dir, e, "bin")
881+
ninja_layout = {
882+
"toolchain.ninja" : {
883+
"source_type": "string",
884+
"value": f'''
885+
include <ninja-toolchain:GCC_NINJA_TOOLCHAIN>
886+
CC={binpath}/clang
887+
CXX={binpath}/clang++
888+
AR={binpath}/ar
889+
'''
890+
},
891+
}
892+
ninja_dependencies = ['mx:GCC_NINJA_TOOLCHAIN']
893+
ninja_native_toolchain = {
894+
'kind': 'ninja',
895+
'compiler': 'llvm',
896+
'target': {
897+
'os': mx.get_os(),
898+
'arch': mx.get_arch(),
899+
'libc': 'musl',
900+
'variant': e.split('-', 1)[1] if '-' in e else None
901+
}
902+
}
903+
ninja_name = 'BOOTSTRAP_' + e.upper().replace('-', '_') + '_NINJA_TOOLCHAIN'
904+
register_distribution(mx.LayoutDirDistribution(_suite, ninja_name, ninja_dependencies, ninja_layout, path=None, theLicense=None, platformDependent=True, native_toolchain=ninja_native_toolchain, native=True, maven=False))
905+
906+
cmake_layout = {
907+
"toolchain.cmake" : {
908+
"source_type": "string",
909+
"value": f'''
910+
set(CMAKE_C_COMPILER {binpath}/clang)
911+
set(CMAKE_CXX_COMPILER {binpath}/clang++)
912+
set(CMAKE_AR {binpath}/ar)
913+
'''
914+
},
915+
}
916+
cmake_dependencies = []
917+
cmake_native_toolchain = dict(**ninja_native_toolchain)
918+
cmake_native_toolchain['kind'] = 'cmake'
919+
cmake_name = 'BOOTSTRAP_' + e.upper().replace('-', '_') + '_CMAKE_TOOLCHAIN'
920+
register_distribution(mx.LayoutDirDistribution(_suite, cmake_name, cmake_dependencies, cmake_layout, path=None, theLicense=None, platformDependent=True, native_toolchain=cmake_native_toolchain, native=True, maven=False))
921+
922+
mx.logv(f'Registered toolchain for {e} from bootstrap GraalVM {_external_bootstrap_graalvm}')
923+
924+
871925
class DynamicPOMDistribution(mx_pomdistribution.POMDistribution):
872926
def __init__(self, suite, name, deps, excl, platformDependent, theLicense, **kw_args):
873927
dist_deps = _pop_list(kw_args, 'distDependencies', suite, name)

0 commit comments

Comments
 (0)