Rules for building native binaries using the GraalVM native-image tool on Bazel 5 and older.
graal_binary
load("@rules_graalvm//graal:graal.bzl", "graal_binary")
graal_binary(name, deps, main_class, executable_name, include_resources, reflection_configuration,
jni_configuration, serialization_configuration, initialize_at_build_time,
initialize_at_run_time, native_features, debug, optimization_mode, shared_library,
static_zlib, c_compiler_option, data, extra_args, allow_fallback, check_toolchains,
native_image_tool, **kwargs)
Alias for the renamed native_image rule. Identical.
PARAMETERS
| Name |
Description |
Default Value |
| name |
Name of the target; required. |
none |
| deps |
Dependency java_library targets to assemble the classpath from. Mandatory. |
none |
| main_class |
Entrypoint main class to build from; mandatory unless building a shared library. |
None |
| executable_name |
Set the name of the output binary; defaults to %target%-bin, or %target%-bin.exe on Windows. The special string %target%, if present, is replaced with name. |
select({"@bazel_tools//src/conditions:windows": "%target%-bin.exe", "//conditions:default": "%target%-bin"}) |
| include_resources |
Glob to pass to IncludeResources. No default; optional. |
None |
| reflection_configuration |
Reflection configuration file. No default; optional. |
None |
| jni_configuration |
JNI configuration file. No default; optional. |
None |
| serialization_configuration |
Serialization configuration file. No default; optional. |
None |
| initialize_at_build_time |
Classes or patterns to pass to --initialize-at-build-time. No default; optional. |
[] |
| initialize_at_run_time |
Classes or patterns to pass to --initialize-at-run-time. No default; optional. |
[] |
| native_features |
GraalVM Feature classes to include and apply. No default; optional. |
[] |
| debug |
Whether to include debug symbols; by default, this flag’s state is managed by Bazel. Passing --compilation_mode=dbg is sufficient to flip this to True, or it can be overridden via this parameter. |
select({"@rules_graalvm//internal/conditions/compiler:debug": True, "//conditions:default": False}) |
| optimization_mode |
Behaves the same as debug; normally, this flag’s state is managed by Bazel. Passing --compilation_mode=fastbuild\|opt\|dbg is sufficient to set this flag, or it can be overridden via this parameter. |
select({"@rules_graalvm//internal/conditions/compiler:fastbuild": "b", "@rules_graalvm//internal/conditions/compiler:optimized": "2", "//conditions:default": ""}) |
| shared_library |
Build a shared library binary instead of an executable. |
None |
| static_zlib |
A cc_library or cc_import target that provides zlib as a static library. On Linux, this is used when Graal statically links zlib into the binary, e.g. with -H:+StaticExecutableWithDynamicLibC. |
None |
| c_compiler_option |
Extra C compiler options to pass through native-image. No default; optional. |
[] |
| data |
Data files to make available during the compilation. No default; optional. |
[] |
| extra_args |
Extra native-image args to pass. Last wins. No default; optional. |
[] |
| allow_fallback |
Whether to allow fall-back to a partial native image; defaults to False. |
False |
| check_toolchains |
Whether to perform toolchain checks in native-image; defaults to True on Windows, False otherwise. |
select({"@bazel_tools//src/conditions:windows": True, "//conditions:default": False}) |
| native_image_tool |
Specific native-image executable target to use. |
Label("@graalvm//:native-image") |
| kwargs |
Extra keyword arguments are passed to the underlying native_image rule. |
none |
native_image
load("@rules_graalvm//graal:graal.bzl", "native_image")
native_image(name, deps, main_class, executable_name, include_resources, reflection_configuration,
jni_configuration, serialization_configuration, initialize_at_build_time,
initialize_at_run_time, native_features, debug, optimization_mode, shared_library,
static_zlib, c_compiler_option, data, extra_args, allow_fallback, check_toolchains,
native_image_tool, **kwargs)
Generates and compiles a GraalVM native image from a Java library target.
PARAMETERS
| Name |
Description |
Default Value |
| name |
Name of the target; required. |
none |
| deps |
Dependency java_library targets to assemble the classpath from. Mandatory. |
none |
| main_class |
Entrypoint main class to build from; mandatory unless building a shared library. |
None |
| executable_name |
Set the name of the output binary; defaults to %target%-bin, or %target%-bin.exe on Windows. The special string %target%, if present, is replaced with name. |
select({"@bazel_tools//src/conditions:windows": "%target%-bin.exe", "//conditions:default": "%target%-bin"}) |
| include_resources |
Glob to pass to IncludeResources. No default; optional. |
None |
| reflection_configuration |
Reflection configuration file. No default; optional. |
None |
| jni_configuration |
JNI configuration file. No default; optional. |
None |
| serialization_configuration |
Serialization configuration file. No default; optional. |
None |
| initialize_at_build_time |
Classes or patterns to pass to --initialize-at-build-time. No default; optional. |
[] |
| initialize_at_run_time |
Classes or patterns to pass to --initialize-at-run-time. No default; optional. |
[] |
| native_features |
GraalVM Feature classes to include and apply. No default; optional. |
[] |
| debug |
Whether to include debug symbols; by default, this flag’s state is managed by Bazel. Passing --compilation_mode=dbg is sufficient to flip this to True, or it can be overridden via this parameter. |
select({"@rules_graalvm//internal/conditions/compiler:debug": True, "//conditions:default": False}) |
| optimization_mode |
Behaves the same as debug; normally, this flag’s state is managed by Bazel. Passing --compilation_mode=fastbuild\|opt\|dbg is sufficient to set this flag, or it can be overridden via this parameter. |
select({"@rules_graalvm//internal/conditions/compiler:fastbuild": "b", "@rules_graalvm//internal/conditions/compiler:optimized": "2", "//conditions:default": ""}) |
| shared_library |
Build a shared library binary instead of an executable. |
None |
| static_zlib |
A cc_library or cc_import target that provides zlib as a static library. On Linux, this is used when Graal statically links zlib into the binary, e.g. with -H:+StaticExecutableWithDynamicLibC. |
None |
| c_compiler_option |
Extra C compiler options to pass through native-image. No default; optional. |
[] |
| data |
Data files to make available during the compilation. No default; optional. |
[] |
| extra_args |
Extra native-image args to pass. Last wins. No default; optional. |
[] |
| allow_fallback |
Whether to allow fall-back to a partial native image; defaults to False. |
False |
| check_toolchains |
Whether to perform toolchain checks in native-image; defaults to True on Windows, False otherwise. |
select({"@bazel_tools//src/conditions:windows": True, "//conditions:default": False}) |
| native_image_tool |
Specific native-image executable target to use. |
Label("@graalvm//:native-image") |
| kwargs |
Extra keyword arguments are passed to the underlying native_image rule. |
none |