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

Platform transition added to Rust binary rules. #2310

Merged
merged 1 commit into from
Dec 13, 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
16 changes: 10 additions & 6 deletions docs/defs.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/flatten.md

Large diffs are not rendered by default.

161 changes: 20 additions & 141 deletions examples/nix_cross_compiling/BUILD.bazel
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",
)
63 changes: 63 additions & 0 deletions examples/nix_cross_compiling/cc_binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
130 changes: 113 additions & 17 deletions examples/nix_cross_compiling/rust_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Loading
Loading