Skip to content

Commit c9c290b

Browse files
committed
[GR-48481] Deploy python as polyglot isolate.
PullRequest: graal/16700
2 parents b26cb04 + c8767ef commit c9c290b

File tree

7 files changed

+532
-101
lines changed

7 files changed

+532
-101
lines changed

sdk/mx.sdk/mx_sdk_vm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ def __init__(self, destination, jar_distributions, build_args, jvm_library=False
205205

206206

207207
class LanguageLibraryConfig(LibraryConfig):
208-
def __init__(self, jar_distributions, build_args, language, main_class=None, is_sdk_launcher=True, launchers=None, option_vars=None, default_vm_args=None, headers=False, set_default_relative_home_path=True, isolate_library_layout_distribution=None, **kwargs):
208+
def __init__(self, jar_distributions, build_args, language, main_class=None, is_sdk_launcher=True, launchers=None, option_vars=None, default_vm_args=None, headers=False, set_default_relative_home_path=True, **kwargs):
209209
"""
210210
:param str language
211211
:param str main_class
212-
:param isolate_library_layout_distribution dict
213212
"""
214213
kwargs.pop('destination', None)
215214
super(LanguageLibraryConfig, self).__init__('lib/<lib:' + language + 'vm>', jar_distributions, build_args, home_finder=True, headers=headers, **kwargs)
@@ -228,7 +227,6 @@ def __init__(self, jar_distributions, build_args, language, main_class=None, is_
228227
if set_default_relative_home_path:
229228
# Ensure the language launcher can always find the language home
230229
self.add_relative_home_path(language, relpath('.', dirname(self.destination)))
231-
self.isolate_library_layout_distribution = isolate_library_layout_distribution
232230

233231
class GraalVmComponent(object):
234232
def __init__(self,

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,47 @@ def getArchivableResults(self, use_relpath=True, single=False):
19911991
def is_skipped(self):
19921992
return _skip_libraries(self.native_image_config)
19931993

1994+
class PolyglotIsolateLibrary(GraalVmLibrary):
1995+
"""
1996+
A native image project dedicated to constructing a language polyglot isolate library.
1997+
Despite being built upon the component supertype, it operates independently of the component system
1998+
and native-image macros. Its configuration relies solely on the module path and META-INF/native-image
1999+
configuration files. Instances are instantiated by mx_truffle::register_polyglot_isolate_distributions
2000+
when a language dynamically registers a polyglot isolate distribution.
2001+
"""
2002+
def __init__(self, target_suite, language, deps, build_args, **kw_args):
2003+
library_config = mx_sdk.LanguageLibraryConfig(
2004+
jar_distributions=deps,
2005+
build_args=[],
2006+
build_args_enterprise=build_args,
2007+
language=language,
2008+
)
2009+
super(PolyglotIsolateLibrary, self).__init__(None, f'{language}.isolate.image',
2010+
list(deps), library_config, **kw_args)
2011+
self.suite = target_suite
2012+
self.dir = target_suite.dir
2013+
2014+
2015+
def getBuildTask(self, args):
2016+
svm_support = _get_svm_support()
2017+
assert svm_support.is_supported(), "Needs svm to build " + str(self)
2018+
if not self.is_skipped():
2019+
return PolyglotIsolateLibraryBuildTask(self, args, svm_support)
2020+
else:
2021+
return mx.NoOpTask(self, args)
2022+
2023+
def getArchivableResults(self, use_relpath=True, single=False):
2024+
for e in super(PolyglotIsolateLibrary, self).getArchivableResults(use_relpath=use_relpath, single=single):
2025+
yield e
2026+
if single:
2027+
return
2028+
output_dir = dirname(self.output_file())
2029+
resources_dir = join(output_dir, 'resources')
2030+
if exists(resources_dir):
2031+
yield resources_dir, 'resources'
2032+
2033+
def is_skipped(self):
2034+
return False
19942035

19952036
class GraalVmMiscLauncher(GraalVmLauncher): # pylint: disable=too-many-ancestors
19962037
def __init__(self, component, native_image_config, stage1=False, **kw_args):
@@ -2440,6 +2481,32 @@ class GraalVmLibraryBuildTask(GraalVmSVMNativeImageBuildTask):
24402481
pass
24412482

24422483

2484+
class PolyglotIsolateLibraryBuildTask(GraalVmLibraryBuildTask):
2485+
"""
2486+
A PolyglotIsolateLibrary build task building a language polyglot isolate library.
2487+
Despite being built upon the component supertype, it operates independently of the component system
2488+
and native-image macros. Its configuration relies solely on the module path and META-INF/native-image
2489+
configuration files.
2490+
"""
2491+
def get_build_args(self):
2492+
project = self.subject
2493+
target = project.native_image_name[:-len(_lib_suffix)]
2494+
build_args = [
2495+
'-EJVMCI_VERSION_CHECK', # Propagate this env var when running native image from mx
2496+
'--parallelism=' + str(self.parallelism),
2497+
'--shared',
2498+
'-o',
2499+
target,
2500+
'--features=com.oracle.svm.enterprise.truffle.PolyglotIsolateGuestFeature',
2501+
'-H:APIFunctionPrefix=truffle_isolate_',
2502+
] + svm_experimental_options([
2503+
'-H:+BuildOutputPrefix',
2504+
'-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json'
2505+
]) + mx.get_runtime_jvm_args(self.subject.native_image_jar_distributions) + \
2506+
project.native_image_config.build_args + project.native_image_config.build_args_enterprise
2507+
return build_args
2508+
2509+
24432510
class JmodModifier(mx.Project):
24442511
def __init__(self, jmod_file, library_projects, jimage_project, **kw_args):
24452512
"""
@@ -3491,7 +3558,6 @@ def register_main_dist(dist, label):
34913558
else:
34923559
with_non_rebuildable_configs = True
34933560
for library_config in _get_library_configs(component):
3494-
library_project = None
34953561
if with_svm:
34963562
library_project = GraalVmLibrary(component, GraalVmNativeImage.project_name(library_config), [], library_config)
34973563
register_project(library_project)
@@ -3509,29 +3575,6 @@ def register_main_dist(dist, label):
35093575
register_project(launcher_project)
35103576
polyglot_config_project = PolyglotConfig(component, library_config)
35113577
register_project(polyglot_config_project)
3512-
if with_svm and library_config.isolate_library_layout_distribution and not library_project.is_skipped() and has_component('tfle', stage1=True):
3513-
# Create a layout distribution with the resulting language library that can be consumed into the
3514-
# isolate resources jar distribution,
3515-
resource_base_folder = f'META-INF/resources/engine/{library_config.language}-isolate/<os>/<arch>/libvm'
3516-
attrs = {
3517-
'description': f'Contains {library_config.language} language library resources',
3518-
'hashEntry': f'{resource_base_folder}/sha256',
3519-
'fileListEntry': f'{resource_base_folder}/files',
3520-
'maven': False,
3521-
}
3522-
register_distribution(mx.LayoutDirDistribution(
3523-
suite=_suite,
3524-
name=library_config.isolate_library_layout_distribution['name'],
3525-
deps=[],
3526-
layout={
3527-
f'{resource_base_folder}/': f'dependency:{library_project.name}'
3528-
},
3529-
path=None,
3530-
platformDependent=True,
3531-
theLicense=None,
3532-
platforms=library_config.isolate_library_layout_distribution['platforms'],
3533-
**attrs
3534-
))
35353578
if isinstance(component, mx_sdk.GraalVmLanguage) and component.support_distributions:
35363579
ni_resources_components = dir_name_to_ni_resources_components.get(component.dir_name)
35373580
if not ni_resources_components:

0 commit comments

Comments
 (0)