aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinh Tran <vinhdaitran@google.com>2023-10-09 22:57:32 -0400
committerGitHub <noreply@github.com>2023-10-09 19:57:32 -0700
commit3e124fb9f5fb91554908fd7fb82d10c378ee4ca8 (patch)
tree3cf1d9788a26d3dfd9c0352d785dc77b31dbe117
parenta7eba053b9b8964f83d5a9ee76ed919a8e385362 (diff)
downloadbazelbuild-rules_rust-3e124fb9f5fb91554908fd7fb82d10c378ee4ca8.tar.gz
Add target_compatible_with from kwargs to build_script_kwargs (#2133)
The top-level `_build_script_run` target should also have `target_compatible_with` in order to work with platforms compatibility.
-rw-r--r--cargo/private/cargo_build_script_wrapper.bzl34
-rw-r--r--docs/cargo.md11
-rw-r--r--docs/flatten.md11
3 files changed, 38 insertions, 18 deletions
diff --git a/cargo/private/cargo_build_script_wrapper.bzl b/cargo/private/cargo_build_script_wrapper.bzl
index 6420b732..579630fa 100644
--- a/cargo/private/cargo_build_script_wrapper.bzl
+++ b/cargo/private/cargo_build_script_wrapper.bzl
@@ -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 = [],
@@ -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
@@ -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.
@@ -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`
@@ -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,
@@ -160,5 +166,5 @@ def cargo_build_script(
rustc_flags = rustc_flags,
visibility = visibility,
tags = tags,
- **build_script_kwargs
+ **kwargs
)
diff --git a/docs/cargo.md b/docs/cargo.md
index 4033c74c..15cf0280 100644
--- a/docs/cargo.md
+++ b/docs/cargo.md
@@ -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
@@ -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. | `[]` |
@@ -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 |
diff --git a/docs/flatten.md b/docs/flatten.md
index 007689e8..49ed5155 100644
--- a/docs/flatten.md
+++ b/docs/flatten.md
@@ -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
@@ -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. | `[]` |
@@ -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 |