Created
February 20, 2024 20:45
-
-
Save jazzdan/c07084f915920dbc09f61cebc23bde95 to your computer and use it in GitHub Desktop.
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
def _executable_package_impl(ctx): | |
srcs = {file.short_path: file for file in ctx.attrs.support_files} | |
srcs.update({exe.short_path: exe for name, exe in ctx.attrs.executables.items()}) | |
# First make a directory containing all of the executables and support files with symlinks into the source tree, so that | |
# we can refer to them and make them available to other rules. | |
out_dir = ctx.actions.symlinked_dir("out", srcs) | |
# Define an "artifact" for each one (basically a Starlark artifact object for each of the symlinks we just created), so | |
# that we can set up the proper action graph dependencies. | |
projected_support_files = [out_dir.project(src.short_path) for src in ctx.attrs.support_files] | |
projected_executables = { | |
name: out_dir.project(exe.short_path) for name, exe in ctx.attrs.executables.items() | |
} | |
# The provider we return contains the output directory as the default output, but it contains a sub-target for each executable. | |
# Each subtarget provides a RunInfo referring to the executable, and the run-info has an action graph dependency on every | |
# support file | |
return [ | |
DefaultInfo( | |
default_output = out_dir, | |
sub_targets={ | |
name: [ | |
DefaultInfo(default_output = executable), | |
RunInfo(args = cmd_args(executable).hidden(projected_support_files)) | |
] for name, executable in projected_executables.items() | |
} | |
), | |
] | |
executable_package = rule( | |
impl = _executable_package_impl, | |
attrs = { | |
"support_files": attrs.list(attrs.source()), | |
"executables": attrs.dict(attrs.string(), attrs.source()) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment