Skip to content

Commit

Permalink
feat: Add resource_configuration to native_image
Browse files Browse the repository at this point in the history
Signed-off-by: loganasherjones <loganasherjones@gmail.com>
  • Loading branch information
loganasherjones authored and sgammon committed Feb 19, 2024
1 parent 00ea284 commit e201dc6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions graalvm/nativeimage/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def native_image(
check_toolchains = _DEFAULT_CHECK_TOOLCHAINS_CONDITION,
native_image_tool = None, # uses toolchains by default
native_image_settings = [_DEFAULT_NATIVE_IMAGE_SETTINGS],
resource_configuration = None,
profiles = [],
**kwargs):
"""Generates and compiles a GraalVM native image from a Java library target.
Expand Down Expand Up @@ -115,6 +116,7 @@ def native_image(
native_image_tool: Specific `native-image` executable target to use.
native_image_settings: Suite(s) of Native Image build settings to use.
profiles: Profiles to use for profile-guided optimization (PGO) and obtained from a native image compiled with `--pgo-instrument`.
resource_configuration: Resource configuration file. No default; optional.
**kwargs: Extra keyword arguments are passed to the underlying `native_image` rule.
"""

Expand All @@ -141,5 +143,6 @@ def native_image(
native_image_tool = native_image_tool,
native_image_settings = native_image_settings,
profiles = profiles,
resource_configuration = resource_configuration,
**kwargs
)
19 changes: 17 additions & 2 deletions internal/native_image/builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def _configure_optimization_mode(ctx, args):
format = "-O%s",
)

def _configure_resources(ctx, args, direct_inputs):
"""Configure resource settings for a Native Image build.
Args:
ctx: Context of the Native Image rule implementation.
args: Args builder for the Native Image build.
direct_inputs: Direct Native Image build action inputs.
"""
if ctx.attr.include_resources != None:
args.add(ctx.attr.include_resources, format = "-H:IncludeResources=%s")

if ctx.attr.resource_configuration != None:
args.add(ctx.file.resource_configuration, format = "-H:ResourceConfigurationFiles=%s")
direct_inputs.append(ctx.file.resource_configuration)

def _configure_reflection(ctx, args, direct_inputs):
"""Configure reflection settings for a Native Image build.
Expand Down Expand Up @@ -203,8 +219,7 @@ def assemble_native_build_options(
_configure_reflection(ctx, args, direct_inputs)

# configure resources
if ctx.attr.include_resources != None:
args.add(ctx.attr.include_resources, format = "-H:IncludeResources=%s")
_configure_resources(ctx, args, direct_inputs)

# if a static build is being performed against hermetic zlib, configure it
if ctx.attr.static_zlib != None:
Expand Down
4 changes: 4 additions & 0 deletions internal/native_image/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ _NATIVE_IMAGE_ATTRS = {
allow_files = True,
mandatory = False,
),
"resource_configuration": attr.label(
mandatory = False,
allow_single_file = True,
),
"_cc_toolchain": attr.label(
default = Label(_BAZEL_CURRENT_CPP_TOOLCHAIN),
),
Expand Down

0 comments on commit e201dc6

Please sign in to comment.