Skip to content

Commit 525acb0

Browse files
olpawfniephaus
authored andcommitted
[GR-43920] Implement containerized native image building for native image bundles #6496.
PullRequest: graal/14927
2 parents 91267e3 + 1cf010d commit 525acb0

File tree

26 files changed

+2148
-157
lines changed

26 files changed

+2148
-157
lines changed

docs/reference-manual/native-image/Bundles.md

Lines changed: 153 additions & 17 deletions
Large diffs are not rendered by default.

substratevm/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This changelog summarizes major changes to GraalVM Native Image.
1717
* (GR-27034) Add `-H:ImageBuildID` option to generate Image Build ID, which is a 128-bit UUID string generated randomly, once per bundle or digest of input args when bundles are not used.
1818
* (GR-47647) Add `-H:±UnlockExperimentalVMOptions` for unlocking access to experimental options similar to HotSpot's `-XX:UnlockExperimentalVMOptions`. Explicit unlocking will be required in a future release, which can be tested with the env setting `NATIVE_IMAGE_EXPERIMENTAL_OPTIONS_ARE_FATAL=true`. For more details, see [issue #7105](https://github.com/oracle/graal/issues/7105).
1919
* (GR-47647) Add `--color[=WHEN]` option to color the output WHEN ('always', 'never', or 'auto'). This API option supersedes the experimental option `-H:+BuildOutputColorful`.
20+
* (GR-43920) Add support for executing native image bundles as jar files with extra options `--with-native-image-agent` and `--container`.
21+
* (GR-43920) Add `,container[=<container-tool>]`, `,dockerfile=<dockerfile>` and `,dry-run` options to `--bundle-create`and `--bundle-apply`.
2022

2123
## GraalVM for JDK 17 and GraalVM for JDK 20 (Internal Version 23.0.0)
2224
* (GR-40187) Report invalid use of SVM specific classes on image class- or module-path as error. As a temporary workaround, `-H:+AllowDeprecatedBuilderClassesOnImageClasspath` allows turning the error into a warning.

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ def _native_image_launcher_extra_jvm_args():
10171017
'--initialize-at-build-time=com.oracle.svm.driver',
10181018
'--link-at-build-time=com.oracle.svm.driver,com.oracle.svm.driver.metainf',
10191019
] + svm_experimental_options([
1020+
'-H:IncludeResources=com/oracle/svm/driver/launcher/.*',
10201021
'-H:-ParseRuntimeOptions',
10211022
])
10221023

substratevm/mx.substratevm/suite.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@
842842
],
843843
"dependencies": [
844844
"com.oracle.svm.hosted",
845+
"com.oracle.svm.driver.launcher",
845846
],
846847
"requires" : [
847848
"jdk.management",
@@ -857,6 +858,23 @@
857858
"jacoco" : "exclude",
858859
},
859860

