Skip to content
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

Add tools attr with exec transition for cargo_build_script #885

Merged
merged 9 commits into from
Aug 25, 2021
17 changes: 13 additions & 4 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ def _build_script_impl(ctx):
ctx,
ctx.attr.build_script_env,
getattr(ctx.attr, "data", []) +
getattr(ctx.attr, "compile_data", []),
getattr(ctx.attr, "compile_data", []) +
getattr(ctx.attr, "tools", []),
))

tools = depset(
direct = [
script,
ctx.executable._cargo_build_script_runner,
toolchain.rustc,
] + ctx.files.data + ([toolchain.target_json] if toolchain.target_json else []),
] + ctx.files.data + ctx.files.tools + ([toolchain.target_json] if toolchain.target_json else []),
transitive = toolchain_tools,
)

Expand Down Expand Up @@ -195,7 +196,7 @@ _build_script_run = rule(
doc = "The list of rust features that the build script should consider activated.",
),
"data": attr.label_list(
doc = "Data or tools required by the build script.",
doc = "Data required by the build script.",
allow_files = True,
),
"deps": attr.label_list(
Expand All @@ -214,6 +215,11 @@ _build_script_run = rule(
mandatory = True,
cfg = "exec",
),
"tools": attr.label_list(
doc = "Tools required by the build script.",
allow_files = True,
cfg = "exec",
),
"version": attr.string(
doc = "The semantic version (semver) of the crate",
),
Expand Down Expand Up @@ -242,6 +248,7 @@ def cargo_build_script(
deps = [],
build_script_env = {},
data = [],
tools = [],
links = None,
rustc_env = {},
**kwargs):
Expand Down Expand Up @@ -309,7 +316,8 @@ def cargo_build_script(
version (str, optional): The semantic version (semver) of the crate.
deps (list, optional): The dependencies of the crate.
build_script_env (dict, optional): Environment variables for build scripts.
data (list, optional): Files or tools needed by the build script.
data (list, optional): Files needed by the build script.
tools (list, optional): Tools (executables) needed by the build script.
links (str, optional): Name of the native library this crate links against.
rustc_env (dict, optional): Environment variables to set in rustc when compiling the build script.
**kwargs: Forwards to the underlying `rust_binary` rule.
Expand Down Expand Up @@ -341,6 +349,7 @@ def cargo_build_script(
links = links,
deps = deps,
data = data,
tools = tools,
)

def _name_to_pkg_name(name):
Expand Down
7 changes: 4 additions & 3 deletions docs/cargo_build_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
## cargo_build_script

<pre>
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-links">links</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>,
<a href="#cargo_build_script-kwargs">kwargs</a>)
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-tools">tools</a>, <a href="#cargo_build_script-links">links</a>,
<a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
</pre>

Compile and execute a rust build script to generate build attributes
Expand Down Expand Up @@ -80,7 +80,8 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | <code>None</code> |
| <a id="cargo_build_script-deps"></a>deps | The dependencies of the crate. | <code>[]</code> |
| <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | <code>{}</code> |
| <a id="cargo_build_script-data"></a>data | Files or tools needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-data"></a>data | Files needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-tools"></a>tools | Tools (executables) needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-links"></a>links | Name of the native library this crate links against. | <code>None</code> |
| <a id="cargo_build_script-rustc_env"></a>rustc_env | Environment variables to set in rustc when compiling the build script. | <code>{}</code> |
| <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying <code>rust_binary</code> rule. | none |
Expand Down
7 changes: 4 additions & 3 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@ A test rule for performing `rustfmt --check` on a set of targets
## cargo_build_script

<pre>
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-links">links</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>,
<a href="#cargo_build_script-kwargs">kwargs</a>)
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-tools">tools</a>, <a href="#cargo_build_script-links">links</a>,
<a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
</pre>

Compile and execute a rust build script to generate build attributes
Expand Down Expand Up @@ -1438,7 +1438,8 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | <code>None</code> |
| <a id="cargo_build_script-deps"></a>deps | The dependencies of the crate. | <code>[]</code> |
| <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | <code>{}</code> |
| <a id="cargo_build_script-data"></a>data | Files or tools needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-data"></a>data | Files needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-tools"></a>tools | Tools (executables) needed by the build script. | <code>[]</code> |
| <a id="cargo_build_script-links"></a>links | Name of the native library this crate links against. | <code>None</code> |
| <a id="cargo_build_script-rustc_env"></a>rustc_env | Environment variables to set in rustc when compiling the build script. | <code>{}</code> |
| <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying <code>rust_binary</code> rule. | none |
Expand Down