fix(native_image): clean up construction of inputs#70
Merged
sgammon merged 2 commits intosgammon:mainfrom Sep 1, 2023
Merged
Conversation
d41ec9f to
94796f0
Compare
Collaborator
Author
|
Stacked on #71 |
This was referenced Aug 31, 2023
`depset` structures should be kept as flat as possible. C++ toolchain files are also already `depset`s and thus shouldn't be passed into `tools`. Signed-off-by: Sam Gammon <sam@elide.ventures>
Owner
|
#71 merged, rebased (and signed-off and signed) will examine expected build failure and hopefully solve so i can hand off to you |
sgammon
added a commit
that referenced
this pull request
Sep 1, 2023
- fix: explicitly check against modern rule status before resolving toolchain, unconditionally take it if running modern applies on top of #70 Signed-off-by: Sam Gammon <sam@elide.ventures>
sgammon
added a commit
that referenced
this pull request
Sep 1, 2023
- 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>
- 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 sgammon#70 Signed-off-by: Sam Gammon <sam@elide.ventures>
Owner
|
@fmeum adjusted to avoid breakages with legacy rules (from a0c767a): diff --git a/internal/native_image/rules.bzl b/internal/native_image/rules.bzl
index c667cf1..03fa527 100644
--- a/internal/native_image/rules.bzl
+++ b/internal/native_image/rules.bzl
@@ -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,
@@ -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],
it was direct_inputs.append(graal_inputs)that was causing the classic rules to fail with it seems to fix it to append only the file, like direct_inputs.append(graal) # graal is `graal_inputs[0]`and it shouldn't affect your use in bazelbuild/bazel#19361, since that code path is only used by the legacy rules. |
sgammon
approved these changes
Sep 1, 2023
|
Kudos, SonarCloud Quality Gate passed! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








depsetstructures should be kept as flat as possible. C++ toolchain files are also alreadydepsets and thus shouldn't be passed intotools.