-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat: Implement binary_toolchain #875
Open
BoleynSu
wants to merge
2
commits into
bazel-contrib:main
Choose a base branch
from
BoleynSu:binary_toolchain
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−65
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
BinaryInfo = provider( | ||
doc = "Provide info for binary", | ||
fields = { | ||
"bin": "Target for the binary", | ||
}, | ||
) | ||
|
||
def _toolchain_impl(ctx): | ||
binary_info = BinaryInfo( | ||
bin = ctx.attr.bin, | ||
) | ||
|
||
toolchain_info = platform_common.ToolchainInfo( | ||
binary_info = binary_info, | ||
) | ||
|
||
return [toolchain_info] | ||
|
||
binary_toolchain = rule( | ||
implementation = _toolchain_impl, | ||
attrs = { | ||
"bin": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, | ||
executable = True, | ||
cfg = "exec", | ||
), | ||
}, | ||
) | ||
|
||
binary_runtime_toolchain = rule( | ||
implementation = _toolchain_impl, | ||
attrs = { | ||
"bin": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, | ||
executable = True, | ||
cfg = "target", | ||
), | ||
}, | ||
) | ||
|
||
def _resolved_binary_rule_impl(ctx, toolchain_type, template_variable): | ||
bin = ctx.toolchains[toolchain_type].binary_info.bin[DefaultInfo] | ||
|
||
out = ctx.actions.declare_file(ctx.attr.name + ".exe") | ||
ctx.actions.symlink( | ||
target_file = bin.files_to_run.executable, | ||
output = out, | ||
is_executable = True, | ||
) | ||
|
||
return [ | ||
DefaultInfo( | ||
executable = out, | ||
files = bin.files, | ||
runfiles = bin.default_runfiles, | ||
), | ||
platform_common.TemplateVariableInfo({ | ||
template_variable: out.path, | ||
} if template_variable != None else {}), | ||
] | ||
|
||
def resolved_binary_rule(*, toolchain_type, template_variable = None): | ||
return rule( | ||
implementation = lambda ctx: _resolved_binary_rule_impl(ctx, toolchain_type, template_variable), | ||
executable = True, | ||
toolchains = [toolchain_type], | ||
) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems very similar to bazel-contrib/rules_oci#590 by @EdSchouten
I wonder if bazel-lib could provide the abstraction that's needed for this case globally. We should bike-shed on this name because "BinaryInfo" can also apply to a binary run as an action on the exec platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree we should have the abstraction shared. binary_toolchain is my answer. While there are still some decision we want to make which are not clear to me yet.
I think ideally we only limit the scope of the solution to 2) in bazelbuild/bazel#19645 (comment)
Then we only need to have one toolchain_type for the binary. Using jq as an example.
We will need