Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource configuration file flag #308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,560 changes: 1,454 additions & 1,106 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ http_archive(
name = "com_grail_bazel_toolchain",
canonical_id = LLVM_TOOLCHAIN_TAG,
sha256 = LLVM_TOOLCHAIN_SHA,
strip_prefix = "bazel-toolchain-{tag}".format(tag = LLVM_TOOLCHAIN_TAG),
url = "https://github.com/grailbio/bazel-toolchain/archive/refs/tags/{tag}.tar.gz".format(tag = LLVM_TOOLCHAIN_TAG),
strip_prefix = "toolchain_llvm-{tag}".format(tag = LLVM_TOOLCHAIN_TAG),
url = "https://github.com/bazel-contrib/toolchains_llvm/archive/refs/tags/{tag}.tar.gz".format(tag = LLVM_TOOLCHAIN_TAG),
)

http_archive(
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ http_archive(
name = "com_grail_bazel_toolchain",
canonical_id = LLVM_TOOLCHAIN_TAG,
sha256 = LLVM_TOOLCHAIN_SHA,
strip_prefix = "bazel-toolchain-{tag}".format(tag = LLVM_TOOLCHAIN_TAG),
url = "https://github.com/grailbio/bazel-toolchain/archive/refs/tags/{tag}.tar.gz".format(tag = LLVM_TOOLCHAIN_TAG),
strip_prefix = "toolchains_llvm-{tag}".format(tag = LLVM_TOOLCHAIN_TAG),
url = "https://github.com/bazel-contrib/toolchains_llvm/archive/refs/tags/{tag}.tar.gz".format(tag = LLVM_TOOLCHAIN_TAG),
)

http_archive(
Expand Down
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
)
2 changes: 1 addition & 1 deletion internal/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PROTOBUF_SHA = "8b28fdd45bab62d15db232ec404248901842e5340299a57765e48abe8a80d930

LLVM_TOOLCHAIN_TAG = "0.8.2"

LLVM_TOOLCHAIN_SHA = "0fc3a2b0c9c929920f4bed8f2b446a8274cad41f5ee823fd3faa0d7641f20db0"
LLVM_TOOLCHAIN_SHA = "3e251524b3e8f3b9ec93848e5267c168424f43b7b554efc983a5291c33d78cde"

HERMETIC_CC_TOOLCHAIN_VERSION = "v2.0.0"

Expand Down
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
Loading