Skip to content

Commit

Permalink
Avoid using the deprecated ctx.resolve_tools in the native_image rule.
Browse files Browse the repository at this point in the history
See bazelbuild/bazel#22249 for context.

Signed-off-by: Tiago Quelhas <tjgq@google.com>
  • Loading branch information
tjgq committed Sep 16, 2024
1 parent 9865845 commit 0fc3313
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions internal/native_image/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,28 @@ def _build_action_message(ctx):
return (_mode_label[ctx.attr.optimization_mode or "default"])

def _graal_binary_implementation(ctx):
graal_attr = ctx.attr.native_image_tool
extra_tool_deps = []
gvm_toolchain = None
graal_attr = ctx.executable.native_image_tool

classpath_depset = depset(transitive = [
dep[JavaInfo].transitive_runtime_jars
for dep in ctx.attr.deps
])

graal = None
direct_inputs = []
transitive_inputs = [classpath_depset]

# resolve via toolchains
info = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm
gvm_toolchain = ctx.toolchains[_GVM_TOOLCHAIN_TYPE].graalvm

# 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 = [
resolved_graal,
] + extra_tool_deps)

graal = graal_inputs.to_list()[0]
graal = graal_attr or gvm_toolchain.native_image_bin.files.to_list()[0]

# add toolchain files to transitive inputs
transitive_inputs.append(gvm_toolchain.gvm_files[DefaultInfo].files)

# if we're using an explicit tool, add it to the direct inputs
if graal:
direct_inputs.append(graal)
else:
# still failed to resolve: cannot resolve via either toolchains or attributes.
if not graal:
# cannot resolve via either toolchains or attributes.
fail("""
No `native-image` tool found. Please either define a `native_image_tool` in your target,
or install a GraalVM `native-image` toolchain.
Expand Down

0 comments on commit 0fc3313

Please sign in to comment.