mirror of
https://github.com/apple/pkl.git
synced 2026-05-16 20:07:00 +02:00
Make Truffle use fallback runtime in Gradle plugin (#995)
Using native libraries in Gradle plugins is problematic; this adds some flags that causes Truffle to use a fallback runtime that avoids loading native libraries.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -49,6 +49,11 @@ import org.pkl.core.util.Nullable;
|
|||||||
import org.pkl.gradle.utils.PluginUtils;
|
import org.pkl.gradle.utils.PluginUtils;
|
||||||
|
|
||||||
public abstract class BasePklTask extends DefaultTask {
|
public abstract class BasePklTask extends DefaultTask {
|
||||||
|
private static final String TRUFFLE_USE_FALLBACK_RUNTIME_FLAG = "truffle.UseFallbackRuntime";
|
||||||
|
|
||||||
|
private static final String POLYGLOT_WARN_INTERPRETER_ONLY_FLAG =
|
||||||
|
"polyglot.engine.WarnInterpreterOnly";
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
public abstract ListProperty<String> getAllowedModules();
|
public abstract ListProperty<String> getAllowedModules();
|
||||||
|
|
||||||
@@ -137,9 +142,26 @@ public abstract class BasePklTask extends DefaultTask {
|
|||||||
@Optional
|
@Optional
|
||||||
public abstract ListProperty<String> getHttpNoProxy();
|
public abstract ListProperty<String> getHttpNoProxy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There are issues with using native libraries in Gradle plugins. As a workaround for now, make
|
||||||
|
* Truffle use an un-optimized runtime.
|
||||||
|
*
|
||||||
|
* @see <a
|
||||||
|
* href="https://discuss.gradle.org/t/loading-a-native-library-in-a-gradle-plugin/44854">https://discuss.gradle.org/t/loading-a-native-library-in-a-gradle-plugin/44854</a>
|
||||||
|
* @see <a
|
||||||
|
* href="https://github.com/apple/pkl/issues/988">https://github.com/apple/pkl/issues/988</a>
|
||||||
|
*/
|
||||||
|
// TODO: Remove this workaround when ugprading to Truffle 24.2+ (Truffle automatically falls back
|
||||||
|
// in this scenario).
|
||||||
|
protected void withFallbackTruffleRuntime(Runnable task) {
|
||||||
|
System.setProperty(TRUFFLE_USE_FALLBACK_RUNTIME_FLAG, "true");
|
||||||
|
System.setProperty(POLYGLOT_WARN_INTERPRETER_ONLY_FLAG, "false");
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void runTask() {
|
public void runTask() {
|
||||||
doRunTask();
|
withFallbackTruffleRuntime(this::doRunTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doRunTask();
|
protected abstract void doRunTask();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -133,7 +133,7 @@ public abstract class ModulesTask extends BasePklTask {
|
|||||||
if (getCliBaseOptions().getNormalizedSourceModules().isEmpty()) {
|
if (getCliBaseOptions().getNormalizedSourceModules().isEmpty()) {
|
||||||
throw new InvalidUserDataException("No source modules specified.");
|
throw new InvalidUserDataException("No source modules specified.");
|
||||||
}
|
}
|
||||||
doRunTask();
|
withFallbackTruffleRuntime(this::doRunTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user