diff --git a/docs/defs.md b/docs/defs.md index e44c1826d9..90fee223d0 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -93,7 +93,7 @@ Add additional rustc_flags from the command line with `--@rules_rust//:extra_rus
rust_binary(name, aliases, compile_data, crate_features, crate_name, crate_root, crate_type, data, deps, edition, env, experimental_use_cc_common_link, linker_script, malloc, out_binary, - proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version) + platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)Builds a Rust binary crate. @@ -203,6 +203,7 @@ is available under the key `dsym_folder` in `OutputGroupInfo`. | linker_script | Link script to forward into linker via rustc options. | Label | optional |
None
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
| out_binary | Force a target, regardless of it's crate_type
, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771. | Boolean | optional | False
|
+| platform | Optional platform to transition the binary to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -403,8 +404,8 @@ Builds a Rust proc-macro crate.
rust_shared_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps, - edition, experimental_use_cc_common_link, malloc, proc_macro_deps, rustc_env, - rustc_env_files, rustc_flags, srcs, stamp, version) + edition, experimental_use_cc_common_link, malloc, platform, proc_macro_deps, + rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)Builds a Rust shared library. @@ -434,6 +435,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional |
""
|
| experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | -1
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
+| platform | Optional platform to transition the shared library to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -449,8 +451,8 @@ When building the whole binary in Bazel, use `rust_library` instead.
rust_static_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps, - edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, - version) + edition, platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, + stamp, version)Builds a Rust static library. @@ -478,6 +480,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | data | List of files used by this rule at compile time and runtime.
compile_data
over data
, to prevent the data also being included in the runfiles. | List of labels | optional | []
|
| deps | List of other libraries to be linked to this library target.rust_library
targets or cc_library
targets if linking a native library. | List of labels | optional | []
|
| edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | ""
|
+| platform | Optional platform to transition the static library to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -493,7 +496,7 @@ When building the whole binary in Bazel, use `rust_library` instead.
rust_test(name, aliases, compile_data, crate, crate_features, crate_name, crate_root, data, deps, - edition, env, experimental_use_cc_common_link, malloc, proc_macro_deps, rustc_env, + edition, env, experimental_use_cc_common_link, malloc, platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, use_libtest_harness, version)@@ -634,6 +637,7 @@ Run the test with `bazel test //hello_lib:greeting_test`. | env | Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to
$(rootpath)
, $(execpath)
, location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. | Dictionary: String -> String | optional | {}
|
| experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | -1
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
+| platform | Optional platform to transition the test to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
diff --git a/docs/flatten.md b/docs/flatten.md
index 5273d745a9..254c5edcd0 100644
--- a/docs/flatten.md
+++ b/docs/flatten.md
@@ -234,7 +234,7 @@ A toolchain for [rust-analyzer](https://rust-analyzer.github.io/).
rust_binary(name, aliases, compile_data, crate_features, crate_name, crate_root, crate_type, data, deps, edition, env, experimental_use_cc_common_link, linker_script, malloc, out_binary, - proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version) + platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)Builds a Rust binary crate. @@ -344,6 +344,7 @@ is available under the key `dsym_folder` in `OutputGroupInfo`. | linker_script | Link script to forward into linker via rustc options. | Label | optional |
None
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
| out_binary | Force a target, regardless of it's crate_type
, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771. | Boolean | optional | False
|
+| platform | Optional platform to transition the binary to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -905,8 +906,8 @@ rust_binary(
rust_shared_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps, - edition, experimental_use_cc_common_link, malloc, proc_macro_deps, rustc_env, - rustc_env_files, rustc_flags, srcs, stamp, version) + edition, experimental_use_cc_common_link, malloc, platform, proc_macro_deps, + rustc_env, rustc_env_files, rustc_flags, srcs, stamp, version)Builds a Rust shared library. @@ -936,6 +937,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional |
""
|
| experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | -1
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
+| platform | Optional platform to transition the shared library to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -951,8 +953,8 @@ When building the whole binary in Bazel, use `rust_library` instead.
rust_static_library(name, aliases, compile_data, crate_features, crate_name, crate_root, data, deps, - edition, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, - version) + edition, platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, + stamp, version)Builds a Rust static library. @@ -980,6 +982,7 @@ When building the whole binary in Bazel, use `rust_library` instead. | data | List of files used by this rule at compile time and runtime.
compile_data
over data
, to prevent the data also being included in the runfiles. | List of labels | optional | []
|
| deps | List of other libraries to be linked to this library target.rust_library
targets or cc_library
targets if linking a native library. | List of labels | optional | []
|
| edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | ""
|
+| platform | Optional platform to transition the static library to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
@@ -1014,7 +1017,7 @@ A dedicated filegroup-like rule for Rust stdlib artifacts.
rust_test(name, aliases, compile_data, crate, crate_features, crate_name, crate_root, data, deps, - edition, env, experimental_use_cc_common_link, malloc, proc_macro_deps, rustc_env, + edition, env, experimental_use_cc_common_link, malloc, platform, proc_macro_deps, rustc_env, rustc_env_files, rustc_flags, srcs, stamp, use_libtest_harness, version)@@ -1155,6 +1158,7 @@ Run the test with `bazel test //hello_lib:greeting_test`. | env | Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to
$(rootpath)
, $(execpath)
, location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. | Dictionary: String -> String | optional | {}
|
| experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | -1
|
| malloc | Override the default dependency on malloc
.@bazel_tools//tools/cpp:malloc"
, which is an empty library and the resulting binary will use libc's malloc
. This label must refer to a cc_library
rule. | Label | optional | @bazel_tools//tools/cpp:malloc
|
+| platform | Optional platform to transition the test to. | Label | optional | None
|
| proc_macro_deps | List of rust_proc_macro
targets used to help build this library target. | List of labels | optional | []
|
| rustc_env | Dictionary of additional "key": "value"
environment variables to set for rustc.{}
|
| rustc_env_files | Files containing additional environment variables to set for rustc.NAME=value
, and newlines may be included in a value by ending a line with a trailing back-slash (\\
).stamp
attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. NAME={WORKSPACE_STATUS_VARIABLE}
. | List of labels | optional | []
|
diff --git a/examples/nix_cross_compiling/BUILD.bazel b/examples/nix_cross_compiling/BUILD.bazel
index 702f9ca35b..257a94728e 100644
--- a/examples/nix_cross_compiling/BUILD.bazel
+++ b/examples/nix_cross_compiling/BUILD.bazel
@@ -1,150 +1,29 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
-load("//bazel:transitions.bzl", "platform_transition_binary")
# Disabled targets need the user to supply a sysroot in `flake.nix` first.
build_test(
name = "nix_cross_compiling",
targets = [
- # ":cc_binary_aarch64-apple-darwin",
- # ":cc_binary_aarch64-apple-ios",
- ":cc_binary_aarch64-linux-android",
- ":cc_binary_aarch64-unknown-linux-gnu",
- ":cc_binary_wasm32-unknown-unknown",
- ":cc_binary_wasm32-wasi",
- # ":cc_binary_x86_64-apple-darwin",
- # ":cc_binary_x86_64-pc-windows-msvc",
- ":cc_binary_x86_64-unknown-linux-gnu",
- ":cc_binary_x86_64-unknown-nixos-gnu",
- # ":rust_binary_aarch64-apple-darwin",
- # ":rust_binary_aarch64-apple-ios",
- ":rust_binary_aarch64-linux-android",
- ":rust_binary_aarch64-unknown-linux-gnu",
- ":rust_binary_wasm32-unknown-unknown",
- ":rust_binary_wasm32-wasi",
- # ":rust_binary_x86_64-apple-darwin",
- # ":rust_binary_x86_64-pc-windows-msvc",
- ":rust_binary_x86_64-unknown-linux-gnu",
- ":rust_binary_x86_64-unknown-nixos-gnu",
+ # "//cc_binary:cc_binary_aarch64-apple-darwin",
+ # "//cc_binary:cc_binary_aarch64-apple-ios",
+ "//cc_binary:cc_binary_aarch64-linux-android",
+ "//cc_binary:cc_binary_aarch64-unknown-linux-gnu",
+ "//cc_binary:cc_binary_wasm32-unknown-unknown",
+ "//cc_binary:cc_binary_wasm32-wasi",
+ # "//cc_binary:cc_binary_x86_64-apple-darwin",
+ # "//cc_binary:cc_binary_x86_64-pc-windows-msvc",
+ "//cc_binary:cc_binary_x86_64-unknown-linux-gnu",
+ "//cc_binary:cc_binary_x86_64-unknown-nixos-gnu",
+ # "//rust_binary:rust_binary_aarch64-apple-darwin",
+ # "//rust_binary:rust_binary_aarch64-apple-ios",
+ "//rust_binary:rust_binary_aarch64-linux-android",
+ "//rust_binary:rust_binary_aarch64-unknown-linux-gnu",
+ "//rust_binary:rust_binary_wasm32-unknown-unknown",
+ "//rust_binary:rust_binary_wasm32-wasi",
+ # "//rust_binary:rust_binary_x86_64-apple-darwin",
+ # "//rust_binary:rust_binary_x86_64-pc-windows-msvc",
+ "//rust_binary:rust_binary_x86_64-unknown-linux-gnu",
+ "//rust_binary:rust_binary_x86_64-unknown-nixos-gnu",
],
)
-
-# platform_transition_binary(
-# name = "cc_binary_aarch64-apple-darwin",
-# binary = "//cc_binary",
-# target_platform = "//bazel/platforms:aarch64-apple-darwin",
-# )
-
-# platform_transition_binary(
-# name = "cc_binary_aarch64-apple-ios",
-# binary = "//cc_binary",
-# target_platform = "//bazel/platforms:aarch64-apple-ios",
-# )
-
-platform_transition_binary(
- name = "cc_binary_aarch64-linux-android",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:aarch64-linux-android",
-)
-
-platform_transition_binary(
- name = "cc_binary_aarch64-unknown-linux-gnu",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:aarch64-unknown-linux-gnu",
-)
-
-platform_transition_binary(
- name = "cc_binary_wasm32-unknown-unknown",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:wasm32-unknown-unknown",
-)
-
-platform_transition_binary(
- name = "cc_binary_wasm32-wasi",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:wasm32-wasi",
-)
-
-# platform_transition_binary(
-# name = "cc_binary_x86_64-apple-darwin",
-# binary = "//cc_binary",
-# target_platform = "//bazel/platforms:x86_64-apple-darwin",
-# )
-
-# platform_transition_binary(
-# name = "cc_binary_x86_64-pc-windows-msvc",
-# binary = "//cc_binary",
-# target_platform = "//bazel/platforms:x86_64-pc-windows-msvc",
-# )
-
-platform_transition_binary(
- name = "cc_binary_x86_64-unknown-linux-gnu",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:x86_64-unknown-linux-gnu",
-)
-
-platform_transition_binary(
- name = "cc_binary_x86_64-unknown-nixos-gnu",
- binary = "//cc_binary",
- target_platform = "//bazel/platforms:x86_64-unknown-nixos-gnu",
-)
-
-# platform_transition_binary(
-# name = "rust_binary_aarch64-apple-darwin",
-# binary = "//rust_binary",
-# target_platform = "//bazel/platforms:aarch64-apple-darwin",
-# )
-
-# platform_transition_binary(
-# name = "rust_binary_aarch64-apple-ios",
-# binary = "//rust_binary",
-# target_platform = "//bazel/platforms:aarch64-apple-ios",
-# )
-
-platform_transition_binary(
- name = "rust_binary_aarch64-linux-android",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:aarch64-linux-android",
-)
-
-platform_transition_binary(
- name = "rust_binary_aarch64-unknown-linux-gnu",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:aarch64-unknown-linux-gnu",
-)
-
-platform_transition_binary(
- name = "rust_binary_wasm32-unknown-unknown",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:wasm32-unknown-unknown",
-)
-
-platform_transition_binary(
- name = "rust_binary_wasm32-wasi",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:wasm32-wasi",
-)
-
-# platform_transition_binary(
-# name = "rust_binary_x86_64-apple-darwin",
-# binary = "//rust_binary",
-# target_platform = "//bazel/platforms:x86_64-apple-darwin",
-# )
-
-# platform_transition_binary(
-# name = "rust_binary_x86_64-pc-windows-msvc",
-# binary = "//rust_binary",
-# target_platform = "//bazel/platforms:x86_64-pc-windows-msvc",
-# )
-
-platform_transition_binary(
- name = "rust_binary_x86_64-unknown-linux-gnu",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:x86_64-unknown-linux-gnu",
-)
-
-platform_transition_binary(
- name = "rust_binary_x86_64-unknown-nixos-gnu",
- binary = "//rust_binary",
- target_platform = "//bazel/platforms:x86_64-unknown-nixos-gnu",
-)
diff --git a/examples/nix_cross_compiling/cc_binary/BUILD.bazel b/examples/nix_cross_compiling/cc_binary/BUILD.bazel
index 68085d41c8..f68b240eea 100644
--- a/examples/nix_cross_compiling/cc_binary/BUILD.bazel
+++ b/examples/nix_cross_compiling/cc_binary/BUILD.bazel
@@ -1,7 +1,70 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
+load("//bazel:transitions.bzl", "platform_transition_binary")
package(default_visibility = ["//visibility:public"])
+# Disabled targets need the user to supply a sysroot in `flake.nix` first.
+
+# platform_transition_binary(
+# name = "cc_binary_aarch64-apple-darwin",
+# binary = ":cc_binary",
+# target_platform = "//bazel/platforms:aarch64-apple-darwin",
+# )
+
+# platform_transition_binary(
+# name = "cc_binary_aarch64-apple-ios",
+# binary = ":cc_binary",
+# target_platform = "//bazel/platforms:aarch64-apple-ios",
+# )
+
+platform_transition_binary(
+ name = "cc_binary_aarch64-linux-android",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:aarch64-linux-android",
+)
+
+platform_transition_binary(
+ name = "cc_binary_aarch64-unknown-linux-gnu",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:aarch64-unknown-linux-gnu",
+)
+
+platform_transition_binary(
+ name = "cc_binary_wasm32-unknown-unknown",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:wasm32-unknown-unknown",
+)
+
+platform_transition_binary(
+ name = "cc_binary_wasm32-wasi",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:wasm32-wasi",
+)
+
+# platform_transition_binary(
+# name = "cc_binary_x86_64-apple-darwin",
+# binary = ":cc_binary",
+# target_platform = "//bazel/platforms:x86_64-apple-darwin",
+# )
+
+# platform_transition_binary(
+# name = "cc_binary_x86_64-pc-windows-msvc",
+# binary = ":cc_binary",
+# target_platform = "//bazel/platforms:x86_64-pc-windows-msvc",
+# )
+
+platform_transition_binary(
+ name = "cc_binary_x86_64-unknown-linux-gnu",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:x86_64-unknown-linux-gnu",
+)
+
+platform_transition_binary(
+ name = "cc_binary_x86_64-unknown-nixos-gnu",
+ binary = ":cc_binary",
+ target_platform = "//bazel/platforms:x86_64-unknown-nixos-gnu",
+)
+
cc_binary(
name = "cc_binary",
srcs = select({
diff --git a/examples/nix_cross_compiling/rust_binary/BUILD.bazel b/examples/nix_cross_compiling/rust_binary/BUILD.bazel
index 71368e7b1e..dcc1b4a6fb 100644
--- a/examples/nix_cross_compiling/rust_binary/BUILD.bazel
+++ b/examples/nix_cross_compiling/rust_binary/BUILD.bazel
@@ -2,27 +2,123 @@ load("@rules_rust//rust:defs.bzl", "rust_binary")
package(default_visibility = ["//visibility:public"])
+# rust_binary(
+# name = "rust_binary_aarch64-apple-darwin",
+# srcs = ["rust_binary.rs"],
+# platform = "//bazel/platforms:aarch64-apple-darwin",
+# deps = [
+# "//cc_library",
+# "//rust_library",
+# "@crate_index//:anyhow",
+# "@crate_index//:tokio",
+# ],
+# )
+
+# rust_binary(
+# name = "rust_binary_aarch64-apple-ios",
+# srcs = ["rust_binary.rs"],
+# platform = "//bazel/platforms:aarch64-apple-ios",
+# deps = [
+# "//cc_library",
+# "//rust_library",
+# "@crate_index//:anyhow",
+# "@crate_index//:tokio",
+# ],
+# )
+
+rust_binary(
+ name = "rust_binary_aarch64-linux-android",
+ srcs = ["rust_binary.rs"],
+ platform = "//bazel/platforms:aarch64-linux-android",
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ "@crate_index//:tokio",
+ ],
+)
+
+rust_binary(
+ name = "rust_binary_aarch64-unknown-linux-gnu",
+ srcs = ["rust_binary.rs"],
+ platform = "//bazel/platforms:aarch64-unknown-linux-gnu",
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ "@crate_index//:tokio",
+ ],
+)
+
rust_binary(
- name = "rust_binary",
- srcs = select({
- # See comments in `rust_binary_wasm32-unknown-unknown.rs`.
- "@platforms//os:none": ["rust_binary_wasm32-unknown-unknown.rs"],
- # See comments in `rust_binary_wasm32-wasi.rs`.
- "@platforms//os:wasi": ["rust_binary_wasm32-wasi.rs"],
- "//conditions:default": ["rust_binary.rs"],
- }),
- tags = ["platform_missing"],
+ name = "rust_binary_wasm32-unknown-unknown",
+ srcs = ["rust_binary_wasm32-unknown-unknown.rs"], # See comments in `rust_binary_wasm32-unknown-unknown.rs`.
+ platform = "//bazel/platforms:wasm32-unknown-unknown",
deps = [
"//cc_library",
"//rust_library",
"@crate_index//:anyhow",
- ] + select({
- "@platforms//os:none": [],
- # To be removed once the `wasm32-wasi` version of `tokio` can `select()`
+ ],
+)
+
+rust_binary(
+ name = "rust_binary_wasm32-wasi",
+ srcs = ["rust_binary_wasm32-wasi.rs"], # See comments in `rust_binary_wasm32-wasi.rs`.
+ platform = "//bazel/platforms:wasm32-wasi",
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ # To be added once the `wasm32-wasi` version of `tokio` can `select()`
# over different features.
- "@platforms//os:wasi": [],
- "//conditions:default": [
- "@crate_index//:tokio",
- ],
- }),
+ # "@crate_index//:tokio",
+ ],
+)
+
+# rust_binary(
+# name = "rust_binary_x86_64-apple-darwin",
+# srcs = ["rust_binary.rs"],
+# platform = "//bazel/platforms:x86_64-apple-darwin",
+# deps = [
+# "//cc_library",
+# "//rust_library",
+# "@crate_index//:anyhow",
+# "@crate_index//:tokio",
+# ],
+# )
+
+# rust_binary(
+# name = "rust_binary_x86_64-pc-windows-msvc",
+# srcs = ["rust_binary.rs"],
+# platform = "//bazel/platforms:x86_64-pc-windows-msvc",
+# deps = [
+# "//cc_library",
+# "//rust_library",
+# "@crate_index//:anyhow",
+# "@crate_index//:tokio",
+# ],
+# )
+
+rust_binary(
+ name = "rust_binary_x86_64-unknown-linux-gnu",
+ srcs = ["rust_binary.rs"],
+ platform = "//bazel/platforms:x86_64-unknown-linux-gnu",
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ "@crate_index//:tokio",
+ ],
+)
+
+rust_binary(
+ name = "rust_binary_x86_64-unknown-nixos-gnu",
+ srcs = ["rust_binary.rs"],
+ platform = "//bazel/platforms:x86_64-unknown-nixos-gnu",
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ "@crate_index//:tokio",
+ ],
)
diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl
index 343ab761f3..4147bf59a3 100644
--- a/rust/private/rust.bzl
+++ b/rust/private/rust.bzl
@@ -579,7 +579,7 @@ _common_attrs = {
The order that these files will be processed is unspecified, so
multiple definitions of a particular variable are discouraged.
- Note that the variables here are subject to
+ Note that the variables here are subject to
[workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status)
stamping should the `stamp` attribute be enabled. Stamp variables
should be wrapped in brackets in order to be resolved. E.g.
@@ -592,7 +592,7 @@ _common_attrs = {
List of compiler flags passed to `rustc`.
These strings are subject to Make variable expansion for predefined
- source/output path variables like `$location`, `$execpath`, and
+ source/output path variables like `$location`, `$execpath`, and
`$rootpath`. This expansion is useful if you wish to pass a generated
file of arguments to rustc: `@$(location //package:target)`.
"""),
@@ -746,7 +746,7 @@ _rust_test_attrs = dict({
mandatory = False,
default = True,
doc = dedent("""\
- Whether to use `libtest`. For targets using this flag, individual tests can be run by using the
+ Whether to use `libtest`. For targets using this flag, individual tests can be run by using the
[--test_arg](https://docs.bazel.build/versions/4.0.0/command-line-reference.html#flag--test_arg) flag.
E.g. `bazel test //src:rust_test --test_arg=foo::test::test_fn`.
"""),
@@ -846,11 +846,35 @@ rust_library = rule(
"""),
)
+def _rust_static_library_transition_impl(settings, attr):
+ return {
+ "//command_line_option:platforms": str(attr.platform) if attr.platform else settings["//command_line_option:platforms"],
+ }
+
+_rust_static_library_transition = transition(
+ implementation = _rust_static_library_transition_impl,
+ inputs = [
+ "//command_line_option:platforms",
+ ],
+ outputs = [
+ "//command_line_option:platforms",
+ ],
+)
+
rust_static_library = rule(
implementation = _rust_static_library_impl,
- attrs = dict(_common_attrs.items()),
+ attrs = dict(_common_attrs.items() + {
+ "platform": attr.label(
+ doc = "Optional platform to transition the static library to.",
+ default = None,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ }.items()),
fragments = ["cpp"],
host_fragments = ["cpp"],
+ cfg = _rust_static_library_transition,
toolchains = [
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
@@ -869,15 +893,36 @@ rust_static_library = rule(
"""),
)
+def _rust_shared_library_transition_impl(settings, attr):
+ return {
+ "//command_line_option:platforms": str(attr.platform) if attr.platform else settings["//command_line_option:platforms"],
+ }
+
+_rust_shared_library_transition = transition(
+ implementation = _rust_shared_library_transition_impl,
+ inputs = [
+ "//command_line_option:platforms",
+ ],
+ outputs = [
+ "//command_line_option:platforms",
+ ],
+)
+
rust_shared_library = rule(
implementation = _rust_shared_library_impl,
- attrs = dict(
- _common_attrs.items() + _experimental_use_cc_common_link_attrs.items() + {
- "_use_grep_includes": attr.bool(default = True),
- }.items(),
- ),
+ attrs = dict(_common_attrs.items() + _experimental_use_cc_common_link_attrs.items() + {
+ "platform": attr.label(
+ doc = "Optional platform to transition the shared library to.",
+ default = None,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ "_use_grep_includes": attr.bool(default = True),
+ }.items()),
fragments = ["cpp"],
host_fragments = ["cpp"],
+ cfg = _rust_shared_library_transition,
toolchains = [
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
@@ -920,11 +965,11 @@ rust_proc_macro = rule(
_allowlist_function_transition = attr.label(default = Label("//tools/allowlists/function_transition_allowlist")),
deps = attr.label_list(
doc = dedent("""\
- List of other libraries to be linked to this library target.
+ List of other libraries to be linked to this library target.
- These can be either other `rust_library` targets or `cc_library` targets if
- linking a native library.
- """),
+ These can be either other `rust_library` targets or `cc_library` targets if
+ linking a native library.
+ """),
cfg = _proc_macro_dep_transition,
),
),
@@ -937,7 +982,7 @@ rust_proc_macro = rule(
incompatible_use_toolchain_transition = True,
doc = dedent("""\
Builds a Rust proc-macro crate.
- """),
+ """),
)
_rust_binary_attrs = dict({
@@ -980,13 +1025,37 @@ _rust_binary_attrs = dict({
"_use_grep_includes": attr.bool(default = True),
}.items() + _experimental_use_cc_common_link_attrs.items())
+def _rust_binary_transition_impl(settings, attr):
+ return {
+ "//command_line_option:platforms": str(attr.platform) if attr.platform else settings["//command_line_option:platforms"],
+ }
+
+_rust_binary_transition = transition(
+ implementation = _rust_binary_transition_impl,
+ inputs = [
+ "//command_line_option:platforms",
+ ],
+ outputs = [
+ "//command_line_option:platforms",
+ ],
+)
+
rust_binary = rule(
implementation = _rust_binary_impl,
provides = _common_providers,
- attrs = dict(_common_attrs.items() + _rust_binary_attrs.items()),
+ attrs = dict(_common_attrs.items() + _rust_binary_attrs.items() + {
+ "platform": attr.label(
+ doc = "Optional platform to transition the binary to.",
+ default = None,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ }.items()),
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
+ cfg = _rust_binary_transition,
toolchains = [
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
@@ -1118,10 +1187,19 @@ def _common_attrs_for_binary_without_process_wrapper(attrs):
rust_binary_without_process_wrapper = rule(
implementation = _rust_binary_impl,
provides = _common_providers,
- attrs = _common_attrs_for_binary_without_process_wrapper(_common_attrs.items() + _rust_binary_attrs.items()),
+ attrs = _common_attrs_for_binary_without_process_wrapper(_common_attrs.items() + _rust_binary_attrs.items() + {
+ "platform": attr.label(
+ doc = "Optional platform to transition the binary to.",
+ default = None,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ }.items()),
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
+ cfg = _rust_binary_transition,
toolchains = [
str(Label("//rust:toolchain_type")),
"@bazel_tools//tools/cpp:toolchain_type",
@@ -1142,14 +1220,37 @@ rust_library_without_process_wrapper = rule(
incompatible_use_toolchain_transition = True,
)
+def _rust_test_transition_impl(settings, attr):
+ return {
+ "//command_line_option:platforms": str(attr.platform) if attr.platform else settings["//command_line_option:platforms"],
+ }
+
+_rust_test_transition = transition(
+ implementation = _rust_test_transition_impl,
+ inputs = [
+ "//command_line_option:platforms",
+ ],
+ outputs = [
+ "//command_line_option:platforms",
+ ],
+)
+
rust_test = rule(
implementation = _rust_test_impl,
provides = _common_providers,
- attrs = dict(_common_attrs.items() +
- _rust_test_attrs.items()),
+ attrs = dict(_common_attrs.items() + _rust_test_attrs.items() + {
+ "platform": attr.label(
+ doc = "Optional platform to transition the test to.",
+ default = None,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ }.items()),
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
+ cfg = _rust_test_transition,
test = True,
toolchains = [
str(Label("//rust:toolchain_type")),
diff --git a/util/repin_all.sh b/util/repin_all.sh
index 994848117a..988d2022fd 100755
--- a/util/repin_all.sh
+++ b/util/repin_all.sh
@@ -7,7 +7,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")"/..
# Re-generates all files which may need to be re-generated after changing crate_universe.
bazel run //crate_universe/3rdparty:crates_vendor
-for d in examples/crate_universe* examples/nix_cross_compiling test/no_std
+for d in examples/crate_universe* test/no_std
do
- (cd ${d} && CARGO_BAZEL_REPIN=true bazel query @crate_index//... >/dev/null)
+ (cd ${d} && CARGO_BAZEL_REPIN=true bazel query //... >/dev/null)
done
+
+# `nix_cross_compiling` special cased as `//...` will invoke Nix.
+(cd examples/nix_cross_compiling && CARGO_BAZEL_REPIN=true bazel query @crate_index//... >/dev/null)