Skip to content

Commit 46e36ff

Browse files
committed
[GR-63732] Migrate polyglot isolate build to use common mx_sdk_vm_ng.py projects.
PullRequest: graal/20451
2 parents 3619d49 + 173709b commit 46e36ff

File tree

3 files changed

+35
-83
lines changed

3 files changed

+35
-83
lines changed

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,47 +1986,6 @@ def getArchivableResults(self, use_relpath=True, single=False):
19861986
def is_skipped(self):
19871987
return _skip_libraries(self.native_image_config)
19881988

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

20311990
class GraalVmMiscLauncher(GraalVmLauncher): # pylint: disable=too-many-ancestors
20321991
def __init__(self, component, native_image_config, stage1=False, **kw_args):
@@ -2481,33 +2440,6 @@ class GraalVmLibraryBuildTask(GraalVmSVMNativeImageBuildTask):
24812440
pass
24822441

24832442

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:+IgnoreMaxHeapSizeWhileInVMOperation',
2504-
'-H:+CopyLanguageResources',
2505-
'-H:+GenerateBuildArtifactsFile', # generate 'build-artifacts.json'
2506-
]) + mx.get_runtime_jvm_args(self.subject.native_image_jar_distributions) + \
2507-
project.native_image_config.build_args + project.native_image_config.build_args_enterprise
2508-
return build_args
2509-
2510-
25112443
class JmodModifier(mx.Project):
25122444
def __init__(self, jmod_file, library_projects, jimage_project, **kw_args):
25132445
"""

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ def clean(self, forBuild=False):
201201
mx.rmtree(self.witness_file(), ignore_errors=True)
202202

203203
class NativeImageProject(mx.Project, metaclass=ABCMeta):
204-
def __init__(self, suite, name, deps, workingSets, theLicense=None, **kw_args):
204+
def __init__(self, suite, name, deps, workingSets, theLicense=None, deliverable=None, **kw_args):
205205
super().__init__(suite, name, subDir=None, srcDirs=[], deps=deps, workingSets=workingSets, d=suite.dir, theLicense=theLicense, **kw_args)
206+
self.deliverable = deliverable if deliverable else name
206207
if not hasattr(self, 'buildDependencies'):
207208
self.buildDependencies = []
208209
if not _external_bootstrap_graalvm and _has_stage1_components():
@@ -221,9 +222,8 @@ def output_file(self):
221222
def output_file_name(self):
222223
pass
223224

224-
@abstractmethod
225225
def base_file_name(self):
226-
pass
226+
return self.deliverable
227227

228228
@abstractmethod
229229
def options_file_name(self):
@@ -294,9 +294,6 @@ def resolveDeps(self):
294294
if mx_sdk_vm_impl._force_bash_launchers(self.output_file_name(), build_by_default=True):
295295
self.ignore = "Skipped executable"
296296

297-
def base_file_name(self):
298-
return self.name
299-
300297
def output_file_name(self):
301298
return mx.exe_suffix(self.base_file_name())
302299

@@ -307,6 +304,12 @@ def name_suffix(self):
307304
return mx.exe_suffix("")
308305

309306
class NativeImageLibraryProject(NativeImageProject):
307+
308+
def __init__(self, suite, name, deps, workingSets, theLicense=None, deliverable=None, **kw_args):
309+
if not deliverable:
310+
deliverable = name[3:] if name.startswith('lib') else name
311+
super().__init__(suite, name, deps, workingSets, theLicense, deliverable, **kw_args)
312+
310313
def resolveDeps(self):
311314
super().resolveDeps()
312315
if mx_sdk_vm_impl._skip_libraries(self.output_file_name(), build_by_default=True):
@@ -324,12 +327,6 @@ def getArchivableResults(self, use_relpath=True, single=False):
324327
if isfile(absolute_path) and e.endswith('.h'):
325328
yield absolute_path, e
326329

327-
def base_file_name(self):
328-
name = self.name
329-
if name.startswith('lib'):
330-
name = name[3:]
331-
return name
332-
333330
def output_file_name(self):
334331
return mx.add_lib_prefix(mx.add_lib_suffix(self.base_file_name()))
335332

truffle/mx.truffle/mx_truffle.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import mx_sdk
5959
import mx_sdk_vm
6060
import mx_sdk_vm_impl
61+
import mx_sdk_vm_ng
6162
import mx_subst
6263
import mx_unittest
6364
import mx_jardistribution
@@ -1492,7 +1493,7 @@ def _qualname(distribution_name):
14921493
if build_for_current_platform:
14931494
# 2. Register a project building the isolate library
14941495
isolate_deps = [language_pom_distribution, 'truffle-enterprise:TRUFFLE_ENTERPRISE']
1495-
build_library = mx_sdk_vm_impl.PolyglotIsolateLibrary(language_suite, language_id, isolate_deps, isolate_build_options)
1496+
build_library = PolyglotIsolateProject(language_suite, language_id, isolate_deps, isolate_build_options)
14961497
register_project(build_library)
14971498

14981499
# 3. Register layout distribution with isolate library and isolate resources
@@ -1509,9 +1510,9 @@ def _qualname(distribution_name):
15091510
deps=[],
15101511
layout={
15111512
f'{resource_base_folder}/': f'dependency:{build_library.name}',
1512-
f'{resource_base_folder}/resources': {"source_type": "dependency",
1513+
f'{resource_base_folder}/resources/': {"source_type": "dependency",
15131514
"dependency": f'{build_library.name}',
1514-
"path": 'resources',
1515+
"path": 'language_resources/resources/*',
15151516
"optional": True},
15161517
},
15171518
path=None,
@@ -1610,6 +1611,28 @@ def _qualname(distribution_name):
16101611
mx.add_argument('--polyglot-isolates', action='store', help='Comma-separated list of languages for which the polyglot isolate library should be built. Setting the value to `true` builds all polyglot isolate libraries.')
16111612

16121613

1614+
class PolyglotIsolateProject(mx_sdk_vm_ng.LanguageLibraryProject):
1615+
"""
1616+
A language library project dedicated to construct a language polyglot isolate library.
1617+
Instances are created by register_polyglot_isolate_distributions when a language
1618+
dynamically registers a polyglot isolate distribution.
1619+
"""
1620+
def __init__(self, language_suite, language_id, isolate_deps, isolate_build_options):
1621+
build_args = [
1622+
'--features=com.oracle.svm.enterprise.truffle.PolyglotIsolateGuestFeature',
1623+
'-H:APIFunctionPrefix=truffle_isolate_',
1624+
'-H:+CopyLanguageResources'
1625+
] + isolate_build_options
1626+
super().__init__(language_suite, f'{language_id}.isolate', isolate_deps, ['Truffle'], None, f'{language_id}vm', **{'build_args': build_args})
1627+
1628+
def resolveDeps(self):
1629+
super().resolveDeps()
1630+
# The polyglot isolate build does not use the --native-images option; it uses its own --polyglot-isolates option.
1631+
# The parent NativeImageLibraryProject uses mx_sdk_vm_impl._skip_libraries which marks the project as ignored.
1632+
# We need to remove the ignore flag
1633+
delattr(self, 'ignore')
1634+
1635+
16131636
class LibffiBuilderProject(mx.AbstractNativeProject, mx_native.NativeDependency): # pylint: disable=too-many-ancestors
16141637
"""Project for building libffi from source.
16151638

0 commit comments

Comments
 (0)