861+
"com.oracle.svm.driver.launcher": {
862+
"subDir": "src",
863+
"sourceDirs": [
864+
"src",
865+
"resources"
866+
],
867+
"checkstyle": "com.oracle.svm.hosted",
868+
"workingSets": "SVM",
869+
"annotationProcessors": [
870+
"compiler:GRAAL_PROCESSOR",
871+
"SVM_PROCESSOR",
872+
],
873+
"javaCompliance" : "17+",
874+
"spotbugs": "false",
875+
"jacoco" : "exclude",
876+
},
877+
860878
"com.oracle.svm.junit": {
861879
"subDir": "src",
862880
"sourceDirs": [
@@ -1705,6 +1723,7 @@
17051723
"mainClass": "com.oracle.svm.driver.NativeImage",
17061724
"dependencies": [
17071725
"com.oracle.svm.driver",
1726+
"com.oracle.svm.driver.launcher",
17081727
"svm-compiler-flags-builder",
17091728
],
17101729
"distDependencies": [

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/NativeImageClassLoaderOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public class NativeImageClassLoaderOptions {
3535

3636
public static final String AddReadsFormat = "<module>=<target-module>(,<target-module>)*";
3737

38-
@APIOption(name = "add-exports", extra = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
38+
@APIOption(name = "add-exports", extra = true, launcherOption = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
3939
@Option(help = "Value " + AddExportsAndOpensFormat + " updates <module> to export <package> to <target-module>, regardless of module declaration." +
4040
" <target-module> can be ALL-UNNAMED to export to all unnamed modules.")//
4141
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> AddExports = new HostedOptionKey<>(LocatableMultiOptionValue.Strings.build());
4242

43-
@APIOption(name = "add-opens", extra = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
43+
@APIOption(name = "add-opens", extra = true, launcherOption = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
4444
@Option(help = "Value " + AddExportsAndOpensFormat + " updates <module> to open <package> to <target-module>, regardless of module declaration.")//
4545
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> AddOpens = new HostedOptionKey<>(LocatableMultiOptionValue.Strings.build());
4646

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/RuntimeAssertionsSupport.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,16 @@ public static class Options {
9191

9292
private static final char VALUE_SEPARATOR = ':';
9393

94-
@APIOption(name = {"-ea", "-enableassertions"}, valueSeparator = VALUE_SEPARATOR, valueTransformer = RuntimeAssertionsOptionTransformer.Enable.class, defaultValue = "", //
94+
@APIOption(name = {"-ea", "-enableassertions"}, launcherOption = true, valueSeparator = VALUE_SEPARATOR, valueTransformer = RuntimeAssertionsOptionTransformer.Enable.class, defaultValue = "", //
9595
customHelp = "also -ea[:[packagename]...|:classname] or -enableassertions[:[packagename]...|:classname]. Enable assertions with specified granularity at run time.")//
96-
@APIOption(name = {"-da", "-disableassertions"}, valueSeparator = VALUE_SEPARATOR, valueTransformer = RuntimeAssertionsOptionTransformer.Disable.class, defaultValue = "", //
96+
@APIOption(name = {"-da",
97+
"-disableassertions"}, launcherOption = true, valueSeparator = VALUE_SEPARATOR, valueTransformer = RuntimeAssertionsOptionTransformer.Disable.class, defaultValue = "", //
9798
customHelp = "also -da[:[packagename]...|:classname] or -disableassertions[:[packagename]...|:classname]. Disable assertions with specified granularity at run time.")//
9899
@Option(help = "Enable or disable Java assert statements at run time") //
99100
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> RuntimeAssertions = new HostedOptionKey<>(LocatableMultiOptionValue.Strings.build());
100101

101-
@APIOption(name = {"-esa", "-enablesystemassertions"}, customHelp = "also -enablesystemassertions. Enables assertions in all system classes at run time.") //
102-
@APIOption(name = {"-dsa", "-disablesystemassertions"}, kind = APIOption.APIOptionKind.Negated, //
102+
@APIOption(name = {"-esa", "-enablesystemassertions"}, launcherOption = true, customHelp = "also -enablesystemassertions. Enables assertions in all system classes at run time.") //
103+
@APIOption(name = {"-dsa", "-disablesystemassertions"}, launcherOption = true, kind = APIOption.APIOptionKind.Negated, //
103104
customHelp = "also -disablesystemassertions. Disables assertions in all system classes at run time.") //
104105
@Option(help = "Enable or disable Java system assertions at run time") //
105106
public static final HostedOptionKey<Boolean> RuntimeSystemAssertions = new HostedOptionKey<>(false);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ public static boolean parseOnce() {
116116
@Option(help = "Build statically linked executable (requires static libc and zlib)")//
117117
public static final HostedOptionKey<Boolean> StaticExecutable = new HostedOptionKey<>(false);
118118

119+
@APIOption(name = "libc")//
120+
@Option(help = "Selects the libc implementation to use. Available implementations: glibc, musl, bionic")//
121+
public static final HostedOptionKey<String> UseLibC = new HostedOptionKey<>(null) {
122+
@Override
123+
public String getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> values) {
124+
if (!values.containsKey(this)) {
125+
return Platform.includedIn(Platform.ANDROID.class)
126+
? "bionic"
127+
: System.getProperty("substratevm.HostLibC", "glibc");
128+
}
129+
return (String) values.get(this);
130+
}
131+
132+
@Override
133+
public String getValue(OptionValues values) {
134+
assert checkDescriptorExists();
135+
return getValueOrDefault(values.getMap());
136+
}
137+
};
138+
119139
@APIOption(name = "target")//
120140
@Option(help = "Selects native-image compilation target (in <OS>-<architecture> format). Defaults to host's OS-architecture pair.")//
121141
public static final HostedOptionKey<String> TargetPlatform = new HostedOptionKey<>("") {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/APIOption.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
*/
6262
boolean extra() default false;
6363

64+
/**
65+
* This option should be stored in a native image bundle and passed to the jvm when executed
66+
* with {@code com.oracle.svm.driver.launcher.BundleLauncher}.
67+
*/
68+
boolean launcherOption() default false;
69+
6470
/**
6571
* Make a boolean option part of a group of boolean options.
6672
**/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This Native Image Bundle launcher allows running the bundled application.
2+
3+
Usage: java -jar bundle-file [options] [bundle-application-options]
4+
5+
where options include:
6+
7+
--with-native-image-agent[,update-bundle[=<new-bundle-name>]]
8+
runs the application with a native-image-agent attached
9+
'update-bundle' adds the agents output to the bundle-files classpath.
10+
'=<new-bundle-name>' creates a new bundle with the agent output instead.
11+
Note 'update-bundle' requires native-image to be installed
12+
13+
--container[=<container-tool>][,dockerfile=<Dockerfile>]
14+
sets up a container image for execution and executes the bundled application
15+
from inside that container. Requires podman or rootless docker to be installed.
16+
If available, 'podman' is preferred and rootless 'docker' is the fallback. Specifying
17+
one or the other as '=<container-tool>' forces the use of a specific tool.
18+
'dockerfile=<Dockerfile>': Use a user-provided 'Dockerfile' instead of the Dockerfile
19+
bundled with the application
20+
21+
--verbose enable verbose output
22+
--help print this help message

0 commit comments

Comments
 (0)