Skip to content

Commit

Permalink
fix: modern rule check
Browse files Browse the repository at this point in the history
- fix: explicitly check against modern rule status before resolving
  toolchain, unconditionally take it if running modern
- fix: direct deps for `native_image_tool` attr
- fix: preserve legacy rule behavior

applies on top of #70

Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Sep 1, 2023
1 parent 459f972 commit f6d03d3
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions internal/native_image/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,39 @@ def _graal_binary_implementation(ctx):
direct_inputs = []
transitive_inputs = [classpath_depset]

if graal_attr == None:
# if we aren't handed a specific `native-image` tool binary, or we are running
# under the modern `native_image` rule, then attempt to resolve via toolchains...
if graal_attr == None and not (ctx.attr._legacy_rule):
# resolve via toolchains
info = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm
graal_attr = info.native_image_bin

# but fall back to explicitly-provided tool, which should override, with the
# remainder of the resolved toolchain present
resolved_graal = graal_attr or info.native_image_bin
gvm_toolchain = info
extra_tool_deps.append(info.gvm_files)

graal_inputs, _ = ctx.resolve_tools(tools = [
graal_attr,
resolved_graal,
] + extra_tool_deps)

graal = graal_inputs.to_list()[0]

# if we're using an explicit tool, add it to the direct inputs
if graal_attr:
direct_inputs.append(graal_inputs)

# add toolchain files to transitive inputs
transitive_inputs.append(gvm_toolchain.gvm_files[DefaultInfo].files)
else:
# otherwise, use the legacy code path
elif graal_attr != None:
# otherwise, use the legacy code path. the `graal` value is used in the run
# `executable` so it isn't listed in deps for earlier Bazel versions.
graal_inputs, _, _ = ctx.resolve_command(tools = [
graal_attr,
])
graal = graal_inputs[0]
direct_inputs.append(graal_inputs)

if graal_attr == None:
direct_inputs.append(graal)
else:
# still failed to resolve: cannot resolve via either toolchains or attributes.
fail("""
No `native-image` tool found. Please either define a `native_image_tool` in your target,
Expand Down Expand Up @@ -263,6 +274,7 @@ def _graal_binary_implementation(ctx):
args.add("-H:+JNI")

inputs = depset(direct_inputs, transitive = transitive_inputs)

run_params = {
"outputs": [binary],
"arguments": [args],
Expand Down

0 comments on commit f6d03d3

Please sign in to comment.