-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Platform transition added to Rust binary rules. (#2310)
Without much insight into core Bazel's plans for supporting "flagless" builds across platforms, this seems like the most direct way to select the platform for a given Rust binary target (all the terminal rules) that doesn't need additional work to forward providers. Currently I'm using `platform_transition_binary` (https://github.com/aspect-build/bazel-lib/blob/main/docs/transitions.md), but it doesn't work with Rust Analyzer/Clippy/etc. presumably due to not forwarding the providers. In the case of this particular rule, it also doesn't work for something like `rust_shared_library()` which is explicitly not an `executable = True` target. @illicitonion brought to my attention `with_cfg` (https://github.com/fmeum/with_cfg.bzl) which could be used as an alternative by consumers of `rules_rust` instead of this PR. That feels reasonable, though certainly more work for individual users and appears to rely on a lot of Bazel black magic. Along the same lines, this could wait on rule inheritance as presumably a more formally supported `with_cfg` approach, which would also be up to individual users and not `rules_rust`.
- Loading branch information
1 parent
c3581a5
commit 0e4be00
Showing
7 changed files
with
340 additions
and
190 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.