-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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, | ||
executable = True, | ||
cfg = "exec", | ||
), | ||
}, | ||
) | ||
|
||
binary_runtime_toolchain = rule( | ||
implementation = _toolchain_impl, | ||
attrs = { | ||
"bin": attr.label( | ||
mandatory = 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], | ||
) |