Skip to content

Commit

Permalink
[GR-48481] Deploy python as polyglot isolate.
Browse files Browse the repository at this point in the history
PullRequest: graal/16700
  • Loading branch information
tzezula committed Apr 26, 2024
2 parents b26cb04 + c8767ef commit c9c290b
Show file tree
Hide file tree
Showing 7 changed files with 532 additions and 101 deletions.
4 changes: 1 addition & 3 deletions sdk/mx.sdk/mx_sdk_vm.py
Expand Up @@ -205,11 +205,10 @@ def __init__(self, destination, jar_distributions, build_args, jvm_library=False


class LanguageLibraryConfig(LibraryConfig):
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):
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):
"""
:param str language
:param str main_class
:param isolate_library_layout_distribution dict
"""
kwargs.pop('destination', None)
super(LanguageLibraryConfig, self).__init__('lib/<lib:' + language + 'vm>', jar_distributions, build_args, home_finder=True, headers=headers, **kwargs)
Expand All @@ -228,7 +227,6 @@ def __init__(self, jar_distributions, build_args, language, main_class=None, is_
if set_default_relative_home_path:
# Ensure the language launcher can always find the language home
self.add_relative_home_path(language, relpath('.', dirname(self.destination)))
self.isolate_library_layout_distribution = isolate_library_layout_distribution

class GraalVmComponent(object):
def __init__(self,
Expand Down
91 changes: 67 additions & 24 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Expand Up @@ -1991,6 +1991,47 @@ def getArchivableResults(self, use_relpath=True, single=False):
def is_skipped(self):
return _skip_libraries(self.native_image_config)

class PolyglotIsolateLibrary(GraalVmLibrary):
"""
A native image project dedicated to constructing a language polyglot isolate library.
Despite being built upon the component supertype, it operates independently of the component system
and native-image macros. Its configuration relies solely on the module path and META-INF/native-image
configuration files. Instances are instantiated by mx_truffle::register_polyglot_isolate_distributions
when a language dynamically registers a polyglot isolate distribution.
"""
def __init__(self, target_suite, language, deps, build_args, **kw_args):
library_config = mx_sdk.LanguageLibraryConfig(
jar_distributions=deps,
build_args=[],
build_args_enterprise=build_args,
language=language,
)
super(PolyglotIsolateLibrary, self).__init__(None, f'{language}.isolate.image',
list(deps), library_config, **kw_args)
self.suite = target_suite
self.dir = target_suite.dir


def getBuildTask(self, args):
svm_support = _get_svm_support()
assert svm_support.is_supported(), "Needs svm to build " + str(self)
if not self.is_skipped():
return PolyglotIsolateLibraryBuildTask(self, args, svm_support)
else:
return mx.NoOpTask(self, args)

def getArchivableResults(self, use_relpath=True, single=False):
for e in super(PolyglotIsolateLibrary, self).getArchivableResults(use_relpath=use_relpath, single=single):
yield e
if single:
return
output_dir = dirname(self.output_file())
resources_dir = join(output_dir, 'resources')
if exists(resources_dir):
yield resources_dir, 'resources'

def is_skipped(self):
return False

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


class PolyglotIsolateLibraryBuildTask(GraalVmLibraryBuildTask):
"""
A PolyglotIsolateLibrary build task building a language polyglot isolate library.
Despite being built upon the component supertype, it operates independently of the component system
and native-image macros. Its configuration relies solely on the module path and META-INF/native-image
configuration files.
"""
def get_build_args(self):
project = self.subject
target = project.native_image_name[:-len(_lib_suffix)]
build_args = [
'-EJVMCI_VERSION_CHECK', # Propagate this env var when running native image from mx
'--parallelism=' + str(self.parallelism),
'--shared',
'-o',
target,
'--features=com.oracle.svm.enterprise.truffle.PolyglotIsolateGuestFeature',
'-H:APIFunctionPrefix=truffle_isolate_',
] + svm_experimental_options([
'-H:+BuildOutputPrefix',
'-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json'
]) + mx.get_runtime_jvm_args(self.subject.native_image_jar_distributions) + \
project.native_image_config.build_args + project.native_image_config.build_args_enterprise
return build_args


class JmodModifier(mx.Project):
def __init__(self, jmod_file, library_projects, jimage_project, **kw_args):
"""
Expand Down Expand Up @@ -3491,7 +3558,6 @@ def register_main_dist(dist, label):
else:
with_non_rebuildable_configs = True
for library_config in _get_library_configs(component):
library_project = None
if with_svm:
library_project = GraalVmLibrary(component, GraalVmNativeImage.project_name(library_config), [], library_config)
register_project(library_project)
Expand All @@ -3509,29 +3575,6 @@ def register_main_dist(dist, label):
register_project(launcher_project)
polyglot_config_project = PolyglotConfig(component, library_config)
register_project(polyglot_config_project)
if with_svm and library_config.isolate_library_layout_distribution and not library_project.is_skipped() and has_component('tfle', stage1=True):
# Create a layout distribution with the resulting language library that can be consumed into the
# isolate resources jar distribution,
resource_base_folder = f'META-INF/resources/engine/{library_config.language}-isolate/<os>/<arch>/libvm'
attrs = {
'description': f'Contains {library_config.language} language library resources',
'hashEntry': f'{resource_base_folder}/sha256',
'fileListEntry': f'{resource_base_folder}/files',
'maven': False,
}
register_distribution(mx.LayoutDirDistribution(
suite=_suite,
name=library_config.isolate_library_layout_distribution['name'],
deps=[],
layout={
f'{resource_base_folder}/': f'dependency:{library_project.name}'
},
path=None,
platformDependent=True,
theLicense=None,
platforms=library_config.isolate_library_layout_distribution['platforms'],
**attrs
))
if isinstance(component, mx_sdk.GraalVmLanguage) and component.support_distributions:
ni_resources_components = dir_name_to_ni_resources_components.get(component.dir_name)
if not ni_resources_components:
Expand Down

0 comments on commit c9c290b

Please sign in to comment.