Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 14f05eb

Browse files
Cleaner format for platform-specific Graal flags
1 parent ffb596b commit 14f05eb

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

build-scripts/graal.js

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ process.on('unhandledRejection', error => {
3434
process.exit(1);
3535
});
3636

37-
const NATIVE_IMAGE_BUILD_ARGS = [
37+
const flagsByPlatformAndArch = new Map([
38+
// Statically link libraries when supported. Allows usage on systems
39+
// which are missing or have incompatible versions of GLIBC.
40+
// Only linux x86 architectures can fully statically link
41+
// See https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/
42+
['linux-x86', ['--static', '--libc=musl']],
43+
['linux-x64', ['--static', '--libc=musl']],
44+
['linux-arm64', ['-H:+StaticExecutableWithDynamicLibC']],
45+
]);
46+
47+
const platformFlags = flagsByPlatformAndArch.get(`${process.platform}-${process.arch}`) || [];
48+
const NATIVE_IMAGE_BUILD_ARGS = platformFlags.concat([
3849
'-H:+UnlockExperimentalVMOptions',
3950
'-H:IncludeResourceBundles=org.kohsuke.args4j.Messages',
4051
'-H:IncludeResourceBundles=org.kohsuke.args4j.spi.Messages',
@@ -54,31 +65,11 @@ const NATIVE_IMAGE_BUILD_ARGS = [
5465
'--color=always',
5566
'-jar',
5667
path.resolve(process.cwd(), 'compiler.jar')
57-
];
68+
]);
5869

59-
const spawnOpts = {};
60-
switch (process.platform) {
61-
case 'win32':
62-
spawnOpts.shell = true;
63-
break;
64-
case 'linux':
65-
// On linux, statically link all libraries. Allows usage on systems
66-
// which are missing or have incompatible versions of GLIBC.
67-
// Only linux x86 architectures can fully statically link
68-
// See https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/
69-
if (process.arch !== 'arm64') {
70-
NATIVE_IMAGE_BUILD_ARGS.unshift('--static', '--libc=musl');
71-
} else {
72-
// Newer Graal versions use the standard flag --static-nolibc
73-
NATIVE_IMAGE_BUILD_ARGS.unshift('-H:+StaticExecutableWithDynamicLibC');
74-
}
75-
break;
76-
case 'darwin': {
77-
// Newer Graal versions use the standard flag --static-nolibc
78-
NATIVE_IMAGE_BUILD_ARGS.unshift('-H:+StaticExecutableWithDynamicLibC');
79-
break;
80-
}
81-
}
70+
const spawnOpts = {
71+
...(process.platform === 'win32' ? { shell: true } : {}),
72+
};
8273

8374
runCommand(`native-image${process.platform === 'win32' ? '.cmd' : ''}`, NATIVE_IMAGE_BUILD_ARGS, spawnOpts)
8475
.catch(e => {

0 commit comments

Comments
 (0)