Skip to content

Commit

Permalink
Platform transition added to Rust binary rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickvanprim committed Dec 9, 2023
1 parent 0a4c4df commit 7f62a13
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 211 deletions.
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",
)
52 changes: 29 additions & 23 deletions examples/nix_cross_compiling/bazel/cargo/cargo-bazel-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Loading

0 comments on commit 7f62a13

Please sign in to comment.