You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -12,16 +12,14 @@ GraalVM Native Image by default builds dynamically linked binaries: at build tim
12
12
13
13
However, you can create a statically linked or mostly-statically linked native executable, depending on your needs.
14
14
15
-
**A static native executable** is a statically linked binary that can be used without any additional library dependencies.
15
+
**A static native executable** is a statically linked binary that you can use without any additional library dependencies.
16
16
A static native executable is easy to distribute and deploy on a slim or distroless container (a scratch container).
17
17
You can create a static native executable by statically linking it against [musl-libc](https://musl.libc.org/), a lightweight, fast and simple `libc` implementation.
18
18
19
-
**A mostly-static native executable** is a binary that links everything (`zlib`, JDK-shared static libraries) except the standard C library, `libc`. This is an alternative option to statically linking everything. Also, depending on the user's code, it may link `libstdc+` and `libgcc`.
19
+
**A mostly-static native executable** is a binary that links all the shared libraries on which the native executable relies (`zlib`, JDK-shared static libraries) except the standard C library, `libc`. This is an alternative option to statically linking everything. Also, depending on the user's code, it may link `libstdc+` and `libgcc`.
20
20
This approach is useful for deployment on a distroless container image.
21
21
22
-
> Note: This currently only works when linked against `libc`.
23
-
24
-
This guide shows how you can take advantage of Native Image linking options including fully dynamic, fully static, and mostly static (except `libc`) to generate an executable ideal for your deployment scenario.
22
+
This guide shows how you can take advantage of Native Image linking options including fully dynamic, fully static, and mostly-static (except `libc`) to generate an executable ideal for your deployment scenario.
25
23
26
24
## Prerequisites and Preparation
27
25
@@ -33,7 +31,7 @@ This guide shows how you can take advantage of Native Image linking options incl
33
31
The easiest way to install GraalVM is with [SDKMAN!](https://sdkman.io/jdks#graal).
34
32
For other installation options, visit the [Downloads section](https://www.graalvm.org/downloads/).
35
33
36
-
To be able to create static native applications with Native Image, a `musl` toolchain with the `zlib` library are required on the system.
34
+
To create statically linked applications with Native Image, you require a `musl` toolchain with the `zlib` library.
37
35
For the best compatibility, use [musl-1.2.4](https://musl.libc.org/releases/musl-1.2.4.tar.gz) or later.
38
36
We recommend building `musl` from [source](https://musl.libc.org/) as shown below:
39
37
@@ -102,7 +100,13 @@ With the requirements set up, create the demo.
102
100
native-image --static--libc=musl EnvMap
103
101
```
104
102
This produces a native executable with statically linked system libraries.
105
-
You can pass other arguments before a classor JAR file. Run it with `./envmap`.
103
+
Run it with `./envmap`.
104
+
105
+
You can confirm the application is fully statically linked using the `ldd` command:
106
+
```shell
107
+
ldd EnvMap
108
+
```
109
+
The output should be "not a dynamic executable".
106
110
107
111
## Build a Mostly-StaticNativeExecutable
108
112
@@ -128,8 +132,8 @@ One way to check what dynamic libraries your application depends on is to run `l
128
132
129
133
#### What is the recommended base container image for deploying a static or mostly-static native executable?
130
134
131
-
A fully staticnative executable gives you the most flexibility to choose a base container image—it can run on anything including a `FROM scratch` image.
132
-
A mostly-staticnative executable requires a container image that provides `libc`, but has no additional requirements.
135
+
A fully static native executable gives you the most flexibility to choose a base container image—it can even run on a `scratch` image.
136
+
A mostly-static native executable requires a container image that provides `libc`, specifically `glibc`, but has no additional requirements.
133
137
In both cases, choosing the base container image generally depends on your native executable's specific requirements.
0 commit comments