Skip to content

Commit

Permalink
Introduce trufflesqueak-polyglot-get
Browse files Browse the repository at this point in the history
Fixes #176
  • Loading branch information
fniephaus committed Feb 16, 2024
1 parent db1e480 commit a4d578a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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' }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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' }}
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions mx.trufflesqueak/mx_trufflesqueak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<exe:trufflesqueak>', 'bin/<exe:trufflesqueak-polyglot-get>'],
jar_distributions=['trufflesqueak:TRUFFLESQUEAK_LAUNCHER', 'sdk:MAVEN_DOWNLOADER'],
main_class='%s.launcher.TruffleSqueakLauncher' % PACKAGE_NAME,
build_args=[
'-H:+DumpThreadStacksOnSignal',
'-H:+DetectUserDirectoriesInImageHeap',
],
destination='lib/<lib:%svm>' % LANGUAGE_ID,
launchers=['bin/<exe:trufflesqueak>'],
default_vm_args=[
'--vm.Xms512M',
'--vm.Xss16M',
Expand Down
2 changes: 2 additions & 0 deletions mx.trufflesqueak/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"dependencies": [
"TRUFFLESQUEAK_SHARED",
"sdk:LAUNCHER_COMMON",
"sdk:MAVEN_DOWNLOADER",
],
"requires": [
"java.desktop",
Expand Down Expand Up @@ -352,6 +353,7 @@
"distDependencies": [
"TRUFFLESQUEAK_SHARED",
"sdk:LAUNCHER_COMMON",
"sdk:MAVEN_DOWNLOADER",
],
"maven": {
"groupId": "de.hpi.swa.trufflesqueak",
Expand Down
2 changes: 1 addition & 1 deletion mx.trufflesqueak/trufflesqueak-jvm
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions mx.trufflesqueak/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ set-env() {

set-up-dependencies() {
local kind=$1
local java_version=$2

if [[ "${kind}" == "native" ]]; then
case "$(uname -s)" in
Expand All @@ -243,15 +244,16 @@ 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}")"
fi
}

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -47,6 +50,15 @@ public static void main(final String[] arguments) throws RuntimeException {

@Override
protected List<String> preprocessArguments(final List<String> arguments, final Map<String, String> 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<String> unrecognized = new ArrayList<>();
for (int i = 0; i < arguments.size(); i++) {
final String arg = arguments.get(i);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,4 +210,34 @@ private static String getRuntimeName() {
return engine.getImplementationName();
}
}

/* Maven Downloader support */

private static void polyglotGet(final List<String> arguments) {
final String smalltalkHome = getPropertyOrFail("org.graalvm.language.smalltalk.home");
final String outputDir = smalltalkHome + File.separator + "modules";
final List<String> 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;
}
}

0 comments on commit a4d578a

Please sign in to comment.