diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d0327a11..cd80a88ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,6 +152,17 @@ jobs: steps: - name: Clone TruffleSqueak repository uses: actions/checkout@v3 + - name: Set up Oracle GraalVM + uses: graalvm/setup-graalvm@v1 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Enable Oracle GraalVM + shell: bash + run: | + echo "EXTRA_GRAALVM_HOME=$JAVA_HOME" >> $GITHUB_ENV + cat "${JAVA_HOME}/LICENSE.txt" > "${GITHUB_WORKSPACE}/LICENSE" - name: Set up Python uses: actions/setup-python@v4 with: diff --git a/mx.trufflesqueak/mx_trufflesqueak.py b/mx.trufflesqueak/mx_trufflesqueak.py index 00a9abeaf..805441ef9 100644 --- a/mx.trufflesqueak/mx_trufflesqueak.py +++ b/mx.trufflesqueak/mx_trufflesqueak.py @@ -6,12 +6,14 @@ # import os +import shutil import sys import mx import mx_gate import mx_sdk import mx_sdk_vm +import mx_sdk_vm_impl import mx_truffle import mx_unittest @@ -174,6 +176,63 @@ def patched_init(self, *args, **kw_args): _enable_local_compression() + +def _copy_macro_and_language_jars(): + staged_dist = mx_sdk_vm_impl.get_stage1_graalvm_distribution() + staged_graalvm_home = os.path.join(staged_dist.output, staged_dist.jdk_base) + # Copy macro + macro_src_dir = os.path.join(staged_graalvm_home, 'lib', 'svm', 'macros', 'smalltalkvm-library') + macro_target_dir = os.path.join(extra_graalvm_home, 'lib', 'svm', 'macros', 'smalltalkvm-library') + if not os.path.exists(macro_src_dir): + mx.abort(f'Unable to locate macro at "{macro_src_dir}".') + if not os.path.exists(macro_target_dir): + shutil.copytree(macro_src_dir, macro_target_dir) + else: + mx.warn(f'Macros already copied to "{macro_target_dir}".') + # Copy language JARs + language_src_dir = os.path.join(staged_graalvm_home, 'languages', 'smalltalk') + language_target_dir = os.path.join(extra_graalvm_home, 'languages', 'smalltalk') + if not os.path.exists(language_src_dir): + mx.abort(f'Unable to locate language JARs at "{language_src_dir}".') + if not os.path.exists(language_target_dir): + shutil.copytree(language_src_dir, language_target_dir) + else: + mx.warn(f'Language JARs already copied to "{language_target_dir}".') + # Copy launcher JAR + launcher_src_dir = os.path.join(staged_graalvm_home, 'lib', 'graalvm', 'trufflesqueak-launcher.jar') + launcher_target_dir = os.path.join(extra_graalvm_home, 'lib', 'graalvm', 'trufflesqueak-launcher.jar') + if not os.path.exists(launcher_src_dir): + mx.abort(f'Unable to locate launcher JAR at "{launcher_src_dir}".') + if not os.path.exists(launcher_target_dir): + shutil.copyfile(launcher_src_dir, launcher_target_dir) + else: + mx.warn(f'Launcher JAR already copied to "{launcher_target_dir}".') + + +def _use_different_graalvm_home_for_native_image(extra_graalvm_home): + + def patched_native_image(self, build_args, output_file, allow_server=False, nonZeroIsFatal=True, out=None, err=None): + mx.log(f'Using EXTRA_GRAALVM_HOME at "{extra_graalvm_home}" for building...') + assert self._svm_supported + _copy_macro_and_language_jars() + native_image_bin = os.path.join(extra_graalvm_home, 'bin', mx.cmd_suffix('native-image')) + native_image_command = [native_image_bin] + build_args + output_directory = os.path.dirname(output_file) + selected_gc = 'G1' if mx.is_linux() and mx.get_arch() == 'amd64' else 'serial' + native_image_command += [ + '-H:Path=' + output_directory or ".", + '--gc=' + selected_gc, + ] + return mx.run(native_image_command, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err) + + mx_sdk_vm_impl.SvmSupport.native_image = patched_native_image + + +extra_graalvm_home = os.getenv('EXTRA_GRAALVM_HOME') +if extra_graalvm_home: + _use_different_graalvm_home_for_native_image(extra_graalvm_home) + + mx_sdk_vm.register_vm_config('trufflesqueak-jar', ['sdk', 'st', 'tfl'], _SUITE, env_file='trufflesqueak-jar') mx_sdk_vm.register_vm_config('trufflesqueak-standalone', ['cmp', 'nfi', 'nfi-libffi', 'sdk', 'st', 'tfl'],