Skip to content

Commit

Permalink
feat: makevar expansion for extra_args
Browse files Browse the repository at this point in the history
Adds Makefile variable expansion support to the `extra_args` flags
passed to `native-image`.

Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Jan 13, 2024
1 parent 223e0b8 commit ed40131
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/native_image/builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ def assemble_native_build_options(

# append extra arguments last
for arg in ctx.attr.extra_args:
args.add(arg)
args.add(ctx.expand_location(arg, ctx.attr.data))
16 changes: 14 additions & 2 deletions internal/native_image/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def _build_action_message(ctx):
}
return (_mode_label[ctx.attr.optimization_mode or "default"])

def _prepare_execution_env(ctx, base_env = {}):
effective = {}
effective.update(base_env)
effective.update({
"GRAALVM_BAZEL": "true",
})
return effective

def _graal_binary_implementation(ctx):
graal_attr = ctx.attr.native_image_tool
extra_tool_deps = []
Expand Down Expand Up @@ -115,7 +123,7 @@ def _graal_binary_implementation(ctx):
elif (not is_windows and not is_macos) and ctx.attr.shared_library:
bin_postfix = _BIN_POSTFIX_SO

args = ctx.actions.args().use_param_file("@%s", use_always=False)
args = ctx.actions.args().use_param_file("@%s", use_always=True)
all_outputs = _prepare_native_image_rule_context(
ctx,
args,
Expand All @@ -126,6 +134,10 @@ def _graal_binary_implementation(ctx):
bin_postfix = bin_postfix,
)
binary = all_outputs[0]
execution_env = _prepare_execution_env(
ctx,
native_toolchain.env,
)

# assemble final inputs
inputs = depset(
Expand All @@ -137,7 +149,7 @@ def _graal_binary_implementation(ctx):
"executable": graal,
"inputs": inputs,
"mnemonic": "NativeImage",
"env": native_toolchain.env,
"env": execution_env,
"execution_requirements": {k: "" for k in native_toolchain.execution_requirements},
"progress_message": "Native Image __target__ (__mode__) %{label}"
.replace("__mode__", _build_action_message(ctx))
Expand Down

0 comments on commit ed40131

Please sign in to comment.