diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc3c84486..446d3c770 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: tar -xzf ${eclipse_tar_path} -C ${RUNNER_TEMP} echo "ECLIPSE_EXE=${RUNNER_TEMP}/eclipse/eclipse" >> "${GITHUB_ENV}" # required by mx # Set up mx, oracle/graal, and LabsJDK21 - mx.trufflesqueak/utils.sh "set-up-mx && shallow-clone-graal && set-up-labsjdk labsjdk-ce-21 ~/" + mx.trufflesqueak/utils.sh "set-up-mx && shallow-clone-graal && set-up-labsjdk 21" # Set up style dependencies sudo apt update && sudo apt install python3-pip python-setuptools jq -r '.pip | to_entries[] | .key+.value' ../graal/common.json | xargs sudo pip install @@ -54,6 +54,7 @@ jobs: matrix: os: [ubuntu-20.04, ubuntu-20.04-aarch64, macos-11, macos-14, windows-2022] java: [22] + jdk_identifier: [latest] env: RUN_WITH_COVERAGE: "${{ matrix.os == 'ubuntu-20.04' }}" MX_ENV: "trufflesqueak-jar" @@ -72,7 +73,7 @@ jobs: python-version: '3.12.0' - name: Set up dependencies shell: bash - run: mx.trufflesqueak/utils.sh set-up-dependencies jar + run: mx.trufflesqueak/utils.sh set-up-dependencies jar ${{ matrix.jdk_identifier }} - name: Build GraalVM with TruffleSqueak run: mx.trufflesqueak/utils.sh build-graalvm ${{ matrix.java }} if: ${{ runner.os != 'Windows' }} @@ -141,6 +142,7 @@ jobs: type: [native, jvm] env: JAVA_VERSION: "22" + JDK_IDENTIFIER: "latest" MX_ENV: "trufflesqueak-${{ matrix.type }}" VERBOSE_GRAALVM_LAUNCHERS: true name: ${{ matrix.type }} ${{ matrix.os }} @@ -169,7 +171,7 @@ jobs: python-version: '3.12.0' - name: Set up dependencies shell: bash - run: mx.trufflesqueak/utils.sh set-up-dependencies ${{ matrix.type }} + run: mx.trufflesqueak/utils.sh set-up-dependencies ${{ matrix.type }} ${{ env.JDK_IDENTIFIER }} - name: Build TruffleSqueak standalone run: mx.trufflesqueak/utils.sh build-standalone ${{ matrix.type }} ${{ env.JAVA_VERSION }} if: ${{ runner.os != 'Windows' }} @@ -193,6 +195,11 @@ jobs: if: ${{ runner.os == 'Windows' }} - name: Run SystemReporter on TruffleSqueak standalone run: 'trufflesqueak --code "(String streamContents: [:s | SystemReporter basicNew reportImage: s; reportVM: s; reportVMParameters: s]) withUnixLineEndings" images/test-64bit.image' + - name: Run trufflesqueak-polyglot-get on TruffleSqueak JVM standalone + run: | + trufflesqueak-polyglot-get -v 23.1.0 -a js + trufflesqueak --code "Polyglot eval: 'js' string: 'new Object({hello_world: 42})'" images/test-64bit.image + if: ${{ matrix.type == 'jvm' }} - name: Upload TruffleSqueak standalone uses: actions/upload-artifact@v4 with: diff --git a/mx.trufflesqueak/mx_trufflesqueak.py b/mx.trufflesqueak/mx_trufflesqueak.py index a81238e24..bcc35ded9 100644 --- a/mx.trufflesqueak/mx_trufflesqueak.py +++ b/mx.trufflesqueak/mx_trufflesqueak.py @@ -214,14 +214,13 @@ def patched_native_image(self, build_args, output_file, out=None, err=None, find library_configs=[ mx_sdk.LanguageLibraryConfig( language=LANGUAGE_ID, - jar_distributions=['trufflesqueak:TRUFFLESQUEAK_LAUNCHER'], + launchers=['bin/', 'bin/'], + jar_distributions=['trufflesqueak:TRUFFLESQUEAK_LAUNCHER', 'sdk:MAVEN_DOWNLOADER'], main_class='%s.launcher.TruffleSqueakLauncher' % PACKAGE_NAME, build_args=[ '-H:+DumpThreadStacksOnSignal', '-H:+DetectUserDirectoriesInImageHeap', ], - destination='lib/' % LANGUAGE_ID, - launchers=['bin/'], default_vm_args=[ '--vm.Xms512M', '--vm.Xss16M', diff --git a/mx.trufflesqueak/suite.py b/mx.trufflesqueak/suite.py index 8f785a18c..4ebde9acd 100644 --- a/mx.trufflesqueak/suite.py +++ b/mx.trufflesqueak/suite.py @@ -180,6 +180,7 @@ "dependencies": [ "TRUFFLESQUEAK_SHARED", "sdk:LAUNCHER_COMMON", + "sdk:MAVEN_DOWNLOADER", ], "requires": [ "java.desktop", @@ -352,6 +353,7 @@ "distDependencies": [ "TRUFFLESQUEAK_SHARED", "sdk:LAUNCHER_COMMON", + "sdk:MAVEN_DOWNLOADER", ], "maven": { "groupId": "de.hpi.swa.trufflesqueak", diff --git a/mx.trufflesqueak/trufflesqueak-jvm b/mx.trufflesqueak/trufflesqueak-jvm index 6b04e20b9..685a5d1ba 100644 --- a/mx.trufflesqueak/trufflesqueak-jvm +++ b/mx.trufflesqueak/trufflesqueak-jvm @@ -1,6 +1,6 @@ COMPONENTS=TruffleSqueak,suite:tools,GraalVM compiler,SubstrateVM,LibGraal DEFAULT_DYNAMIC_IMPORTS=/compiler,/substratevm,/tools,/vm INSTALLABLES=TruffleSqueak -NATIVE_IMAGES=lib:jvmcicompiler +NATIVE_IMAGES=lib:jvmcicompiler,trufflesqueak-polyglot-get BUILD_TARGETS=GRAALVM,GRAALVM_STANDALONES GRAALVM_SKIP_ARCHIVE=true diff --git a/mx.trufflesqueak/utils.sh b/mx.trufflesqueak/utils.sh index dc317040d..e49825b90 100755 --- a/mx.trufflesqueak/utils.sh +++ b/mx.trufflesqueak/utils.sh @@ -227,6 +227,7 @@ set-env() { set-up-dependencies() { local kind=$1 + local java_version=$2 if [[ "${kind}" == "native" ]]; then case "$(uname -s)" in @@ -243,7 +244,7 @@ set-up-dependencies() { set-up-mx shallow-clone-graal - set-up-labsjdk + set-up-labsjdk "${java_version}" download-trufflesqueak-test-image if [[ "${kind}" != "jar" ]]; then set-env "STANDALONE_TARGET" "$(filename-standalone "${kind}")" @@ -251,7 +252,8 @@ set-up-dependencies() { } set-up-labsjdk() { - local jdk_id="labsjdk-ce-latest" + local java_version=$1 + local jdk_id="labsjdk-ce-${java_version}" local target_dir="${RUNNER_TEMP}/jdk" local dl_dir="${RUNNER_TEMP}/jdk-dl" local mx_suffix="" && [[ "${OS_NAME}" == "windows" ]] && mx_suffix=".cmd" diff --git a/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java b/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java index bb755d6ad..5526e3ab5 100644 --- a/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java +++ b/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java @@ -17,6 +17,7 @@ import java.util.Set; import org.graalvm.launcher.AbstractLanguageLauncher; +import org.graalvm.maven.downloader.Main; import org.graalvm.options.OptionCategory; import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Engine; @@ -32,6 +33,8 @@ public final class TruffleSqueakLauncher extends AbstractLanguageLauncher { private static final String ENGINE_MODE_OPTION = "engine.Mode"; private static final String ENGINE_MODE_LATENCY = "latency"; + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + private boolean headless; private boolean printImagePath; private boolean quiet; @@ -47,6 +50,15 @@ public static void main(final String[] arguments) throws RuntimeException { @Override protected List preprocessArguments(final List arguments, final Map polyglotOptions) { + final String launcherName = System.getProperty("org.graalvm.launcher.executablename", "trufflesqueak"); + if (launcherName.endsWith("trufflesqueak-polyglot-get") || launcherName.endsWith("trufflesqueak-polyglot-get.exe")) { + if (isAOT()) { + throw abort("trufflesqueak-polyglot-get is not available in a native standalone. Please try again with a JVM standalone of TruffleSqueak."); + } else { + polyglotGet(arguments); + } + } + final List unrecognized = new ArrayList<>(); for (int i = 0; i < arguments.size(); i++) { final String arg = arguments.get(i); @@ -165,7 +177,7 @@ protected String getMainClass() { @Override protected String[] getDefaultLanguages() { - return new String[0]; // Allow all languages (same effect of `--polyglot`) + return EMPTY_STRING_ARRAY; // Allow all languages (same effect of `--polyglot`) } @Override @@ -198,4 +210,34 @@ private static String getRuntimeName() { return engine.getImplementationName(); } } + + /* Maven Downloader support */ + + private static void polyglotGet(final List arguments) { + final String smalltalkHome = getPropertyOrFail("org.graalvm.language.smalltalk.home"); + final String outputDir = smalltalkHome + File.separator + "modules"; + final List args = new ArrayList<>(); + args.add("-o"); + args.add(outputDir); + args.add("-v"); + args.add(getPropertyOrFail("org.graalvm.version")); + if (arguments.size() == 1 && !arguments.get(0).startsWith("-")) { + args.add("-a"); + } + args.addAll(arguments); + try { + Main.main(args.toArray(EMPTY_STRING_ARRAY)); + } catch (Exception e) { + throw new Error(e); + } + System.exit(0); + } + + private static String getPropertyOrFail(final String property) { + final String value = System.getProperty(property); + if (value == null) { + throw new UnsupportedOperationException("Expected system property '" + property + "' to be set"); + } + return value; + } }