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 target_compatible_with from kwargs to build_script_kwargs #2133

Merged
merged 9 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions cargo/private/cargo_build_script_wrapper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ load("//rust:defs.bzl", "rust_binary")

def cargo_build_script(
name,
edition = None,
crate_name = None,
crate_root = None,
srcs = [],
crate_features = [],
version = None,
deps = [],
link_deps = [],
proc_macro_deps = [],
build_script_env = {},
data = [],
tools = [],
Expand All @@ -23,6 +28,7 @@ def cargo_build_script(
rustc_flags = [],
visibility = None,
tags = None,
aliases = None,
**kwargs):
"""Compile and execute a rust build script to generate build attributes

Expand Down Expand Up @@ -85,11 +91,16 @@ def cargo_build_script(
Args:
name (str): The name for the underlying rule. This should be the name of the package
being compiled, optionally with a suffix of `_build_script`.
edition (str): The rust edition to use for the internal binary crate.
crate_name (str): Crate name to use for build script.
crate_root (label): The file that will be passed to rustc to be used for building this crate.
srcs (list of label): Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made.
crate_features (list, optional): A list of features to enable for the build script.
version (str, optional): The semantic version (semver) of the crate.
deps (list, optional): The build-dependencies of the crate.
link_deps (list, optional): The subset of the (normal) dependencies of the crate that have the
links attribute and therefore provide environment variables to this build script.
proc_macro_deps (list of label, optional): List of rust_proc_macro targets used to build the script.
build_script_env (dict, optional): Environment variables for build scripts.
data (list, optional): Files needed by the build script.
tools (list, optional): Tools (executables) needed by the build script.
Expand All @@ -103,6 +114,8 @@ def cargo_build_script(
rustc_flags (list, optional): List of compiler flags passed to `rustc`.
visibility (list of label, optional): Visibility to apply to the generated build script output.
tags: (list of str, optional): Tags to apply to the generated build script output.
aliases (dict, optional): Remap crates to a new name or moniker for linkage to this target. \
These are other `rust_library` targets and will be presented as the new name given.
**kwargs: Forwards to the underlying `rust_binary` rule. An exception is the `compatible_with`
attribute, which shouldn't be forwarded to the `rust_binary`, as the `rust_binary` is only
built and used in `exec` mode. We propagate the `compatible_with` attribute to the `_build_scirpt_run`
Expand All @@ -122,28 +135,21 @@ def cargo_build_script(
binary_tags = [tag for tag in tags or []]
if "manual" not in binary_tags:
binary_tags.append("manual")
build_script_kwargs = {}
binary_kwargs = kwargs
if "compatible_with" in kwargs:
build_script_kwargs["compatible_with"] = kwargs["compatible_with"]
binary_kwargs.pop("compatible_with")

if "toolchains" in kwargs:
build_script_kwargs["toolchains"] = kwargs["toolchains"]

if "features" in kwargs:
build_script_kwargs["features"] = kwargs["features"]

rust_binary(
name = name + "_",
crate_name = crate_name,
srcs = srcs,
crate_root = crate_root,
crate_features = crate_features,
version = version,
deps = deps,
proc_macro_deps = proc_macro_deps,
data = data,
rustc_env = rustc_env,
rustc_flags = rustc_flags,
edition = edition,
tags = binary_tags,
**binary_kwargs
aliases = aliases,
)
_build_script_run(
name = name,
Expand All @@ -160,5 +166,5 @@ def cargo_build_script(
rustc_flags = rustc_flags,
visibility = visibility,
tags = tags,
**build_script_kwargs
**kwargs
)
11 changes: 9 additions & 2 deletions docs/cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ A rule for generating variables for dependent `cargo_build_script`s without a bu
## 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-link_deps">link_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-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</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-edition">edition</a>, <a href="#cargo_build_script-crate_name">crate_name</a>, <a href="#cargo_build_script-crate_root">crate_root</a>, <a href="#cargo_build_script-srcs">srcs</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-link_deps">link_deps</a>, <a href="#cargo_build_script-proc_macro_deps">proc_macro_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-rundir">rundir</a>,
<a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</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 @@ -132,10 +133,15 @@ The `hello_lib` target will be build with the flags and the environment variable
| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="cargo_build_script-name"></a>name | The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of <code>_build_script</code>. | none |
| <a id="cargo_build_script-edition"></a>edition | The rust edition to use for the internal binary crate. | `None` |
| <a id="cargo_build_script-crate_name"></a>crate_name | Crate name to use for build script. | `None` |
| <a id="cargo_build_script-crate_root"></a>crate_root | The file that will be passed to rustc to be used for building this crate. | `None` |
| <a id="cargo_build_script-srcs"></a>srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made. | `[]` |
| <a id="cargo_build_script-crate_features"></a>crate_features | A list of features to enable for the build script. | `[]` |
| <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | `None` |
| <a id="cargo_build_script-deps"></a>deps | The build-dependencies of the crate. | `[]` |
| <a id="cargo_build_script-link_deps"></a>link_deps | The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script. | `[]` |
| <a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps | List of rust_proc_macro targets used to build the script. | `[]` |
| <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | `{}` |
| <a id="cargo_build_script-data"></a>data | Files needed by the build script. | `[]` |
| <a id="cargo_build_script-tools"></a>tools | Tools (executables) needed by the build script. | `[]` |
Expand All @@ -145,6 +151,7 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-rustc_flags"></a>rustc_flags | List of compiler flags passed to <code>rustc</code>. | `[]` |
| <a id="cargo_build_script-visibility"></a>visibility | Visibility to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-tags"></a>tags | (list of str, optional): Tags to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target. These are other <code>rust_library</code> targets and will be presented as the new name given. | `None` |
| <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying <code>rust_binary</code> rule. An exception is the <code>compatible_with</code> attribute, which shouldn't be forwarded to the <code>rust_binary</code>, as the <code>rust_binary</code> is only built and used in <code>exec</code> mode. We propagate the <code>compatible_with</code> attribute to the <code>_build_scirpt_run</code> target. | none |


Expand Down
11 changes: 9 additions & 2 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,9 @@ A collection of files either found within the `rust-stdlib` artifact or generate
## 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-link_deps">link_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-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</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-edition">edition</a>, <a href="#cargo_build_script-crate_name">crate_name</a>, <a href="#cargo_build_script-crate_root">crate_root</a>, <a href="#cargo_build_script-srcs">srcs</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-link_deps">link_deps</a>, <a href="#cargo_build_script-proc_macro_deps">proc_macro_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-rundir">rundir</a>,
<a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</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 @@ -1614,10 +1615,15 @@ The `hello_lib` target will be build with the flags and the environment variable
| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="cargo_build_script-name"></a>name | The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of <code>_build_script</code>. | none |
| <a id="cargo_build_script-edition"></a>edition | The rust edition to use for the internal binary crate. | `None` |
| <a id="cargo_build_script-crate_name"></a>crate_name | Crate name to use for build script. | `None` |
| <a id="cargo_build_script-crate_root"></a>crate_root | The file that will be passed to rustc to be used for building this crate. | `None` |
| <a id="cargo_build_script-srcs"></a>srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made. | `[]` |
| <a id="cargo_build_script-crate_features"></a>crate_features | A list of features to enable for the build script. | `[]` |
| <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | `None` |
| <a id="cargo_build_script-deps"></a>deps | The build-dependencies of the crate. | `[]` |
| <a id="cargo_build_script-link_deps"></a>link_deps | The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script. | `[]` |
| <a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps | List of rust_proc_macro targets used to build the script. | `[]` |
| <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | `{}` |
| <a id="cargo_build_script-data"></a>data | Files needed by the build script. | `[]` |
| <a id="cargo_build_script-tools"></a>tools | Tools (executables) needed by the build script. | `[]` |
Expand All @@ -1627,6 +1633,7 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-rustc_flags"></a>rustc_flags | List of compiler flags passed to <code>rustc</code>. | `[]` |
| <a id="cargo_build_script-visibility"></a>visibility | Visibility to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-tags"></a>tags | (list of str, optional): Tags to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target. These are other <code>rust_library</code> targets and will be presented as the new name given. | `None` |
| <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying <code>rust_binary</code> rule. An exception is the <code>compatible_with</code> attribute, which shouldn't be forwarded to the <code>rust_binary</code>, as the <code>rust_binary</code> is only built and used in <code>exec</code> mode. We propagate the <code>compatible_with</code> attribute to the <code>_build_scirpt_run</code> target. | none |


Expand Down