diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index edd97e364..ce9eef0f4 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -621,6 +621,21 @@ tasks:
# working_directory: examples/zig_cross_compiling
# build_targets:
# - "//..."
+ nix_cross_compiling:
+ name: Nix cross compiling test
+ platform: ubuntu2204
+ working_directory: examples/nix_cross_compiling
+ setup:
+ - curl -L https://nixos.org/nix/install | bash
+ - sudo cp ~/.nix-profile/bin/nix* /usr/local/bin/
+ - sudo mkdir /etc/nix
+ - echo "experimental-features = nix-command flakes" | sudo tee --append /etc/nix/nix.conf
+ build_targets:
+ # Root `build_test` target is called directly to catch missing platforms
+ # that would otherwise be quietly skipped due to `target_compatible_with`.
+ - "//:nix_cross_compiling"
+ test_targets:
+ - "//..."
buildifier:
version: latest
diff --git a/.envrc b/.envrc
new file mode 100644
index 000000000..650c81c17
--- /dev/null
+++ b/.envrc
@@ -0,0 +1,10 @@
+# `nix-direnv` to provide developer tools to terminals and VSCode when working
+# in the repo.
+#
+# See:
+# - https://github.com/nix-community/nix-direnv
+# - https://marketplace.visualstudio.com/items?itemName=mkhl.direnv
+
+# Use `path:` syntax to avoid copying the entire repo to the Nix Store.
+nix_direnv_watch_file ./nix/flake.nix
+use flake path:./nix
diff --git a/crate_universe/flake.lock b/crate_universe/flake.lock
new file mode 100644
index 000000000..f3c5cbdd9
--- /dev/null
+++ b/crate_universe/flake.lock
@@ -0,0 +1,61 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1694529238,
+ "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1700444282,
+ "narHash": "sha256-s/+tgT+Iz0LZO+nBvSms+xsMqvHt2LqYniG9r+CYyJc=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "3f21a22b5aafefa1845dec6f4a378a8f53d8681c",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/crate_universe/flake.nix b/crate_universe/flake.nix
new file mode 100644
index 000000000..55672167f
--- /dev/null
+++ b/crate_universe/flake.nix
@@ -0,0 +1,26 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { self, nixpkgs, flake-utils, ... }:
+ flake-utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ in
+ {
+ packages.cargo-bazel = pkgs.rustPlatform.buildRustPackage {
+ pname = "cargo-bazel";
+ version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
+
+ src = ./.;
+ cargoLock.lockFile = ./Cargo.lock;
+
+ # Tests cannot be run via Cargo due to the dependency on the
+ # Bazel `runfiles` crate.
+ doCheck = false;
+ };
+ });
+}
diff --git a/examples/.bazelignore b/examples/.bazelignore
index a921d2043..d27cd1beb 100644
--- a/examples/.bazelignore
+++ b/examples/.bazelignore
@@ -4,4 +4,5 @@ crate_universe
crate_universe_unnamed
ios
ios_build
+nix_cross_compiling
zig_cross_compiling
diff --git a/examples/nix_cross_compiling/.bazelrc b/examples/nix_cross_compiling/.bazelrc
new file mode 100644
index 000000000..6686d26d1
--- /dev/null
+++ b/examples/nix_cross_compiling/.bazelrc
@@ -0,0 +1,15 @@
+# Sensible Defaults
+build --sandbox_default_allow_network=false
+build --incompatible_strict_action_env
+build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
+build --incompatible_enable_cc_toolchain_resolution=true
+
+# Require Platform Transitions
+## This works by setting the targte platform to an invalid platform
+## and each `x_binary()` and `x_library()` rule unfortunately needs
+## to tag itself with `platform_missing` to get excluded from glob
+## builds like `build //...` but still have a way to include them
+## by removing the filter line for things like Rust Analyzer.
+build --host_platform=//bazel/platforms:host
+build --platforms=//bazel/platforms:missing
+build --build_tag_filters=-platform_missing
diff --git a/examples/nix_cross_compiling/.gitignore b/examples/nix_cross_compiling/.gitignore
new file mode 100644
index 000000000..a6ef824c1
--- /dev/null
+++ b/examples/nix_cross_compiling/.gitignore
@@ -0,0 +1 @@
+/bazel-*
diff --git a/examples/nix_cross_compiling/BUILD.bazel b/examples/nix_cross_compiling/BUILD.bazel
new file mode 100644
index 000000000..702f9ca35
--- /dev/null
+++ b/examples/nix_cross_compiling/BUILD.bazel
@@ -0,0 +1,150 @@
+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",
+ ],
+)
+
+# 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/README.md b/examples/nix_cross_compiling/README.md
new file mode 100644
index 000000000..8438fafd8
--- /dev/null
+++ b/examples/nix_cross_compiling/README.md
@@ -0,0 +1,3 @@
+# Nix + Bazel Cross Compiling
+
+Blog Post:
diff --git a/examples/nix_cross_compiling/WORKSPACE.bazel b/examples/nix_cross_compiling/WORKSPACE.bazel
new file mode 100644
index 000000000..d4605e7c2
--- /dev/null
+++ b/examples/nix_cross_compiling/WORKSPACE.bazel
@@ -0,0 +1,87 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+# Nix
+http_archive(
+ name = "io_tweag_rules_nixpkgs",
+ sha256 = "54946958c311f48c17c9b2e70683b621fec135258b75173f3900f901d52d8115",
+ strip_prefix = "rules_nixpkgs-2b4702c8a0d1d7ea474ea0913344e8add2759f9c",
+ urls = ["https://github.com/tweag/rules_nixpkgs/archive/2b4702c8a0d1d7ea474ea0913344e8add2759f9c.tar.gz"],
+)
+
+load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
+
+rules_nixpkgs_dependencies()
+
+load("//bazel:nix_repositories.bzl", "nix_repositories")
+
+nix_repositories()
+
+# Rust
+local_repository(
+ name = "rules_rust",
+ path = "../..",
+)
+
+load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies")
+
+rules_rust_dependencies()
+
+load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "render_config", "splicing_config")
+load("//bazel/cargo:crates_repository.bzl", CARGO_ANNOTATIONS = "ANNOTATIONS", CARGO_PACKAGES = "PACKAGES")
+
+crates_repository(
+ name = "crate_index",
+ annotations = CARGO_ANNOTATIONS,
+ cargo_lockfile = "//bazel/cargo:Cargo.lock",
+ generate_build_scripts = False,
+ generator = "@cargo-bazel//:bin/cargo-bazel",
+ lockfile = "//bazel/cargo:cargo-bazel-lock.json",
+ packages = CARGO_PACKAGES,
+ render_config = render_config(
+ platforms_template = "@//bazel/cargo/platforms:{triple}",
+ ),
+ rust_toolchain_cargo_template = "@nix_rust//:bin/{tool}",
+ rust_toolchain_rustc_template = "@nix_rust//:bin/{tool}",
+ splicing_config = splicing_config(
+ resolver_version = "2",
+ ),
+ supported_platform_triples = [
+ "aarch64-apple-darwin",
+ "aarch64-apple-ios",
+ "aarch64-linux-android",
+ "aarch64-unknown-linux-gnu",
+ "wasm32-unknown-unknown",
+ "wasm32-wasi",
+ "x86_64-apple-darwin",
+ "x86_64-pc-windows-msvc",
+ "x86_64-unknown-linux-gnu",
+ ],
+)
+
+load("@crate_index//:defs.bzl", "crate_repositories")
+
+crate_repositories()
+
+# Toolchains
+register_toolchains(
+ "//bazel/toolchains/cc/aarch64-apple-darwin:toolchain",
+ "//bazel/toolchains/cc/aarch64-apple-ios:toolchain",
+ "//bazel/toolchains/cc/aarch64-linux-android:toolchain",
+ "//bazel/toolchains/cc/aarch64-unknown-linux-gnu:toolchain",
+ "//bazel/toolchains/cc/wasm32-unknown-unknown:toolchain",
+ "//bazel/toolchains/cc/wasm32-wasi:toolchain",
+ "//bazel/toolchains/cc/x86_64-apple-darwin:toolchain",
+ "//bazel/toolchains/cc/x86_64-pc-windows-msvc:toolchain",
+ "//bazel/toolchains/cc/x86_64-unknown-linux-gnu:toolchain",
+ "//bazel/toolchains/cc/x86_64-unknown-nixos-gnu:toolchain",
+ "//bazel/toolchains/rust/aarch64-apple-darwin:toolchain",
+ "//bazel/toolchains/rust/aarch64-apple-ios:toolchain",
+ "//bazel/toolchains/rust/aarch64-linux-android:toolchain",
+ "//bazel/toolchains/rust/aarch64-unknown-linux-gnu:toolchain",
+ "//bazel/toolchains/rust/wasm32-unknown-unknown:toolchain",
+ "//bazel/toolchains/rust/wasm32-wasi:toolchain",
+ "//bazel/toolchains/rust/x86_64-apple-darwin:toolchain",
+ "//bazel/toolchains/rust/x86_64-pc-windows-msvc:toolchain",
+ "//bazel/toolchains/rust/x86_64-unknown-linux-gnu:toolchain",
+ "//bazel/toolchains/rust/x86_64-unknown-nixos-gnu:toolchain",
+)
diff --git a/examples/nix_cross_compiling/bazel/BUILD.bazel b/examples/nix_cross_compiling/bazel/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/bazel/cargo/BUILD.bazel b/examples/nix_cross_compiling/bazel/cargo/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/bazel/cargo/Cargo.lock b/examples/nix_cross_compiling/bazel/cargo/Cargo.lock
new file mode 100644
index 000000000..90eda90c9
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/Cargo.lock
@@ -0,0 +1,365 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "addr2line"
+version = "0.21.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
+name = "anyhow"
+version = "1.0.75"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
+
+[[package]]
+name = "autocfg"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+
+[[package]]
+name = "backtrace"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "bytes"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
+
+[[package]]
+name = "cc"
+version = "1.0.84"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "direct-cargo-bazel-deps"
+version = "0.0.1"
+dependencies = [
+ "anyhow",
+ "tokio",
+]
+
+[[package]]
+name = "gimli"
+version = "0.28.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
+
+[[package]]
+name = "hermit-abi"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
+
+[[package]]
+name = "libc"
+version = "0.2.150"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
+
+[[package]]
+name = "lock_api"
+version = "0.4.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
+dependencies = [
+ "autocfg",
+ "scopeguard",
+]
+
+[[package]]
+name = "memchr"
+version = "2.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
+
+[[package]]
+name = "miniz_oxide"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
+dependencies = [
+ "adler",
+]
+
+[[package]]
+name = "mio"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
+dependencies = [
+ "libc",
+ "wasi",
+ "windows-sys",
+]
+
+[[package]]
+name = "num_cpus"
+version = "1.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
+dependencies = [
+ "hermit-abi",
+ "libc",
+]
+
+[[package]]
+name = "object"
+version = "0.32.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "parking_lot"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
+dependencies = [
+ "lock_api",
+ "parking_lot_core",
+]
+
+[[package]]
+name = "parking_lot_core"
+version = "0.9.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "redox_syscall",
+ "smallvec",
+ "windows-targets",
+]
+
+[[package]]
+name = "pin-project-lite"
+version = "0.2.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "rustc-demangle"
+version = "0.1.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+
+[[package]]
+name = "scopeguard"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+
+[[package]]
+name = "signal-hook-registry"
+version = "1.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "smallvec"
+version = "1.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
+
+[[package]]
+name = "socket2"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "tokio"
+version = "1.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
+dependencies = [
+ "backtrace",
+ "bytes",
+ "libc",
+ "mio",
+ "num_cpus",
+ "parking_lot",
+ "pin-project-lite",
+ "signal-hook-registry",
+ "socket2",
+ "tokio-macros",
+ "windows-sys",
+]
+
+[[package]]
+name = "tokio-macros"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
+
+[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
+name = "windows-sys"
+version = "0.48.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.48.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
diff --git a/examples/nix_cross_compiling/bazel/cargo/cargo-bazel-lock.json b/examples/nix_cross_compiling/bazel/cargo/cargo-bazel-lock.json
new file mode 100644
index 000000000..7a40041fd
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/cargo-bazel-lock.json
@@ -0,0 +1,1960 @@
+{
+ "checksum": "3ea228c74c6897dd56feea25dfd24669949e7a141dae208820d02da3e174a6af",
+ "crates": {
+ "addr2line 0.21.0": {
+ "name": "addr2line",
+ "version": "0.21.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/addr2line/0.21.0/download",
+ "sha256": "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "addr2line",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "addr2line",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "gimli 0.28.0",
+ "target": "gimli"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.21.0"
+ },
+ "license": "Apache-2.0 OR MIT"
+ },
+ "adler 1.0.2": {
+ "name": "adler",
+ "version": "1.0.2",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/adler/1.0.2/download",
+ "sha256": "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "adler",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "adler",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2015",
+ "version": "1.0.2"
+ },
+ "license": "0BSD OR MIT OR Apache-2.0"
+ },
+ "anyhow 1.0.75": {
+ "name": "anyhow",
+ "version": "1.0.75",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/anyhow/1.0.75/download",
+ "sha256": "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "anyhow",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "anyhow",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "std"
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "1.0.75"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "autocfg 1.1.0": {
+ "name": "autocfg",
+ "version": "1.1.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/autocfg/1.1.0/download",
+ "sha256": "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "autocfg",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "autocfg",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2015",
+ "version": "1.1.0"
+ },
+ "license": "Apache-2.0 OR MIT"
+ },
+ "backtrace 0.3.69": {
+ "name": "backtrace",
+ "version": "0.3.69",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/backtrace/0.3.69/download",
+ "sha256": "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "backtrace",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "backtrace",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "cfg-if 1.0.0",
+ "target": "cfg_if"
+ },
+ {
+ "id": "rustc-demangle 0.1.23",
+ "target": "rustc_demangle"
+ }
+ ],
+ "selects": {
+ "cfg(not(all(windows, target_env = \"msvc\", not(target_vendor = \"uwp\"))))": [
+ {
+ "id": "addr2line 0.21.0",
+ "target": "addr2line"
+ },
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ },
+ {
+ "id": "miniz_oxide 0.7.1",
+ "target": "miniz_oxide"
+ },
+ {
+ "id": "object 0.32.1",
+ "target": "object"
+ }
+ ]
+ }
+ },
+ "edition": "2018",
+ "version": "0.3.69"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "bitflags 1.3.2": {
+ "name": "bitflags",
+ "version": "1.3.2",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/bitflags/1.3.2/download",
+ "sha256": "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "bitflags",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "bitflags",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "1.3.2"
+ },
+ "license": "MIT/Apache-2.0"
+ },
+ "bytes 1.4.0": {
+ "name": "bytes",
+ "version": "1.4.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/bytes/1.4.0/download",
+ "sha256": "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "bytes",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "bytes",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "std"
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "1.4.0"
+ },
+ "license": "MIT"
+ },
+ "cc 1.0.84": {
+ "name": "cc",
+ "version": "1.0.84",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/cc/1.0.84/download",
+ "sha256": "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "cc",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "cc",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [],
+ "selects": {
+ "cfg(unix)": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ]
+ }
+ },
+ "edition": "2018",
+ "version": "1.0.84"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "cfg-if 1.0.0": {
+ "name": "cfg-if",
+ "version": "1.0.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/cfg-if/1.0.0/download",
+ "sha256": "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "cfg_if",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "cfg_if",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "1.0.0"
+ },
+ "license": "MIT/Apache-2.0"
+ },
+ "direct-cargo-bazel-deps 0.0.1": {
+ "name": "direct-cargo-bazel-deps",
+ "version": "0.0.1",
+ "repository": null,
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "direct_cargo_bazel_deps",
+ "crate_root": ".direct_cargo_bazel_deps.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "direct_cargo_bazel_deps",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "anyhow 1.0.75",
+ "target": "anyhow"
+ },
+ {
+ "id": "tokio 1.34.0",
+ "target": "tokio"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.0.1"
+ },
+ "license": null
+ },
+ "gimli 0.28.0": {
+ "name": "gimli",
+ "version": "0.28.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/gimli/0.28.0/download",
+ "sha256": "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "gimli",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "gimli",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.28.0"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "hermit-abi 0.3.3": {
+ "name": "hermit-abi",
+ "version": "0.3.3",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/hermit-abi/0.3.3/download",
+ "sha256": "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "hermit_abi",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "hermit_abi",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2021",
+ "version": "0.3.3"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "libc 0.2.150": {
+ "name": "libc",
+ "version": "0.2.150",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/libc/0.2.150/download",
+ "sha256": "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "libc",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "libc",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "std"
+ ],
+ "selects": {}
+ },
+ "edition": "2015",
+ "rustc_flags": [
+ "--cfg=freebsd11",
+ "--cfg=libc_priv_mod_use",
+ "--cfg=libc_union",
+ "--cfg=libc_const_size_of",
+ "--cfg=libc_align",
+ "--cfg=libc_int128",
+ "--cfg=libc_core_cvoid",
+ "--cfg=libc_packedN",
+ "--cfg=libc_cfg_target_vendor",
+ "--cfg=libc_non_exhaustive",
+ "--cfg=libc_long_array",
+ "--cfg=libc_ptr_addr_of",
+ "--cfg=libc_underscore_const_names",
+ "--cfg=libc_const_extern_fn"
+ ],
+ "version": "0.2.150"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "lock_api 0.4.11": {
+ "name": "lock_api",
+ "version": "0.4.11",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/lock_api/0.4.11/download",
+ "sha256": "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "lock_api",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "lock_api",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "atomic_usize",
+ "default"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "scopeguard 1.2.0",
+ "target": "scopeguard"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.4.11"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "memchr 2.6.4": {
+ "name": "memchr",
+ "version": "2.6.4",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/memchr/2.6.4/download",
+ "sha256": "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "memchr",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "memchr",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2021",
+ "version": "2.6.4"
+ },
+ "license": "Unlicense OR MIT"
+ },
+ "miniz_oxide 0.7.1": {
+ "name": "miniz_oxide",
+ "version": "0.7.1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/miniz_oxide/0.7.1/download",
+ "sha256": "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "miniz_oxide",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "miniz_oxide",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "adler 1.0.2",
+ "target": "adler"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.7.1"
+ },
+ "license": "MIT OR Zlib OR Apache-2.0"
+ },
+ "mio 0.8.9": {
+ "name": "mio",
+ "version": "0.8.9",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/mio/0.8.9/download",
+ "sha256": "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "mio",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "mio",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "net",
+ "os-ext",
+ "os-poll"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [],
+ "selects": {
+ "cfg(target_os = \"wasi\")": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ },
+ {
+ "id": "wasi 0.11.0+wasi-snapshot-preview1",
+ "target": "wasi"
+ }
+ ],
+ "cfg(unix)": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ],
+ "cfg(windows)": [
+ {
+ "id": "windows-sys 0.48.0",
+ "target": "windows_sys"
+ }
+ ]
+ }
+ },
+ "edition": "2018",
+ "version": "0.8.9"
+ },
+ "license": "MIT"
+ },
+ "num_cpus 1.16.0": {
+ "name": "num_cpus",
+ "version": "1.16.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/num_cpus/1.16.0/download",
+ "sha256": "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "num_cpus",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "num_cpus",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [],
+ "selects": {
+ "cfg(not(windows))": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ],
+ "cfg(target_os = \"hermit\")": [
+ {
+ "id": "hermit-abi 0.3.3",
+ "target": "hermit_abi"
+ }
+ ]
+ }
+ },
+ "edition": "2015",
+ "version": "1.16.0"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "object 0.32.1": {
+ "name": "object",
+ "version": "0.32.1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/object/0.32.1/download",
+ "sha256": "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "object",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "object",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "memchr 2.6.4",
+ "target": "memchr"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.32.1"
+ },
+ "license": "Apache-2.0 OR MIT"
+ },
+ "parking_lot 0.12.1": {
+ "name": "parking_lot",
+ "version": "0.12.1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/parking_lot/0.12.1/download",
+ "sha256": "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "parking_lot",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "parking_lot",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "lock_api 0.4.11",
+ "target": "lock_api"
+ },
+ {
+ "id": "parking_lot_core 0.9.9",
+ "target": "parking_lot_core"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.12.1"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "parking_lot_core 0.9.9": {
+ "name": "parking_lot_core",
+ "version": "0.9.9",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/parking_lot_core/0.9.9/download",
+ "sha256": "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "parking_lot_core",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "parking_lot_core",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "cfg-if 1.0.0",
+ "target": "cfg_if"
+ },
+ {
+ "id": "smallvec 1.11.2",
+ "target": "smallvec"
+ }
+ ],
+ "selects": {
+ "cfg(target_os = \"redox\")": [
+ {
+ "id": "redox_syscall 0.4.1",
+ "target": "syscall"
+ }
+ ],
+ "cfg(unix)": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ],
+ "cfg(windows)": [
+ {
+ "id": "windows-targets 0.48.5",
+ "target": "windows_targets"
+ }
+ ]
+ }
+ },
+ "edition": "2018",
+ "version": "0.9.9"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "pin-project-lite 0.2.13": {
+ "name": "pin-project-lite",
+ "version": "0.2.13",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/pin-project-lite/0.2.13/download",
+ "sha256": "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "pin_project_lite",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "pin_project_lite",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.2.13"
+ },
+ "license": "Apache-2.0 OR MIT"
+ },
+ "proc-macro2 1.0.69": {
+ "name": "proc-macro2",
+ "version": "1.0.69",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/proc-macro2/1.0.69/download",
+ "sha256": "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "proc_macro2",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "proc_macro2",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "proc-macro"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "unicode-ident 1.0.8",
+ "target": "unicode_ident"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2021",
+ "rustc_flags": [
+ "--cfg=proc_macro_span",
+ "--cfg=span_locations",
+ "--cfg=use_proc_macro",
+ "--cfg=wrap_proc_macro"
+ ],
+ "version": "1.0.69"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "quote 1.0.26": {
+ "name": "quote",
+ "version": "1.0.26",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/quote/1.0.26/download",
+ "sha256": "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "quote",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "quote",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "proc-macro"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "proc-macro2 1.0.69",
+ "target": "proc_macro2"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "1.0.26"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "redox_syscall 0.4.1": {
+ "name": "redox_syscall",
+ "version": "0.4.1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/redox_syscall/0.4.1/download",
+ "sha256": "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "syscall",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "syscall",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "bitflags 1.3.2",
+ "target": "bitflags"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.4.1"
+ },
+ "license": "MIT"
+ },
+ "rustc-demangle 0.1.23": {
+ "name": "rustc-demangle",
+ "version": "0.1.23",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/rustc-demangle/0.1.23/download",
+ "sha256": "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "rustc_demangle",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "rustc_demangle",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2015",
+ "version": "0.1.23"
+ },
+ "license": "MIT/Apache-2.0"
+ },
+ "scopeguard 1.2.0": {
+ "name": "scopeguard",
+ "version": "1.2.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/scopeguard/1.2.0/download",
+ "sha256": "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "scopeguard",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "scopeguard",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2015",
+ "version": "1.2.0"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "signal-hook-registry 1.4.1": {
+ "name": "signal-hook-registry",
+ "version": "1.4.1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/signal-hook-registry/1.4.1/download",
+ "sha256": "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "signal_hook_registry",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "signal_hook_registry",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2015",
+ "version": "1.4.1"
+ },
+ "license": "Apache-2.0/MIT"
+ },
+ "smallvec 1.11.2": {
+ "name": "smallvec",
+ "version": "1.11.2",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/smallvec/1.11.2/download",
+ "sha256": "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "smallvec",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "smallvec",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "1.11.2"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "socket2 0.5.5": {
+ "name": "socket2",
+ "version": "0.5.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/socket2/0.5.5/download",
+ "sha256": "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "socket2",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "socket2",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "all"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [],
+ "selects": {
+ "cfg(unix)": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ }
+ ],
+ "cfg(windows)": [
+ {
+ "id": "windows-sys 0.48.0",
+ "target": "windows_sys"
+ }
+ ]
+ }
+ },
+ "edition": "2021",
+ "version": "0.5.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "syn 2.0.15": {
+ "name": "syn",
+ "version": "2.0.15",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/syn/2.0.15/download",
+ "sha256": "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "syn",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "syn",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "clone-impls",
+ "default",
+ "derive",
+ "extra-traits",
+ "fold",
+ "full",
+ "parsing",
+ "printing",
+ "proc-macro",
+ "quote",
+ "visit",
+ "visit-mut"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "proc-macro2 1.0.69",
+ "target": "proc_macro2"
+ },
+ {
+ "id": "quote 1.0.26",
+ "target": "quote"
+ },
+ {
+ "id": "unicode-ident 1.0.8",
+ "target": "unicode_ident"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2021",
+ "version": "2.0.15"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "tokio 1.34.0": {
+ "name": "tokio",
+ "version": "1.34.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/tokio/1.34.0/download",
+ "sha256": "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "tokio",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "tokio",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "bytes",
+ "default",
+ "fs",
+ "full",
+ "io-std",
+ "io-util",
+ "libc",
+ "macros",
+ "mio",
+ "net",
+ "num_cpus",
+ "parking_lot",
+ "process",
+ "rt",
+ "rt-multi-thread",
+ "signal",
+ "signal-hook-registry",
+ "socket2",
+ "sync",
+ "time",
+ "tokio-macros"
+ ],
+ "selects": {
+ "x86_64-pc-windows-msvc": [
+ "windows-sys"
+ ]
+ }
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "bytes 1.4.0",
+ "target": "bytes"
+ },
+ {
+ "id": "mio 0.8.9",
+ "target": "mio"
+ },
+ {
+ "id": "num_cpus 1.16.0",
+ "target": "num_cpus"
+ },
+ {
+ "id": "parking_lot 0.12.1",
+ "target": "parking_lot"
+ },
+ {
+ "id": "pin-project-lite 0.2.13",
+ "target": "pin_project_lite"
+ }
+ ],
+ "selects": {
+ "cfg(not(target_family = \"wasm\"))": [
+ {
+ "id": "socket2 0.5.5",
+ "target": "socket2"
+ }
+ ],
+ "cfg(tokio_taskdump)": [
+ {
+ "id": "backtrace 0.3.69",
+ "target": "backtrace"
+ }
+ ],
+ "cfg(unix)": [
+ {
+ "id": "libc 0.2.150",
+ "target": "libc"
+ },
+ {
+ "id": "signal-hook-registry 1.4.1",
+ "target": "signal_hook_registry"
+ }
+ ],
+ "cfg(windows)": [
+ {
+ "id": "windows-sys 0.48.0",
+ "target": "windows_sys"
+ }
+ ]
+ }
+ },
+ "edition": "2021",
+ "proc_macro_deps": {
+ "common": [
+ {
+ "id": "tokio-macros 2.2.0",
+ "target": "tokio_macros"
+ }
+ ],
+ "selects": {}
+ },
+ "version": "1.34.0"
+ },
+ "license": "MIT"
+ },
+ "tokio-macros 2.2.0": {
+ "name": "tokio-macros",
+ "version": "2.2.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/tokio-macros/2.2.0/download",
+ "sha256": "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
+ }
+ },
+ "targets": [
+ {
+ "ProcMacro": {
+ "crate_name": "tokio_macros",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "tokio_macros",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [
+ {
+ "id": "proc-macro2 1.0.69",
+ "target": "proc_macro2"
+ },
+ {
+ "id": "quote 1.0.26",
+ "target": "quote"
+ },
+ {
+ "id": "syn 2.0.15",
+ "target": "syn"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2021",
+ "version": "2.2.0"
+ },
+ "license": "MIT"
+ },
+ "unicode-ident 1.0.8": {
+ "name": "unicode-ident",
+ "version": "1.0.8",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/unicode-ident/1.0.8/download",
+ "sha256": "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "unicode_ident",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "unicode_ident",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "1.0.8"
+ },
+ "license": "(MIT OR Apache-2.0) AND Unicode-DFS-2016"
+ },
+ "wasi 0.11.0+wasi-snapshot-preview1": {
+ "name": "wasi",
+ "version": "0.11.0+wasi-snapshot-preview1",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/wasi/0.11.0+wasi-snapshot-preview1/download",
+ "sha256": "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "wasi",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "wasi",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "default",
+ "std"
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.11.0+wasi-snapshot-preview1"
+ },
+ "license": "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
+ },
+ "windows-sys 0.48.0": {
+ "name": "windows-sys",
+ "version": "0.48.0",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows-sys/0.48.0/download",
+ "sha256": "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_sys",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_sys",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "crate_features": {
+ "common": [
+ "Win32",
+ "Win32_Foundation",
+ "Win32_Networking",
+ "Win32_Networking_WinSock",
+ "Win32_Security",
+ "Win32_Storage",
+ "Win32_Storage_FileSystem",
+ "Win32_System",
+ "Win32_System_Console",
+ "Win32_System_IO",
+ "Win32_System_Pipes",
+ "Win32_System_SystemServices",
+ "Win32_System_Threading",
+ "Win32_System_WindowsProgramming",
+ "default"
+ ],
+ "selects": {}
+ },
+ "deps": {
+ "common": [
+ {
+ "id": "windows-targets 0.48.5",
+ "target": "windows_targets"
+ }
+ ],
+ "selects": {}
+ },
+ "edition": "2018",
+ "version": "0.48.0"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows-targets 0.48.5": {
+ "name": "windows-targets",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows-targets/0.48.5/download",
+ "sha256": "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_targets",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_targets",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "deps": {
+ "common": [],
+ "selects": {
+ "aarch64-pc-windows-gnullvm": [
+ {
+ "id": "windows_aarch64_gnullvm 0.48.5",
+ "target": "windows_aarch64_gnullvm"
+ }
+ ],
+ "cfg(all(target_arch = \"aarch64\", target_env = \"msvc\", not(windows_raw_dylib)))": [
+ {
+ "id": "windows_aarch64_msvc 0.48.5",
+ "target": "windows_aarch64_msvc"
+ }
+ ],
+ "cfg(all(target_arch = \"x86\", target_env = \"gnu\", not(windows_raw_dylib)))": [
+ {
+ "id": "windows_i686_gnu 0.48.5",
+ "target": "windows_i686_gnu"
+ }
+ ],
+ "cfg(all(target_arch = \"x86\", target_env = \"msvc\", not(windows_raw_dylib)))": [
+ {
+ "id": "windows_i686_msvc 0.48.5",
+ "target": "windows_i686_msvc"
+ }
+ ],
+ "cfg(all(target_arch = \"x86_64\", target_env = \"gnu\", not(target_abi = \"llvm\"), not(windows_raw_dylib)))": [
+ {
+ "id": "windows_x86_64_gnu 0.48.5",
+ "target": "windows_x86_64_gnu"
+ }
+ ],
+ "cfg(all(target_arch = \"x86_64\", target_env = \"msvc\", not(windows_raw_dylib)))": [
+ {
+ "id": "windows_x86_64_msvc 0.48.5",
+ "target": "windows_x86_64_msvc"
+ }
+ ],
+ "x86_64-pc-windows-gnullvm": [
+ {
+ "id": "windows_x86_64_gnullvm 0.48.5",
+ "target": "windows_x86_64_gnullvm"
+ }
+ ]
+ }
+ },
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_aarch64_gnullvm 0.48.5": {
+ "name": "windows_aarch64_gnullvm",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_aarch64_gnullvm/0.48.5/download",
+ "sha256": "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_aarch64_gnullvm",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_aarch64_gnullvm",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_aarch64_msvc 0.48.5": {
+ "name": "windows_aarch64_msvc",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_aarch64_msvc/0.48.5/download",
+ "sha256": "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_aarch64_msvc",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_aarch64_msvc",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_i686_gnu 0.48.5": {
+ "name": "windows_i686_gnu",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_i686_gnu/0.48.5/download",
+ "sha256": "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_i686_gnu",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_i686_gnu",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_i686_msvc 0.48.5": {
+ "name": "windows_i686_msvc",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_i686_msvc/0.48.5/download",
+ "sha256": "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_i686_msvc",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_i686_msvc",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_x86_64_gnu 0.48.5": {
+ "name": "windows_x86_64_gnu",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_x86_64_gnu/0.48.5/download",
+ "sha256": "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_x86_64_gnu",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_x86_64_gnu",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_x86_64_gnullvm 0.48.5": {
+ "name": "windows_x86_64_gnullvm",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_x86_64_gnullvm/0.48.5/download",
+ "sha256": "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_x86_64_gnullvm",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_x86_64_gnullvm",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ },
+ "windows_x86_64_msvc 0.48.5": {
+ "name": "windows_x86_64_msvc",
+ "version": "0.48.5",
+ "repository": {
+ "Http": {
+ "url": "https://crates.io/api/v1/crates/windows_x86_64_msvc/0.48.5/download",
+ "sha256": "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+ }
+ },
+ "targets": [
+ {
+ "Library": {
+ "crate_name": "windows_x86_64_msvc",
+ "crate_root": "src/lib.rs",
+ "srcs": [
+ "**/*.rs"
+ ]
+ }
+ }
+ ],
+ "library_target_name": "windows_x86_64_msvc",
+ "common_attrs": {
+ "compile_data_glob": [
+ "**"
+ ],
+ "edition": "2018",
+ "version": "0.48.5"
+ },
+ "license": "MIT OR Apache-2.0"
+ }
+ },
+ "binary_crates": [],
+ "workspace_members": {
+ "direct-cargo-bazel-deps 0.0.1": ""
+ },
+ "conditions": {
+ "aarch64-apple-darwin": [
+ "aarch64-apple-darwin"
+ ],
+ "aarch64-apple-ios": [
+ "aarch64-apple-ios"
+ ],
+ "aarch64-linux-android": [
+ "aarch64-linux-android"
+ ],
+ "aarch64-pc-windows-gnullvm": [],
+ "aarch64-unknown-linux-gnu": [
+ "aarch64-unknown-linux-gnu"
+ ],
+ "cfg(all(target_arch = \"aarch64\", target_env = \"msvc\", not(windows_raw_dylib)))": [],
+ "cfg(all(target_arch = \"x86\", target_env = \"gnu\", not(windows_raw_dylib)))": [],
+ "cfg(all(target_arch = \"x86\", target_env = \"msvc\", not(windows_raw_dylib)))": [],
+ "cfg(all(target_arch = \"x86_64\", target_env = \"gnu\", not(target_abi = \"llvm\"), not(windows_raw_dylib)))": [
+ "x86_64-unknown-linux-gnu"
+ ],
+ "cfg(all(target_arch = \"x86_64\", target_env = \"msvc\", not(windows_raw_dylib)))": [
+ "x86_64-pc-windows-msvc"
+ ],
+ "cfg(not(all(windows, target_env = \"msvc\", not(target_vendor = \"uwp\"))))": [
+ "aarch64-apple-darwin",
+ "aarch64-apple-ios",
+ "aarch64-linux-android",
+ "aarch64-unknown-linux-gnu",
+ "wasm32-unknown-unknown",
+ "wasm32-wasi",
+ "x86_64-apple-darwin",
+ "x86_64-unknown-linux-gnu"
+ ],
+ "cfg(not(target_family = \"wasm\"))": [
+ "aarch64-apple-darwin",
+ "aarch64-apple-ios",
+ "aarch64-linux-android",
+ "aarch64-unknown-linux-gnu",
+ "x86_64-apple-darwin",
+ "x86_64-pc-windows-msvc",
+ "x86_64-unknown-linux-gnu"
+ ],
+ "cfg(not(windows))": [
+ "aarch64-apple-darwin",
+ "aarch64-apple-ios",
+ "aarch64-linux-android",
+ "aarch64-unknown-linux-gnu",
+ "wasm32-unknown-unknown",
+ "wasm32-wasi",
+ "x86_64-apple-darwin",
+ "x86_64-unknown-linux-gnu"
+ ],
+ "cfg(target_os = \"hermit\")": [],
+ "cfg(target_os = \"redox\")": [],
+ "cfg(target_os = \"wasi\")": [
+ "wasm32-wasi"
+ ],
+ "cfg(tokio_taskdump)": [],
+ "cfg(unix)": [
+ "aarch64-apple-darwin",
+ "aarch64-apple-ios",
+ "aarch64-linux-android",
+ "aarch64-unknown-linux-gnu",
+ "x86_64-apple-darwin",
+ "x86_64-unknown-linux-gnu"
+ ],
+ "cfg(windows)": [
+ "x86_64-pc-windows-msvc"
+ ],
+ "wasm32-unknown-unknown": [
+ "wasm32-unknown-unknown"
+ ],
+ "wasm32-wasi": [
+ "wasm32-wasi"
+ ],
+ "x86_64-apple-darwin": [
+ "x86_64-apple-darwin"
+ ],
+ "x86_64-pc-windows-gnullvm": [],
+ "x86_64-pc-windows-msvc": [
+ "x86_64-pc-windows-msvc"
+ ],
+ "x86_64-unknown-linux-gnu": [
+ "x86_64-unknown-linux-gnu"
+ ]
+ },
+ "direct_deps": [
+ "anyhow 1.0.75",
+ "tokio 1.34.0"
+ ],
+ "direct_dev_deps": []
+}
diff --git a/examples/nix_cross_compiling/bazel/cargo/crates/BUILD.bazel b/examples/nix_cross_compiling/bazel/cargo/crates/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/bazel/cargo/crates/libc.bzl b/examples/nix_cross_compiling/bazel/cargo/crates/libc.bzl
new file mode 100644
index 000000000..2d4f45cb0
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/crates/libc.bzl
@@ -0,0 +1,22 @@
+""" Crate Annotation for libc """
+
+load("@rules_rust//crate_universe:defs.bzl", "crate")
+
+ANNOTATION = crate.annotation(
+ rustc_flags = [
+ "--cfg=freebsd11",
+ "--cfg=libc_priv_mod_use",
+ "--cfg=libc_union",
+ "--cfg=libc_const_size_of",
+ "--cfg=libc_align",
+ "--cfg=libc_int128",
+ "--cfg=libc_core_cvoid",
+ "--cfg=libc_packedN",
+ "--cfg=libc_cfg_target_vendor",
+ "--cfg=libc_non_exhaustive",
+ "--cfg=libc_long_array",
+ "--cfg=libc_ptr_addr_of",
+ "--cfg=libc_underscore_const_names",
+ "--cfg=libc_const_extern_fn",
+ ],
+)
diff --git a/examples/nix_cross_compiling/bazel/cargo/crates/proc_macro2.bzl b/examples/nix_cross_compiling/bazel/cargo/crates/proc_macro2.bzl
new file mode 100644
index 000000000..3810d5493
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/crates/proc_macro2.bzl
@@ -0,0 +1,12 @@
+""" Crate Annotation for proc-macro2 """
+
+load("@rules_rust//crate_universe:defs.bzl", "crate")
+
+ANNOTATION = crate.annotation(
+ rustc_flags = [
+ "--cfg=proc_macro_span",
+ "--cfg=span_locations",
+ "--cfg=use_proc_macro",
+ "--cfg=wrap_proc_macro",
+ ],
+)
diff --git a/examples/nix_cross_compiling/bazel/cargo/crates/syn.bzl b/examples/nix_cross_compiling/bazel/cargo/crates/syn.bzl
new file mode 100644
index 000000000..4d33f436a
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/crates/syn.bzl
@@ -0,0 +1,18 @@
+""" Crate Annotation for syn """
+
+load("@rules_rust//crate_universe:defs.bzl", "crate")
+
+ANNOTATION = crate.annotation(
+ crate_features = [
+ "clone-impls",
+ "derive",
+ "extra-traits",
+ "fold",
+ "full",
+ "parsing",
+ "printing",
+ "proc-macro",
+ "visit-mut",
+ "visit",
+ ],
+)
diff --git a/examples/nix_cross_compiling/bazel/cargo/crates_repository.bzl b/examples/nix_cross_compiling/bazel/cargo/crates_repository.bzl
new file mode 100644
index 000000000..4784624e4
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/crates_repository.bzl
@@ -0,0 +1,24 @@
+""" Crate Universe Packages and Annotations """
+
+load("@rules_rust//crate_universe:defs.bzl", "crate")
+load("//bazel/cargo/crates:libc.bzl", libc = "ANNOTATION")
+load("//bazel/cargo/crates:proc_macro2.bzl", proc_macro2 = "ANNOTATION")
+load("//bazel/cargo/crates:syn.bzl", syn = "ANNOTATION")
+
+PACKAGES = {
+ "anyhow": crate.spec(
+ version = "1.0.75",
+ ),
+ "tokio": crate.spec(
+ version = "1.34.0",
+ features = [
+ "full",
+ ],
+ ),
+}
+
+ANNOTATIONS = {
+ "libc": [libc],
+ "proc-macro2": [proc_macro2],
+ "syn": [syn],
+}
diff --git a/examples/nix_cross_compiling/bazel/cargo/platforms/BUILD.bazel b/examples/nix_cross_compiling/bazel/cargo/platforms/BUILD.bazel
new file mode 100644
index 000000000..0fff2254c
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/cargo/platforms/BUILD.bazel
@@ -0,0 +1,109 @@
+load("@bazel_skylib//lib:selects.bzl", "selects")
+
+config_setting(
+ name = "aarch64-apple-darwin",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:macos",
+ ],
+)
+
+config_setting(
+ name = "aarch64-apple-ios",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:ios",
+ ],
+)
+
+config_setting(
+ name = "aarch64-linux-android",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:android",
+ ],
+)
+
+# This seems like the best way for the Cargo generated dependencies to be
+# aware of `aarch64-unknown-nixos-gnu`.
+selects.config_setting_group(
+ name = "aarch64-unknown-linux-gnu",
+ match_any = [
+ ":aarch64-unknown-linux-gnu_linux",
+ ":aarch64-unknown-linux-gnu_nixos",
+ ],
+)
+
+config_setting(
+ name = "aarch64-unknown-linux-gnu_linux",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:linux",
+ ],
+)
+
+config_setting(
+ name = "aarch64-unknown-linux-gnu_nixos",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:nixos",
+ ],
+)
+
+config_setting(
+ name = "wasm32-unknown-unknown",
+ constraint_values = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:none",
+ ],
+)
+
+config_setting(
+ name = "wasm32-wasi",
+ constraint_values = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:wasi",
+ ],
+)
+
+config_setting(
+ name = "x86_64-apple-darwin",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:macos",
+ ],
+)
+
+config_setting(
+ name = "x86_64-pc-windows-msvc",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:windows",
+ ],
+)
+
+# This seems like the best way for the Cargo generated dependencies to be
+# aware of `x86_64-unknown-nixos-gnu`.
+selects.config_setting_group(
+ name = "x86_64-unknown-linux-gnu",
+ match_any = [
+ ":x86_64-unknown-linux-gnu_linux",
+ ":x86_64-unknown-linux-gnu_nixos",
+ ],
+)
+
+config_setting(
+ name = "x86_64-unknown-linux-gnu_linux",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ ],
+)
+
+config_setting(
+ name = "x86_64-unknown-linux-gnu_nixos",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+)
diff --git a/examples/nix_cross_compiling/bazel/nix_repositories.bzl b/examples/nix_cross_compiling/bazel/nix_repositories.bzl
new file mode 100644
index 000000000..bb5e2f98a
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/nix_repositories.bzl
@@ -0,0 +1,233 @@
+""" Nix Repositories """
+
+load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_flake_package")
+
+_CONFIG_BUILD_FILE_CONTENT = """
+package(default_visibility = ["//visibility:public"])
+
+exports_files(["config.bzl"])
+"""
+
+_RUST_BUILD_FILE_CONTENT = """
+load("@rules_rust//rust:toolchain.bzl", "rust_stdlib_filegroup")
+
+package(default_visibility = ["//visibility:public"])
+
+# https://github.com/tweag/rules_nixpkgs/blob/master/toolchains/rust/rust.bzl#L33-L116
+filegroup(
+ name = "rustc",
+ srcs = ["bin/rustc"],
+)
+
+filegroup(
+ name = "rustdoc",
+ srcs = ["bin/rustdoc"],
+)
+
+filegroup(
+ name = "rustfmt",
+ srcs = ["bin/rustfmt"],
+)
+
+filegroup(
+ name = "cargo",
+ srcs = ["bin/cargo"],
+)
+
+filegroup(
+ name = "clippy_driver",
+ srcs = ["bin/clippy-driver"],
+)
+
+filegroup(
+ name = "proc_macro_srv",
+ srcs = ["libexec/rust-analyzer-proc-macro-srv"],
+)
+
+filegroup(
+ name = "rustc_lib",
+ srcs = glob(
+ [
+ "bin/*.so",
+ "lib/*.so",
+ "lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/*.so",
+ "lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/*.dylib",
+ "lib/rustlib/x86_64-unknown-linux-gnu/bin/*",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.dylib",
+ ],
+ allow_empty = True,
+ ),
+)
+
+filegroup(
+ name = "rust-src",
+ srcs = glob(["lib/rustlib/src/**/*"]),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-aarch64-apple-darwin",
+ srcs = glob(
+ [
+ "lib/rustlib/aarch64-apple-darwin/lib/*.rlib",
+ "lib/rustlib/aarch64-apple-darwin/lib/*.so",
+ "lib/rustlib/aarch64-apple-darwin/lib/*.dylib",
+ "lib/rustlib/aarch64-apple-darwin/lib/*.a",
+ "lib/rustlib/aarch64-apple-darwin/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-aarch64-apple-ios",
+ srcs = glob(
+ [
+ "lib/rustlib/aarch64-apple-ios/lib/*.rlib",
+ "lib/rustlib/aarch64-apple-ios/lib/*.so",
+ "lib/rustlib/aarch64-apple-ios/lib/*.dylib",
+ "lib/rustlib/aarch64-apple-ios/lib/*.a",
+ "lib/rustlib/aarch64-apple-ios/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-aarch64-linux-android",
+ srcs = glob(
+ [
+ "lib/rustlib/aarch64-linux-android/lib/*.rlib",
+ "lib/rustlib/aarch64-linux-android/lib/*.so",
+ "lib/rustlib/aarch64-linux-android/lib/*.dylib",
+ "lib/rustlib/aarch64-linux-android/lib/*.a",
+ "lib/rustlib/aarch64-linux-android/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-aarch64-unknown-linux-gnu",
+ srcs = glob(
+ [
+ "lib/rustlib/aarch64-unknown-linux-gnu/lib/*.rlib",
+ "lib/rustlib/aarch64-unknown-linux-gnu/lib/*.so",
+ "lib/rustlib/aarch64-unknown-linux-gnu/lib/*.dylib",
+ "lib/rustlib/aarch64-unknown-linux-gnu/lib/*.a",
+ "lib/rustlib/aarch64-unknown-linux-gnu/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-wasm32-unknown-unknown",
+ srcs = glob(
+ [
+ "lib/rustlib/wasm32-unknown-unknown/lib/*.rlib",
+ "lib/rustlib/wasm32-unknown-unknown/lib/*.so",
+ "lib/rustlib/wasm32-unknown-unknown/lib/*.dylib",
+ "lib/rustlib/wasm32-unknown-unknown/lib/*.a",
+ "lib/rustlib/wasm32-unknown-unknown/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-wasm32-wasi",
+ srcs = glob(
+ [
+ "lib/rustlib/wasm32-wasi/lib/*.rlib",
+ "lib/rustlib/wasm32-wasi/lib/*.so",
+ "lib/rustlib/wasm32-wasi/lib/*.dylib",
+ "lib/rustlib/wasm32-wasi/lib/*.a",
+ "lib/rustlib/wasm32-wasi/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-x86_64-apple-darwin",
+ srcs = glob(
+ [
+ "lib/rustlib/x86_64-apple-darwin/lib/*.rlib",
+ "lib/rustlib/x86_64-apple-darwin/lib/*.so",
+ "lib/rustlib/x86_64-apple-darwin/lib/*.dylib",
+ "lib/rustlib/x86_64-apple-darwin/lib/*.a",
+ "lib/rustlib/x86_64-apple-darwin/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-x86_64-pc-windows-msvc",
+ srcs = glob(
+ [
+ "lib/rustlib/x86_64-pc-windows-msvc/lib/*.rlib",
+ "lib/rustlib/x86_64-pc-windows-msvc/lib/*.so",
+ "lib/rustlib/x86_64-pc-windows-msvc/lib/*.dylib",
+ "lib/rustlib/x86_64-pc-windows-msvc/lib/*.a",
+ "lib/rustlib/x86_64-pc-windows-msvc/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+
+rust_stdlib_filegroup(
+ name = "rust_std-x86_64-unknown-linux-gnu",
+ srcs = glob(
+ [
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.rlib",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.so",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.dylib",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/*.a",
+ "lib/rustlib/x86_64-unknown-linux-gnu/lib/self-contained/**",
+ ],
+ # Some patterns (e.g. `lib/*.a`) don't match anything, see https://github.com/bazelbuild/rules_rust/pull/245
+ allow_empty = True,
+ ),
+)
+"""
+
+_CARGO_BAZEL_BUILD_FILE_CONTENT = """
+package(default_visibility = ["//visibility:public"])
+
+exports_files(["bin/cargo-bazel"])
+"""
+
+def nix_repositories():
+ nixpkgs_flake_package(
+ name = "nix_config",
+ nix_flake_file = "//nix:flake.nix",
+ nix_flake_lock_file = "//nix:flake.lock",
+ package = "bazel.config",
+ build_file_content = _CONFIG_BUILD_FILE_CONTENT,
+ )
+
+ nixpkgs_flake_package(
+ name = "nix_rust",
+ nix_flake_file = "//nix:flake.nix",
+ nix_flake_lock_file = "//nix:flake.lock",
+ package = "bazel.rust",
+ build_file_content = _RUST_BUILD_FILE_CONTENT,
+ )
+
+ nixpkgs_flake_package(
+ name = "cargo-bazel",
+ nix_flake_file = "@rules_rust//crate_universe:flake.nix",
+ nix_flake_lock_file = "@rules_rust//crate_universe:flake.lock",
+ package = "cargo-bazel",
+ build_file_content = _CARGO_BAZEL_BUILD_FILE_CONTENT,
+ )
diff --git a/examples/nix_cross_compiling/bazel/platforms/BUILD.bazel b/examples/nix_cross_compiling/bazel/platforms/BUILD.bazel
new file mode 100644
index 000000000..55f7faca1
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/platforms/BUILD.bazel
@@ -0,0 +1,104 @@
+package(default_visibility = ["//visibility:public"])
+
+# Host
+platform(
+ name = "host",
+ constraint_values = ["@platforms//os:nixos"],
+ parents = ["@local_config_platform//:host"],
+)
+
+# Platforms
+platform(
+ name = "aarch64-apple-darwin",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:macos",
+ ],
+)
+
+platform(
+ name = "aarch64-apple-ios",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:ios",
+ ],
+)
+
+platform(
+ name = "aarch64-linux-android",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:android",
+ ],
+)
+
+platform(
+ name = "aarch64-unknown-linux-gnu",
+ constraint_values = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:linux",
+ ],
+)
+
+platform(
+ name = "wasm32-unknown-unknown",
+ constraint_values = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:none",
+ ],
+)
+
+platform(
+ name = "wasm32-wasi",
+ constraint_values = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:wasi",
+ ],
+)
+
+platform(
+ name = "x86_64-apple-darwin",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:macos",
+ ],
+)
+
+platform(
+ name = "x86_64-pc-windows-msvc",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:windows",
+ ],
+)
+
+platform(
+ name = "x86_64-unknown-linux-gnu",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ ],
+)
+
+platform(
+ name = "x86_64-unknown-nixos-gnu",
+ constraint_values = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+)
+
+# Sentinel to catch implicit target platform usage
+platform(
+ name = "missing",
+ constraint_values = [
+ ":missing_constraint_value",
+ ],
+)
+
+constraint_setting(name = "missing_constraint_setting")
+
+constraint_value(
+ name = "missing_constraint_value",
+ constraint_setting = ":missing_constraint_setting",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchain_rules/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/clang.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/clang.bzl
new file mode 100644
index 000000000..f55d2ca62
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/clang.bzl
@@ -0,0 +1,210 @@
+""" CC Compile ActionConfigs for clang """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "with_feature_set",
+)
+
+BAZEL_COMPILE_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-MD", "-MF", "%{dependency_file}"],
+ expand_if_available = "dependency_file",
+ ),
+ flag_group(
+ flags = ["-frandom-seed=%{output_file}"],
+ expand_if_available = "output_file",
+ ),
+ flag_group(
+ flags = ["-D%{preprocessor_defines}"],
+ iterate_over = "preprocessor_defines",
+ ),
+ flag_group(
+ flags = ["-include", "%{includes}"],
+ iterate_over = "includes",
+ expand_if_available = "includes",
+ ),
+ flag_group(
+ flags = ["-iquote", "%{quote_include_paths}"],
+ iterate_over = "quote_include_paths",
+ ),
+ flag_group(
+ flags = ["-I%{include_paths}"],
+ iterate_over = "include_paths",
+ ),
+ flag_group(
+ flags = ["-isystem", "%{system_include_paths}"],
+ iterate_over = "system_include_paths",
+ ),
+ flag_group(
+ flags = ["-isystem", "%{external_include_paths}"],
+ iterate_over = "external_include_paths",
+ expand_if_available = "external_include_paths",
+ ),
+ flag_group(
+ flags = ["%{user_compile_flags}"],
+ iterate_over = "user_compile_flags",
+ expand_if_available = "user_compile_flags",
+ ),
+ flag_group(
+ flags = ["-c", "%{source_file}"],
+ expand_if_available = "source_file",
+ ),
+ flag_group(
+ flags = ["-o", "%{output_file}"],
+ expand_if_available = "output_file",
+ ),
+ ],
+)
+
+def compile_action_configs(
+ clang,
+ target,
+ builtin_include_directories,
+ builtin_framework_directories,
+ compile_flags,
+ dbg_compile_flags,
+ fastbuild_compile_flags,
+ opt_compile_flags,
+ remap_path_prefix):
+ """
+ Generates CC Compile ActionConfigs
+
+ Args:
+ clang (string): Path to clang binaries.
+ target (string): Target triple to pass to the compiler.
+ builtin_include_directories (List): List of include directories to always be passed to the compiler as system includes.
+ builtin_framework_directories (List): List of Apple framework include directories to always be passed to the compiler.
+ compile_flags (List): List of flags to always be passed to the compiler.
+ dbg_compile_flags (List): List of additional flags to always be passed to the compiler in dbg configuration.
+ fastbuild_compile_flags (List): List of additional flags to always be passed to the compiler in fastbuild configuration.
+ opt_compile_flags (List): List of additional flags to always be passed to the compiler in opt configuration.
+ remap_path_prefix (string): Path to be passed to the compiler's remap path prefix flag.
+
+ Returns:
+ List of CC Compile ActionConfigs
+ """
+
+ builtin_include_directory_compile_flags = []
+ for builtin_include_directory in builtin_include_directories:
+ builtin_include_directory_compile_flags.append("-isystem")
+ builtin_include_directory_compile_flags.append(builtin_include_directory)
+
+ builtin_framework_directory_compile_flags = []
+ for builtin_framework_directory in builtin_framework_directories:
+ builtin_framework_directory_compile_flags.append("-iframework")
+ builtin_framework_directory_compile_flags.append(builtin_framework_directory)
+
+ required_compile_flags = ([
+ "--target={}".format(target),
+ "-nostdinc",
+
+ # `unix_cc_toolchain_config`
+ "-Wno-builtin-macro-redefined",
+ "-D__DATE__=\"redacted\"",
+ "-D__TIMESTAMP__=\"redacted\"",
+ "-D__TIME__=\"redacted\"",
+ "-fdebug-prefix-map=${{pwd}}={}".format(remap_path_prefix),
+ ] +
+ builtin_include_directory_compile_flags +
+ builtin_framework_directory_compile_flags)
+ required_compile_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_compile_flags),
+ ] if required_compile_flags else []),
+ )
+
+ compile_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = compile_flags),
+ ] if compile_flags else []),
+ )
+
+ dbg_compile_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = dbg_compile_flags),
+ ] if dbg_compile_flags else []),
+ with_features = [with_feature_set(features = ["dbg"])],
+ )
+
+ fastbuild_compile_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = fastbuild_compile_flags),
+ ] if fastbuild_compile_flags else []),
+ with_features = [with_feature_set(features = ["fastbuild"])],
+ )
+
+ opt_compile_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = opt_compile_flags),
+ ] if opt_compile_flags else []),
+ with_features = [with_feature_set(features = ["opt"])],
+ )
+
+ return [
+ action_config(
+ action_name = ACTION_NAMES.assemble,
+ tools = [tool(path = "{}/bin/clang".format(clang))],
+ flag_sets = [
+ required_compile_flag_set,
+ compile_flag_set,
+ dbg_compile_flag_set,
+ fastbuild_compile_flag_set,
+ opt_compile_flag_set,
+ BAZEL_COMPILE_FLAG_SET,
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.preprocess_assemble,
+ tools = [tool(path = "{}/bin/clang".format(clang))],
+ flag_sets = [
+ required_compile_flag_set,
+ compile_flag_set,
+ dbg_compile_flag_set,
+ fastbuild_compile_flag_set,
+ opt_compile_flag_set,
+ BAZEL_COMPILE_FLAG_SET,
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.c_compile,
+ tools = [tool(path = "{}/bin/clang".format(clang))],
+ flag_sets = [
+ required_compile_flag_set,
+ compile_flag_set,
+ dbg_compile_flag_set,
+ fastbuild_compile_flag_set,
+ opt_compile_flag_set,
+ BAZEL_COMPILE_FLAG_SET,
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_compile,
+ tools = [tool(path = "{}/bin/clang".format(clang))],
+ flag_sets = [
+ required_compile_flag_set,
+ compile_flag_set,
+ dbg_compile_flag_set,
+ fastbuild_compile_flag_set,
+ opt_compile_flag_set,
+ BAZEL_COMPILE_FLAG_SET,
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_header_parsing,
+ tools = [tool(path = "{}/bin/clang".format(clang))],
+ flag_sets = [
+ required_compile_flag_set,
+ compile_flag_set,
+ dbg_compile_flag_set,
+ fastbuild_compile_flag_set,
+ opt_compile_flag_set,
+ BAZEL_COMPILE_FLAG_SET,
+ ],
+ ),
+ ]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld.lld.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld.lld.bzl
new file mode 100644
index 000000000..183462d72
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld.lld.bzl
@@ -0,0 +1,307 @@
+""" CC Link ActionConfigs for ld.lld """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "variable_with_value",
+ "with_feature_set",
+)
+
+BAZEL_LINK_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["%{linkstamp_paths}"],
+ iterate_over = "linkstamp_paths",
+ expand_if_available = "linkstamp_paths",
+ ),
+ flag_group(
+ iterate_over = "runtime_library_search_directories",
+ flag_groups = [
+ flag_group(
+ flags = [
+ "-Xlinker",
+ "-rpath",
+ "-Xlinker",
+ "$ORIGIN/%{runtime_library_search_directories}",
+ ],
+ ),
+ ],
+ expand_if_available =
+ "runtime_library_search_directories",
+ ),
+ flag_group(
+ flags = ["-L%{library_search_directories}"],
+ iterate_over = "library_search_directories",
+ expand_if_available = "library_search_directories",
+ ),
+ flag_group(
+ iterate_over = "libraries_to_link",
+ flag_groups = [
+ flag_group(
+ flags = ["--start-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["-whole-archive"],
+ expand_if_true =
+ "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.object_files}"],
+ iterate_over = "libraries_to_link.object_files",
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "interface_library",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "static_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l:%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "versioned_dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-no-whole-archive"],
+ expand_if_true = "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["--end-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ ],
+ expand_if_available = "libraries_to_link",
+ ),
+ flag_group(
+ flags = ["@%{thinlto_param_file}"],
+ expand_if_true = "thinlto_param_file",
+ ),
+ flag_group(
+ flags = ["%{user_link_flags}"],
+ iterate_over = "user_link_flags",
+ expand_if_available = "user_link_flags",
+ ),
+ flag_group(
+ flags = ["-o", "%{output_execpath}"],
+ expand_if_available = "output_execpath",
+ ),
+ ],
+)
+
+def link_action_configs(
+ llvm,
+ builtin_library_directories,
+ builtin_libraries,
+ builtin_framework_directories,
+ builtin_frameworks,
+ builtin_executable_objects,
+ link_flags,
+ dbg_link_flags,
+ fastbuild_link_flags,
+ opt_link_flags):
+ """
+ Generates CC Link ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+ builtin_library_directories (List): List of library directories to always be passed to the linker.
+ builtin_libraries (List): List of libraries to always be passed to the linker.
+ builtin_framework_directories (List): List of Apple framework directories to always be passed to the linker.
+ builtin_frameworks (List): List of Apple frameworks to always be passed to the linker.
+ builtin_executable_objects (List): List of object files to always be passed to the linker.
+ link_flags (List): List of flags to always be passed to the linker.
+ dbg_link_flags (List): List of additional flags to always be passed to the linker in dbg configuration.
+ fastbuild_link_flags (List): List of additional flags to always be passed to the linker in fastbuild configuration.
+ opt_link_flags (List): List of additional flags to always be passed to the linker in opt configuration.
+
+ Returns:
+ List of CC Link ActionConfigs
+ """
+
+ builtin_library_directory_link_flags = []
+ for builtin_library_directory in builtin_library_directories:
+ builtin_library_directory_link_flags.append("-L")
+ builtin_library_directory_link_flags.append(builtin_library_directory)
+
+ builtin_library_link_flags = []
+ for builtin_library in builtin_libraries:
+ builtin_library_link_flags.append("-l{}".format(builtin_library))
+
+ if builtin_framework_directories:
+ fail("Frameworks not supported by `ld.lld`")
+
+ if builtin_frameworks:
+ fail("Frameworks not supported by `ld.lld`")
+
+ builtin_executable_objects_link_flags = []
+ for builtin_executable_object in builtin_executable_objects:
+ builtin_executable_objects_link_flags.append("-l{}".format(builtin_executable_object))
+
+ required_link_flags = (["-nostdlib"] +
+ builtin_library_directory_link_flags +
+ builtin_library_link_flags)
+ required_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_link_flags),
+ ] if required_link_flags else []),
+ )
+
+ required_executable_link_flags = (builtin_executable_objects_link_flags)
+ required_executable_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_executable_link_flags),
+ ] if required_executable_link_flags else []),
+ )
+
+ link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = link_flags),
+ ] if link_flags else []),
+ )
+
+ dbg_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = dbg_link_flags),
+ ] if dbg_link_flags else []),
+ with_features = [with_feature_set(features = ["dbg"])],
+ )
+
+ fastbuild_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = fastbuild_link_flags),
+ ] if fastbuild_link_flags else []),
+ with_features = [with_feature_set(features = ["fastbuild"])],
+ )
+
+ opt_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = opt_link_flags),
+ ] if opt_link_flags else []),
+ with_features = [with_feature_set(features = ["opt"])],
+ )
+
+ return [
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_dynamic_library,
+ tools = [tool(path = "{}/bin/ld.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-shared"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+ tools = [tool(path = "{}/bin/ld.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-shared"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_executable,
+ tools = [tool(path = "{}/bin/ld.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ required_executable_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-pie"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ ]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld64.lld.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld64.lld.bzl
new file mode 100644
index 000000000..96131e9b0
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/ld64.lld.bzl
@@ -0,0 +1,305 @@
+""" CC Link ActionConfigs for ld64.lld """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "variable_with_value",
+ "with_feature_set",
+)
+
+BAZEL_LINK_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["%{linkstamp_paths}"],
+ iterate_over = "linkstamp_paths",
+ expand_if_available = "linkstamp_paths",
+ ),
+ flag_group(
+ iterate_over = "runtime_library_search_directories",
+ flag_groups = [
+ flag_group(
+ flags = [
+ "-Xlinker",
+ "-rpath",
+ "-Xlinker",
+ "$ORIGIN/%{runtime_library_search_directories}",
+ ],
+ ),
+ ],
+ expand_if_available =
+ "runtime_library_search_directories",
+ ),
+ flag_group(
+ flags = ["-L%{library_search_directories}"],
+ iterate_over = "library_search_directories",
+ expand_if_available = "library_search_directories",
+ ),
+ flag_group(
+ iterate_over = "libraries_to_link",
+ flag_groups = [
+ flag_group(
+ flags = ["--start-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["-whole-archive"],
+ expand_if_true =
+ "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.object_files}"],
+ iterate_over = "libraries_to_link.object_files",
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "interface_library",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "static_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l:%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "versioned_dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-no-whole-archive"],
+ expand_if_true = "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["--end-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ ],
+ expand_if_available = "libraries_to_link",
+ ),
+ flag_group(
+ flags = ["@%{thinlto_param_file}"],
+ expand_if_true = "thinlto_param_file",
+ ),
+ flag_group(
+ flags = ["%{user_link_flags}"],
+ iterate_over = "user_link_flags",
+ expand_if_available = "user_link_flags",
+ ),
+ flag_group(
+ flags = ["-o", "%{output_execpath}"],
+ expand_if_available = "output_execpath",
+ ),
+ ],
+)
+
+def link_action_configs(
+ llvm,
+ builtin_library_directories,
+ builtin_libraries,
+ builtin_framework_directories,
+ builtin_frameworks,
+ builtin_executable_objects,
+ link_flags,
+ dbg_link_flags,
+ fastbuild_link_flags,
+ opt_link_flags):
+ """
+ Generates CC Link ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+ builtin_library_directories (List): List of library directories to always be passed to the linker.
+ builtin_libraries (List): List of libraries to always be passed to the linker.
+ builtin_framework_directories (List): List of Apple framework directories to always be passed to the linker.
+ builtin_frameworks (List): List of Apple frameworks to always be passed to the linker.
+ builtin_executable_objects (List): List of object files to always be passed to the linker.
+ link_flags (List): List of flags to always be passed to the linker.
+ dbg_link_flags (List): List of additional flags to always be passed to the linker in dbg configuration.
+ fastbuild_link_flags (List): List of additional flags to always be passed to the linker in fastbuild configuration.
+ opt_link_flags (List): List of additional flags to always be passed to the linker in opt configuration.
+
+ Returns:
+ List of CC Link ActionConfigs
+ """
+
+ builtin_library_directory_link_flags = []
+ for builtin_library_directory in builtin_library_directories:
+ builtin_library_directory_link_flags.append("-L")
+ builtin_library_directory_link_flags.append(builtin_library_directory)
+
+ builtin_library_link_flags = []
+ for builtin_library in builtin_libraries:
+ builtin_library_link_flags.append("-l{}".format(builtin_library))
+
+ builtin_framework_directory_link_flags = []
+ for builtin_framework_directory in builtin_framework_directories:
+ builtin_framework_directory_link_flags.append("-F")
+ builtin_framework_directory_link_flags.append(builtin_framework_directory)
+
+ builtin_framework_link_flags = []
+ for builtin_framework in builtin_frameworks:
+ builtin_framework_link_flags.append("-framework")
+ builtin_framework_link_flags.append(builtin_framework)
+
+ builtin_executable_objects_link_flags = []
+ for builtin_executable_object in builtin_executable_objects:
+ builtin_executable_objects_link_flags.append("-l{}".format(builtin_executable_object))
+
+ required_link_flags = (builtin_library_directory_link_flags +
+ builtin_library_link_flags +
+ builtin_framework_directory_link_flags +
+ builtin_framework_link_flags)
+ required_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_link_flags),
+ ] if required_link_flags else []),
+ )
+
+ required_executable_link_flags = (builtin_executable_objects_link_flags)
+ required_executable_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_executable_link_flags),
+ ] if required_executable_link_flags else []),
+ )
+
+ link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = link_flags),
+ ] if link_flags else []),
+ )
+
+ dbg_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = dbg_link_flags),
+ ] if dbg_link_flags else []),
+ with_features = [with_feature_set(features = ["dbg"])],
+ )
+
+ fastbuild_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = fastbuild_link_flags),
+ ] if fastbuild_link_flags else []),
+ with_features = [with_feature_set(features = ["fastbuild"])],
+ )
+
+ opt_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = opt_link_flags),
+ ] if opt_link_flags else []),
+ with_features = [with_feature_set(features = ["opt"])],
+ )
+
+ return [
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_dynamic_library,
+ tools = [tool(path = "{}/bin/ld64.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-dylib"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+ tools = [tool(path = "{}/bin/ld64.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-dylib"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_executable,
+ tools = [tool(path = "{}/bin/ld64.lld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ required_executable_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ ],
+ ),
+ ]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/lld_link.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/lld_link.bzl
new file mode 100644
index 000000000..b6f5acc3d
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/lld_link.bzl
@@ -0,0 +1,299 @@
+""" CC Link ActionConfigs for lld-link """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "variable_with_value",
+ "with_feature_set",
+)
+
+BAZEL_LINK_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["%{linkstamp_paths}"],
+ iterate_over = "linkstamp_paths",
+ expand_if_available = "linkstamp_paths",
+ ),
+ flag_group(
+ iterate_over = "runtime_library_search_directories",
+ flag_groups = [
+ flag_group(
+ flags = [
+ "-Xlinker",
+ "-rpath",
+ "-Xlinker",
+ "$ORIGIN/%{runtime_library_search_directories}",
+ ],
+ ),
+ ],
+ expand_if_available =
+ "runtime_library_search_directories",
+ ),
+ flag_group(
+ flags = ["/libpath:%{library_search_directories}"],
+ iterate_over = "library_search_directories",
+ expand_if_available = "library_search_directories",
+ ),
+ flag_group(
+ iterate_over = "libraries_to_link",
+ flag_groups = [
+ flag_group(
+ flags = ["/start-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.object_files}"],
+ iterate_over = "libraries_to_link.object_files",
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "interface_library",
+ ),
+ ),
+ flag_group(
+ flag_groups = [
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_false = "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["/wholearchive:%{libraries_to_link.name}"],
+ expand_if_true = "libraries_to_link.is_whole_archive",
+ ),
+ ],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "static_library",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "versioned_dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["/end-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ ],
+ expand_if_available = "libraries_to_link",
+ ),
+ flag_group(
+ flags = ["@%{thinlto_param_file}"],
+ expand_if_true = "thinlto_param_file",
+ ),
+ flag_group(
+ flags = ["%{user_link_flags}"],
+ iterate_over = "user_link_flags",
+ expand_if_available = "user_link_flags",
+ ),
+ flag_group(
+ flags = ["/out:%{output_execpath}"],
+ expand_if_available = "output_execpath",
+ ),
+ ],
+)
+
+def link_action_configs(
+ llvm,
+ builtin_executable_objects,
+ builtin_library_directories,
+ builtin_libraries,
+ builtin_framework_directories,
+ builtin_frameworks,
+ link_flags,
+ dbg_link_flags,
+ fastbuild_link_flags,
+ opt_link_flags):
+ """
+ Generates CC Link ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+ builtin_library_directories (List): List of library directories to always be passed to the linker.
+ builtin_libraries (List): List of libraries to always be passed to the linker.
+ builtin_framework_directories (List): List of Apple framework directories to always be passed to the linker.
+ builtin_frameworks (List): List of Apple frameworks to always be passed to the linker.
+ builtin_executable_objects (List): List of object files to always be passed to the linker.
+ link_flags (List): List of flags to always be passed to the linker.
+ dbg_link_flags (List): List of additional flags to always be passed to the linker in dbg configuration.
+ fastbuild_link_flags (List): List of additional flags to always be passed to the linker in fastbuild configuration.
+ opt_link_flags (List): List of additional flags to always be passed to the linker in opt configuration.
+
+ Returns:
+ List of CC Link ActionConfigs
+ """
+
+ builtin_library_directory_link_flags = []
+ for builtin_library_directory in builtin_library_directories:
+ builtin_library_directory_link_flags.append("/libpath:{}".format(builtin_library_directory))
+
+ builtin_library_link_flags = []
+ for builtin_library in builtin_libraries:
+ builtin_library_link_flags.append(builtin_library)
+
+ if builtin_framework_directories:
+ fail("Frameworks not supported by `lld-link`")
+
+ if builtin_frameworks:
+ fail("Frameworks not supported by `lld-link`")
+
+ builtin_executable_objects_link_flags = []
+ for builtin_executable_object in builtin_executable_objects:
+ builtin_executable_objects_link_flags.append(builtin_executable_object)
+
+ required_link_flags = (["/nodefaultlib"] +
+ builtin_library_directory_link_flags +
+ builtin_library_link_flags)
+ required_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_link_flags),
+ ] if required_link_flags else []),
+ )
+
+ required_executable_link_flags = (builtin_executable_objects_link_flags)
+ required_executable_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_executable_link_flags),
+ ] if required_executable_link_flags else []),
+ )
+
+ link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = link_flags),
+ ] if link_flags else []),
+ )
+
+ dbg_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = dbg_link_flags),
+ ] if dbg_link_flags else []),
+ with_features = [with_feature_set(features = ["dbg"])],
+ )
+
+ fastbuild_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = fastbuild_link_flags),
+ ] if fastbuild_link_flags else []),
+ with_features = [with_feature_set(features = ["fastbuild"])],
+ )
+
+ opt_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = opt_link_flags),
+ ] if opt_link_flags else []),
+ with_features = [with_feature_set(features = ["opt"])],
+ )
+
+ return [
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_dynamic_library,
+ tools = [tool(path = "{}/bin/lld-link".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["/dll"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+ tools = [tool(path = "{}/bin/lld-link".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["/dll"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_executable,
+ tools = [tool(path = "{}/bin/lld-link".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ required_executable_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ ],
+ ),
+ ]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_ar.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_ar.bzl
new file mode 100644
index 000000000..80b5d9334
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_ar.bzl
@@ -0,0 +1,77 @@
+""" CC Archive ActionConfigs for llvm-ar """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "variable_with_value",
+)
+
+BASE_ARCHIVER_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-rcsD", "%{output_execpath}"],
+ expand_if_available = "output_execpath",
+ ),
+ flag_group(
+ iterate_over = "libraries_to_link",
+ flag_groups = [
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.object_files}"],
+ iterate_over = "libraries_to_link.object_files",
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ ],
+ expand_if_available = "libraries_to_link",
+ ),
+ ],
+)
+
+def archive_action_configs(llvm, archive_flags):
+ """
+ Generates CC Archive ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+ archive_flags (List): List of flags to always be passed to the archiver.
+
+ Returns:
+ List of CC Archive ActionConfigs
+ """
+
+ archive_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = archive_flags),
+ ] if archive_flags else []),
+ )
+
+ return [action_config(
+ action_name = ACTION_NAMES.cpp_link_static_library,
+ tools = [tool(path = "{}/bin/llvm-ar".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ archive_flag_set,
+ BASE_ARCHIVER_FLAG_SET,
+ ],
+ )]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_strip.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_strip.bzl
new file mode 100644
index 000000000..136294170
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/llvm_strip.bzl
@@ -0,0 +1,42 @@
+""" CC Strip ActionConfigs for llvm-strip """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+)
+
+def strip_action_configs(llvm):
+ """
+ Generates CC Strip ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+
+ Returns:
+ List of CC Strip ActionConfigs
+ """
+
+ return [action_config(
+ action_name = ACTION_NAMES.strip,
+ tools = [tool(path = "{}/bin/llvm-strip".format(llvm))],
+ flag_sets = [
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-S", "-p", "-o", "%{output_file}"],
+ ),
+ flag_group(
+ iterate_over = "stripopts",
+ flags = ["%{stripopts}"],
+ ),
+ flag_group(
+ flags = ["%{input_file}"],
+ ),
+ ],
+ ),
+ ],
+ )]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/wasm_ld.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/wasm_ld.bzl
new file mode 100644
index 000000000..c29fa38d3
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/cc_tools/wasm_ld.bzl
@@ -0,0 +1,299 @@
+""" CC Link ActionConfigs for wasm-ld """
+
+load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "action_config",
+ "flag_group",
+ "flag_set",
+ "tool",
+ "variable_with_value",
+ "with_feature_set",
+)
+
+BAZEL_LINK_FLAG_SET = flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["%{linkstamp_paths}"],
+ iterate_over = "linkstamp_paths",
+ expand_if_available = "linkstamp_paths",
+ ),
+ flag_group(
+ iterate_over = "runtime_library_search_directories",
+ flag_groups = [
+ flag_group(
+ flags = [
+ "-Xlinker",
+ "-rpath",
+ "-Xlinker",
+ "$ORIGIN/%{runtime_library_search_directories}",
+ ],
+ ),
+ ],
+ expand_if_available =
+ "runtime_library_search_directories",
+ ),
+ flag_group(
+ flags = ["-L%{library_search_directories}"],
+ iterate_over = "library_search_directories",
+ expand_if_available = "library_search_directories",
+ ),
+ flag_group(
+ iterate_over = "libraries_to_link",
+ flag_groups = [
+ flag_group(
+ flags = ["--start-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["-whole-archive"],
+ expand_if_true =
+ "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.object_files}"],
+ iterate_over = "libraries_to_link.object_files",
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "interface_library",
+ ),
+ ),
+ flag_group(
+ flags = ["%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "static_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-l:%{libraries_to_link.name}"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "versioned_dynamic_library",
+ ),
+ ),
+ flag_group(
+ flags = ["-no-whole-archive"],
+ expand_if_true = "libraries_to_link.is_whole_archive",
+ ),
+ flag_group(
+ flags = ["--end-lib"],
+ expand_if_equal = variable_with_value(
+ name = "libraries_to_link.type",
+ value = "object_file_group",
+ ),
+ ),
+ ],
+ expand_if_available = "libraries_to_link",
+ ),
+ flag_group(
+ flags = ["@%{thinlto_param_file}"],
+ expand_if_true = "thinlto_param_file",
+ ),
+ flag_group(
+ flags = ["%{user_link_flags}"],
+ iterate_over = "user_link_flags",
+ expand_if_available = "user_link_flags",
+ ),
+ flag_group(
+ flags = ["-o", "%{output_execpath}"],
+ expand_if_available = "output_execpath",
+ ),
+ ],
+)
+
+def link_action_configs(
+ llvm,
+ builtin_library_directories,
+ builtin_libraries,
+ builtin_framework_directories,
+ builtin_frameworks,
+ builtin_executable_objects,
+ link_flags,
+ dbg_link_flags,
+ fastbuild_link_flags,
+ opt_link_flags):
+ """
+ Generates CC Link ActionConfigs
+
+ Args:
+ llvm (string): Path to LLVM binaries.
+ builtin_library_directories (List): List of library directories to always be passed to the linker.
+ builtin_libraries (List): List of libraries to always be passed to the linker.
+ builtin_framework_directories (List): List of Apple framework directories to always be passed to the linker.
+ builtin_frameworks (List): List of Apple frameworks to always be passed to the linker.
+ builtin_executable_objects (List): List of object files to always be passed to the linker.
+ link_flags (List): List of flags to always be passed to the linker.
+ dbg_link_flags (List): List of additional flags to always be passed to the linker in dbg configuration.
+ fastbuild_link_flags (List): List of additional flags to always be passed to the linker in fastbuild configuration.
+ opt_link_flags (List): List of additional flags to always be passed to the linker in opt configuration.
+
+ Returns:
+ List of CC Link ActionConfigs
+ """
+
+ builtin_library_directory_link_flags = []
+ for builtin_library_directory in builtin_library_directories:
+ builtin_library_directory_link_flags.append("-L")
+ builtin_library_directory_link_flags.append(builtin_library_directory)
+
+ builtin_library_link_flags = []
+ for builtin_library in builtin_libraries:
+ builtin_library_link_flags.append("-l{}".format(builtin_library))
+
+ if builtin_framework_directories:
+ fail("Frameworks not supported by `wasm-ld`")
+
+ if builtin_frameworks:
+ fail("Frameworks not supported by `wasm-ld`")
+
+ builtin_executable_objects_link_flags = []
+ for builtin_executable_object in builtin_executable_objects:
+ builtin_executable_objects_link_flags.append("-l{}".format(builtin_executable_object))
+
+ required_link_flags = (builtin_library_directory_link_flags +
+ builtin_library_link_flags)
+ required_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_link_flags),
+ ] if required_link_flags else []),
+ )
+
+ required_executable_link_flags = (builtin_executable_objects_link_flags)
+ required_executable_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = required_executable_link_flags),
+ ] if required_executable_link_flags else []),
+ )
+
+ link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = link_flags),
+ ] if link_flags else []),
+ )
+
+ dbg_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = dbg_link_flags),
+ ] if dbg_link_flags else []),
+ with_features = [with_feature_set(features = ["dbg"])],
+ )
+
+ fastbuild_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = fastbuild_link_flags),
+ ] if fastbuild_link_flags else []),
+ with_features = [with_feature_set(features = ["fastbuild"])],
+ )
+
+ opt_link_flag_set = flag_set(
+ flag_groups = ([
+ flag_group(flags = opt_link_flags),
+ ] if opt_link_flags else []),
+ with_features = [with_feature_set(features = ["opt"])],
+ )
+
+ return [
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_dynamic_library,
+ tools = [tool(path = "{}/bin/wasm-ld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-shared"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
+ tools = [tool(path = "{}/bin/wasm-ld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["-shared"],
+ ),
+ ],
+ ),
+ ],
+ ),
+ action_config(
+ action_name = ACTION_NAMES.cpp_link_executable,
+ tools = [tool(path = "{}/bin/wasm-ld".format(llvm))],
+ flag_sets = [
+ # Mandatory, no link flags come through on command line.
+ flag_set(
+ flag_groups = [
+ flag_group(
+ flags = ["@%{linker_param_file}"],
+ expand_if_available = "linker_param_file",
+ ),
+ ],
+ ),
+ required_link_flag_set,
+ required_executable_link_flag_set,
+ link_flag_set,
+ dbg_link_flag_set,
+ fastbuild_link_flag_set,
+ opt_link_flag_set,
+ BAZEL_LINK_FLAG_SET,
+ ],
+ ),
+ ]
diff --git a/examples/nix_cross_compiling/bazel/toolchain_rules/llvm_cc_toolchain_config.bzl b/examples/nix_cross_compiling/bazel/toolchain_rules/llvm_cc_toolchain_config.bzl
new file mode 100644
index 000000000..726b18b2d
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchain_rules/llvm_cc_toolchain_config.bzl
@@ -0,0 +1,230 @@
+""" Generate CcToolchainConfigInfo for LLVM """
+
+load(
+ "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
+ "artifact_name_pattern",
+ "feature",
+)
+load("//bazel/toolchain_rules/cc_tools:clang.bzl", clang_compile_action_configs = "compile_action_configs")
+load("//bazel/toolchain_rules/cc_tools:ld.lld.bzl", ld_lld_link_action_configs = "link_action_configs")
+load("//bazel/toolchain_rules/cc_tools:ld64.lld.bzl", ld64_lld_link_action_configs = "link_action_configs")
+load("//bazel/toolchain_rules/cc_tools:lld_link.bzl", lld_link_link_action_configs = "link_action_configs")
+load("//bazel/toolchain_rules/cc_tools:llvm_ar.bzl", llvm_ar_archive_action_configs = "archive_action_configs")
+load("//bazel/toolchain_rules/cc_tools:llvm_strip.bzl", llvm_strip_strip_action_configs = "strip_action_configs")
+load("//bazel/toolchain_rules/cc_tools:wasm_ld.bzl", wasm_ld_link_action_configs = "link_action_configs")
+
+APPLE_ARTIFACT_NAME_PATTERNS = [
+ # Artifact name patterns differ from the defaults only for dynamic libraries.
+ artifact_name_pattern(
+ category_name = "dynamic_library",
+ prefix = "lib",
+ extension = ".dylib",
+ ),
+]
+
+LINUX_ARTIFACT_NAME_PATTERNS = [
+ # Artifact name patterns are the default.
+]
+
+WASM_ARTIFACT_NAME_PATTERNS = [
+ # Artifact name patterns differ from the defaults only for executables.
+ artifact_name_pattern(
+ category_name = "executable",
+ prefix = "",
+ extension = ".wasm",
+ ),
+]
+
+WINDOWS_ARTIFACT_NAME_PATTERNS = [
+ artifact_name_pattern(
+ category_name = "object_file",
+ prefix = "",
+ extension = ".obj",
+ ),
+ artifact_name_pattern(
+ category_name = "static_library",
+ prefix = "",
+ extension = ".lib",
+ ),
+ artifact_name_pattern(
+ category_name = "alwayslink_static_library",
+ prefix = "",
+ extension = ".lo.lib",
+ ),
+ artifact_name_pattern(
+ category_name = "executable",
+ prefix = "",
+ extension = ".exe",
+ ),
+ artifact_name_pattern(
+ category_name = "dynamic_library",
+ prefix = "",
+ extension = ".dll",
+ ),
+ artifact_name_pattern(
+ category_name = "interface_library",
+ prefix = "",
+ extension = ".if.lib",
+ ),
+]
+
+TARGET_CONFIG = {
+ "aarch64-apple-darwin": struct(
+ artifact_name_patterns = APPLE_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld64_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "aarch64-apple-ios": struct(
+ artifact_name_patterns = APPLE_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld64_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "aarch64-linux-android": struct(
+ artifact_name_patterns = LINUX_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "aarch64-unknown-linux-gnu": struct(
+ artifact_name_patterns = LINUX_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "wasm32-unknown-unknown": struct(
+ artifact_name_patterns = WASM_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = wasm_ld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "wasm32-wasi": struct(
+ artifact_name_patterns = WASM_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = wasm_ld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "x86_64-apple-darwin": struct(
+ artifact_name_patterns = APPLE_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld64_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "x86_64-pc-windows-msvc": struct(
+ artifact_name_patterns = WINDOWS_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = lld_link_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+ "x86_64-unknown-linux-gnu": struct(
+ artifact_name_patterns = LINUX_ARTIFACT_NAME_PATTERNS,
+ compile_action_configs = clang_compile_action_configs,
+ archive_action_configs = llvm_ar_archive_action_configs,
+ link_action_configs = ld_lld_link_action_configs,
+ strip_action_configs = llvm_strip_strip_action_configs,
+ ),
+}
+
+def _llvm_cc_toolchain_config_impl(ctx):
+ target_config = TARGET_CONFIG[ctx.attr.target]
+
+ compile_action_configs = target_config.compile_action_configs(
+ clang = ctx.attr.clang,
+ target = ctx.attr.target,
+ builtin_include_directories = ctx.attr.builtin_include_directories,
+ builtin_framework_directories = ctx.attr.builtin_framework_directories,
+ compile_flags = ctx.attr.compile_flags,
+ dbg_compile_flags = ctx.attr.dbg_compile_flags,
+ fastbuild_compile_flags = ctx.attr.fastbuild_compile_flags,
+ opt_compile_flags = ctx.attr.opt_compile_flags,
+ remap_path_prefix = ctx.attr.remap_path_prefix,
+ )
+
+ archive_action_configs = target_config.archive_action_configs(
+ llvm = ctx.attr.llvm,
+ archive_flags = ctx.attr.archive_flags,
+ )
+
+ link_action_configs = target_config.link_action_configs(
+ llvm = ctx.attr.llvm,
+ builtin_library_directories = ctx.attr.builtin_library_directories,
+ builtin_libraries = ctx.attr.builtin_libraries,
+ builtin_framework_directories = ctx.attr.builtin_framework_directories,
+ builtin_frameworks = ctx.attr.builtin_frameworks,
+ builtin_executable_objects = ctx.attr.builtin_executable_objects,
+ link_flags = ctx.attr.link_flags,
+ dbg_link_flags = ctx.attr.dbg_link_flags,
+ fastbuild_link_flags = ctx.attr.fastbuild_link_flags,
+ opt_link_flags = ctx.attr.opt_link_flags,
+ )
+
+ strip_action_configs = target_config.strip_action_configs(
+ llvm = ctx.attr.llvm,
+ )
+
+ return cc_common.create_cc_toolchain_config_info(
+ ctx = ctx,
+ features = [
+ feature(name = "no_legacy_features", enabled = True),
+ feature(name = "supports_start_end_lib", enabled = ctx.attr.supports_start_end_lib),
+ feature(name = "supports_interface_shared_libraries", enabled = False),
+ feature(name = "supports_dynamic_linker", enabled = True),
+ feature(name = "has_configured_linker_path", enabled = True),
+ feature(name = "static_link_cpp_runtimes", enabled = False),
+ feature(name = "supports_pic", enabled = True),
+ ],
+ action_configs = compile_action_configs +
+ archive_action_configs +
+ link_action_configs +
+ strip_action_configs,
+ artifact_name_patterns = target_config.artifact_name_patterns,
+ cxx_builtin_include_directories = ctx.attr.builtin_include_directories,
+ toolchain_identifier = ctx.attr.name,
+ host_system_name = None,
+ target_system_name = ctx.attr.target,
+ target_cpu = "unused",
+ target_libc = "unused",
+ compiler = "unused",
+ abi_version = None,
+ abi_libc_version = None,
+ tool_paths = [],
+ make_variables = [],
+ builtin_sysroot = None,
+ cc_target_os = None,
+ )
+
+llvm_cc_toolchain_config = rule(
+ implementation = _llvm_cc_toolchain_config_impl,
+ attrs = {
+ "archive_flags": attr.string_list(),
+ "builtin_executable_objects": attr.string_list(),
+ "builtin_framework_directories": attr.string_list(),
+ "builtin_frameworks": attr.string_list(),
+ "builtin_include_directories": attr.string_list(),
+ "builtin_libraries": attr.string_list(),
+ "builtin_library_directories": attr.string_list(),
+ "clang": attr.string(mandatory = True),
+ "compile_flags": attr.string_list(),
+ "dbg_compile_flags": attr.string_list(),
+ "dbg_link_flags": attr.string_list(),
+ "fastbuild_compile_flags": attr.string_list(),
+ "fastbuild_link_flags": attr.string_list(),
+ "link_flags": attr.string_list(),
+ "llvm": attr.string(mandatory = True),
+ "opt_compile_flags": attr.string_list(),
+ "opt_link_flags": attr.string_list(),
+ "remap_path_prefix": attr.string(),
+ "supports_start_end_lib": attr.bool(default = True),
+ "target": attr.string(mandatory = True),
+ },
+ provides = [CcToolchainConfigInfo],
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-darwin/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-darwin/BUILD.bazel
new file mode 100644
index 000000000..18b9e4466
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-darwin/BUILD.bazel
@@ -0,0 +1,101 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_UNIVERSAL_APPLE_DARWIN",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_framework_directories = [
+ "{}/System/Library/Frameworks".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ builtin_frameworks = [],
+ builtin_include_directories = [
+ "{}/usr/include/c++/v1".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/usr/include".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ builtin_libraries = [],
+ builtin_library_directories = [
+ "{}/usr/lib".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [
+ "-g",
+ "-fstandalone-debug",
+ ],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "-fatal_warnings",
+ "-arch",
+ "arm64",
+ "-macos_version_min",
+ "13.0.0",
+ "-platform_version",
+ "macos",
+ "13.0.0",
+ "13.1",
+ "-headerpad_max_install_names",
+ "-undefined",
+ "dynamic_lookup",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [
+ "-g0",
+ "-O2",
+ "-D_FORTIFY_SOURCE=1",
+ "-DNDEBUG",
+ "-ffunction-sections",
+ "-fdata-sections",
+ ],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "aarch64-apple-darwin",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:macos",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-ios/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-ios/BUILD.bazel
new file mode 100644
index 000000000..6864ff30a
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-apple-ios/BUILD.bazel
@@ -0,0 +1,99 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_UNIVERSAL_APPLE_IOS",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_framework_directories = [
+ "{}/System/Library/Frameworks".format(SDK_UNIVERSAL_APPLE_IOS),
+ ],
+ builtin_frameworks = [],
+ builtin_include_directories = [
+ "{}/usr/include/c++/v1".format(SDK_UNIVERSAL_APPLE_IOS),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/usr/include".format(SDK_UNIVERSAL_APPLE_IOS),
+ ],
+ builtin_libraries = [],
+ builtin_library_directories = [
+ "{}/usr/lib".format(SDK_UNIVERSAL_APPLE_IOS),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [
+ "-g",
+ "-fstandalone-debug",
+ ],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "-fatal_warnings",
+ "-arch",
+ "arm64",
+ "-platform_version",
+ "ios",
+ "16.0.0",
+ "16.2",
+ "-headerpad_max_install_names",
+ "-undefined",
+ "dynamic_lookup",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [
+ "-g0",
+ "-O2",
+ "-D_FORTIFY_SOURCE=1",
+ "-DNDEBUG",
+ "-ffunction-sections",
+ "-fdata-sections",
+ ],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "aarch64-apple-ios",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:ios",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-linux-android/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-linux-android/BUILD.bazel
new file mode 100644
index 000000000..6d5e4f51b
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-linux-android/BUILD.bazel
@@ -0,0 +1,114 @@
+load(
+ "@nix_config//:config.bzl",
+ "ANDROID_NDK_VERSION",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_UNIVERSAL_LINUX_ANDROID",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [
+ ":crtbegin_dynamic.o",
+ ":crtend_android.o",
+ ],
+ builtin_include_directories = [
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ ],
+ builtin_libraries = [
+ "c",
+ "dl",
+ "m",
+ "unwind",
+ "stdc++",
+ "c++",
+ "c++abi",
+ ],
+ builtin_library_directories = [
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.7/lib/linux/aarch64".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ "{}/share/android-sdk/ndk/{}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib".format(SDK_UNIVERSAL_LINUX_ANDROID, ANDROID_NDK_VERSION),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-DANDROID",
+ "-D_FORTIFY_SOURCE=2",
+ "-fdata-sections",
+ "-ffunction-sections",
+ "-fno-exceptions",
+ "-fstack-protector-strong",
+ "-funwind-tables",
+ "-no-canonical-prefixes",
+ "-Wall",
+ "-Werror",
+ "-Werror=format-security",
+ "-Wformat",
+ "-Wself-assign",
+ "-Wthread-safety",
+ ],
+ dbg_compile_flags = [
+ "-g",
+ "-fno-limit-debug-info",
+ ],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ "--sysroot={}/toolchains/llvm/prebuilt/linux-x86_64/sysroot".format(SDK_UNIVERSAL_LINUX_ANDROID),
+ "--dynamic-linker=/system/bin/linker64",
+ "--build-id=md5",
+ "--hash-style=gnu",
+ "-z",
+ "relro",
+ "-z",
+ "now",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "aarch64-linux-android",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:android",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-unknown-linux-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-unknown-linux-gnu/BUILD.bazel
new file mode 100644
index 000000000..a8021a3f8
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/aarch64-unknown-linux-gnu/BUILD.bazel
@@ -0,0 +1,103 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_AARCH64_UNKNOWN_LINUX_GNU",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [
+ ":Scrt1.o",
+ ":crti.o",
+ ":crtbeginS.o",
+ ":crtendS.o",
+ ":crtn.o",
+ ],
+ builtin_include_directories = [
+ "{}/usr/include/c++/10".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include/aarch64-linux-gnu/c++/10".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include/c++/10/backward".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/usr/include/aarch64-linux-gnu".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ ],
+ builtin_libraries = [
+ "c",
+ "dl",
+ "gcc_s",
+ "gcc",
+ "m",
+ "pthread",
+ "stdc++",
+ ],
+ builtin_library_directories = [
+ "{}/lib/aarch64-linux-gnu".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/usr/lib/gcc/aarch64-linux-gnu/10".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "{}/usr/lib/aarch64-linux-gnu".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ "--sysroot={}".format(SDK_AARCH64_UNKNOWN_LINUX_GNU),
+ "--dynamic-linker=/lib64/ld-linux-aarch64.so.1",
+ "--build-id=md5",
+ "--hash-style=gnu",
+ "-z",
+ "relro",
+ "-z",
+ "now",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "aarch64-unknown-linux-gnu",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:linux",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-unknown-unknown/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-unknown-unknown/BUILD.bazel
new file mode 100644
index 000000000..7f2edf683
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-unknown-unknown/BUILD.bazel
@@ -0,0 +1,75 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LIBCLANG_RT_WASM32",
+ "LLVM",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_include_directories = [
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ ],
+ builtin_libraries = [],
+ builtin_library_directories = [],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ # `wasm-ld` doesn't respect the verbatim `-l:` syntax.
+ "{}/lib/wasi/libclang_rt.builtins-wasm32.a".format(LIBCLANG_RT_WASM32),
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ supports_start_end_lib = False,
+ tags = ["manual"],
+ target = "wasm32-unknown-unknown",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:none",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-wasi/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-wasi/BUILD.bazel
new file mode 100644
index 000000000..3af385af2
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/wasm32-wasi/BUILD.bazel
@@ -0,0 +1,86 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LIBCLANG_RT_WASM32",
+ "LLVM",
+ "SDK_WASM32_WASI",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_include_directories = [
+ "{}/wasi-sysroot/include/c++/v1".format(SDK_WASM32_WASI),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/wasi-sysroot/include".format(SDK_WASM32_WASI),
+ ],
+ builtin_libraries = [
+ "c",
+ "c++",
+ "c++abi",
+ "m",
+ ],
+ builtin_library_directories = [
+ "{}/wasi-sysroot/lib/wasm32-wasi".format(SDK_WASM32_WASI),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ # `wasm-ld` doesn't respect the verbatim `-l:` syntax.
+ "{}/lib/wasi/libclang_rt.builtins-wasm32.a".format(LIBCLANG_RT_WASM32),
+ "{}/wasi-sysroot/lib/wasm32-wasi/crt1.o".format(SDK_WASM32_WASI),
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ supports_start_end_lib = False,
+ tags = ["manual"],
+ target = "wasm32-wasi",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:wasi",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-apple-darwin/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-apple-darwin/BUILD.bazel
new file mode 100644
index 000000000..578f63214
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-apple-darwin/BUILD.bazel
@@ -0,0 +1,101 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_UNIVERSAL_APPLE_DARWIN",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_framework_directories = [
+ "{}/System/Library/Frameworks".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ builtin_frameworks = [],
+ builtin_include_directories = [
+ "{}/usr/include/c++/v1".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/usr/include".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ builtin_libraries = [],
+ builtin_library_directories = [
+ "{}/usr/lib".format(SDK_UNIVERSAL_APPLE_DARWIN),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [
+ "-g",
+ "-fstandalone-debug",
+ ],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "-fatal_warnings",
+ "-arch",
+ "x86_64",
+ "-macos_version_min",
+ "13.0.0",
+ "-platform_version",
+ "macos",
+ "13.0.0",
+ "13.1",
+ "-headerpad_max_install_names",
+ "-undefined",
+ "dynamic_lookup",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [
+ "-g0",
+ "-O2",
+ "-D_FORTIFY_SOURCE=1",
+ "-DNDEBUG",
+ "-ffunction-sections",
+ "-fdata-sections",
+ ],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "x86_64-apple-darwin",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:macos",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-pc-windows-msvc/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-pc-windows-msvc/BUILD.bazel
new file mode 100644
index 000000000..18c75dcfe
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-pc-windows-msvc/BUILD.bazel
@@ -0,0 +1,93 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_X86_64_PC_WINDOWS_MSVC",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [],
+ builtin_include_directories = [
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/crt/include".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/include/ucrt".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/include/shared".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/include/um".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/include/winrt".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ ],
+ builtin_libraries = [
+ "advapi32.lib",
+ "bcrypt.lib",
+ "kernel32.lib",
+ "libcmt.lib",
+ "libcpmt.lib",
+ "libucrt.lib",
+ "libvcruntime.lib",
+ "ntdll.lib",
+ "userenv.lib",
+ "uuid.lib",
+ "ws2_32.lib",
+ ],
+ builtin_library_directories = [
+ "{}/crt/lib/x86_64".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/lib/um/x86_64".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ "{}/sdk/lib/ucrt/x86_64".format(SDK_X86_64_PC_WINDOWS_MSVC),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "/wx", # Treat warnings as errors
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "/opt:icf,ref",
+ ],
+ tags = ["manual"],
+ target = "x86_64-pc-windows-msvc",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:windows",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-linux-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-linux-gnu/BUILD.bazel
new file mode 100644
index 000000000..49cb0cf51
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-linux-gnu/BUILD.bazel
@@ -0,0 +1,103 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "SDK_X86_64_UNKNOWN_LINUX_GNU",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [
+ ":Scrt1.o",
+ ":crti.o",
+ ":crtbeginS.o",
+ ":crtendS.o",
+ ":crtn.o",
+ ],
+ builtin_include_directories = [
+ "{}/usr/include/c++/10".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include/x86_64-linux-gnu/c++/10".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include/c++/10/backward".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/usr/include/x86_64-linux-gnu".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/usr/include".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ ],
+ builtin_libraries = [
+ "c",
+ "dl",
+ "gcc_s",
+ "gcc",
+ "m",
+ "pthread",
+ "stdc++",
+ ],
+ builtin_library_directories = [
+ "{}/lib/x86_64-linux-gnu".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/usr/lib/gcc/x86_64-linux-gnu/10".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "{}/usr/lib/x86_64-linux-gnu".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ "--sysroot={}".format(SDK_X86_64_UNKNOWN_LINUX_GNU),
+ "--dynamic-linker=/lib64/ld-linux-x86-64.so.2",
+ "--build-id=md5",
+ "--hash-style=gnu",
+ "-z",
+ "relro",
+ "-z",
+ "now",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "x86_64-unknown-linux-gnu",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-nixos-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-nixos-gnu/BUILD.bazel
new file mode 100644
index 000000000..5e85ae306
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/cc/x86_64-unknown-nixos-gnu/BUILD.bazel
@@ -0,0 +1,99 @@
+load(
+ "@nix_config//:config.bzl",
+ "CLANG",
+ "CLANG_LIB",
+ "CLANG_LIB_VERSION",
+ "LLVM",
+ "NIXOS_DYNAMIC_LINKER",
+ "SDK_X86_64_UNKNOWN_NIXOS_GNU",
+)
+load("@rules_cc//cc:defs.bzl", "cc_toolchain")
+load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
+
+llvm_cc_toolchain_config(
+ name = "cc_toolchain_config",
+ archive_flags = [],
+ builtin_executable_objects = [
+ ":Scrt1.o",
+ ":crti.o",
+ ":crtbeginS.o",
+ ":crtendS.o",
+ ":crtn.o",
+ ],
+ builtin_include_directories = [
+ "{}/include/c++/v1".format(SDK_X86_64_UNKNOWN_NIXOS_GNU),
+ "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
+ "{}/include".format(SDK_X86_64_UNKNOWN_NIXOS_GNU),
+ ],
+ builtin_libraries = [
+ ":libunwind.a",
+ ":libc.so",
+ ":libc++.a",
+ ":libc++abi.a",
+ "dl",
+ "m",
+ "pthread",
+ ],
+ builtin_library_directories = [
+ "{}/lib".format(SDK_X86_64_UNKNOWN_NIXOS_GNU),
+ "{}/lib/gcc/x86_64-unknown-linux-gnu/13.2.0".format(SDK_X86_64_UNKNOWN_NIXOS_GNU),
+ ],
+ clang = CLANG,
+ compile_flags = [
+ "-fno-exceptions",
+ "-Werror",
+ "-Wall",
+ "-Wthread-safety",
+ "-Wself-assign",
+ ],
+ dbg_compile_flags = [],
+ dbg_link_flags = [],
+ fastbuild_compile_flags = [],
+ fastbuild_link_flags = [],
+ link_flags = [
+ "--fatal-warnings",
+ "--dynamic-linker={}".format(NIXOS_DYNAMIC_LINKER),
+ "--build-id=md5",
+ "--hash-style=gnu",
+ "-z",
+ "relro",
+ "-z",
+ "now",
+ ],
+ llvm = LLVM,
+ opt_compile_flags = [],
+ opt_link_flags = [
+ "--gc-sections",
+ ],
+ tags = ["manual"],
+ target = "x86_64-unknown-linux-gnu",
+)
+
+cc_toolchain(
+ name = "cc_toolchain",
+ all_files = "@nix_config//:config.bzl",
+ ar_files = "@nix_config//:config.bzl",
+ as_files = "@nix_config//:config.bzl",
+ compiler_files = "@nix_config//:config.bzl",
+ coverage_files = "@nix_config//:config.bzl",
+ dwp_files = "@nix_config//:config.bzl",
+ linker_files = "@nix_config//:config.bzl",
+ objcopy_files = "@nix_config//:config.bzl",
+ strip_files = "@nix_config//:config.bzl",
+ tags = ["manual"],
+ toolchain_config = "cc_toolchain_config",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ toolchain = ":cc_toolchain",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-darwin/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-darwin/BUILD.bazel
new file mode 100644
index 000000000..ee0f84bac
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-darwin/BUILD.bazel
@@ -0,0 +1,43 @@
+load("@nix_config//:config.bzl", "SDK_UNIVERSAL_APPLE_DARWIN")
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {
+ "SDKROOT": SDK_UNIVERSAL_APPLE_DARWIN,
+ },
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ extra_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-aarch64-apple-darwin",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "aarch64-apple-darwin",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:macos",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-ios/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-ios/BUILD.bazel
new file mode 100644
index 000000000..d0ae50817
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-apple-ios/BUILD.bazel
@@ -0,0 +1,43 @@
+load("@nix_config//:config.bzl", "SDK_UNIVERSAL_APPLE_IOS")
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {
+ "SDKROOT": SDK_UNIVERSAL_APPLE_IOS,
+ },
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ extra_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-aarch64-apple-ios",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "aarch64-apple-ios",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:ios",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-linux-android/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-linux-android/BUILD.bazel
new file mode 100644
index 000000000..3c56b4833
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-linux-android/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-aarch64-linux-android",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "aarch64-linux-android",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:android",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-unknown-linux-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-unknown-linux-gnu/BUILD.bazel
new file mode 100644
index 000000000..215b7d74d
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/aarch64-unknown-linux-gnu/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-aarch64-unknown-linux-gnu",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "aarch64-unknown-linux-gnu",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:aarch64",
+ "@platforms//os:linux",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-unknown-unknown/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-unknown-unknown/BUILD.bazel
new file mode 100644
index 000000000..409d1dfe1
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-unknown-unknown/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = ".wasm",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-wasm32-unknown-unknown",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "wasm32-unknown-unknown",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:none",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-wasi/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-wasi/BUILD.bazel
new file mode 100644
index 000000000..f9494a07a
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/wasm32-wasi/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = ".wasm",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-wasm32-wasi",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "wasm32-wasi",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:wasm32",
+ "@platforms//os:wasi",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-apple-darwin/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-apple-darwin/BUILD.bazel
new file mode 100644
index 000000000..9ad447eef
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-apple-darwin/BUILD.bazel
@@ -0,0 +1,43 @@
+load("@nix_config//:config.bzl", "SDK_UNIVERSAL_APPLE_DARWIN")
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".dylib",
+ env = {
+ "SDKROOT": SDK_UNIVERSAL_APPLE_DARWIN,
+ },
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ extra_rustc_flags = [
+ "-Clinker-flavor=ld64.lld",
+ ],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-x86_64-apple-darwin",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "x86_64-apple-darwin",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:macos",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-pc-windows-msvc/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-pc-windows-msvc/BUILD.bazel
new file mode 100644
index 000000000..d03d58087
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-pc-windows-msvc/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = ".exe",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".dll",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-x86_64-pc-windows-msvc",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".lib",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "x86_64-pc-windows-msvc",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:windows",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-linux-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-linux-gnu/BUILD.bazel
new file mode 100644
index 000000000..3a79e3970
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-linux-gnu/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-x86_64-unknown-linux-gnu",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "x86_64-unknown-linux-gnu",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-nixos-gnu/BUILD.bazel b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-nixos-gnu/BUILD.bazel
new file mode 100644
index 000000000..d237d28fb
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/toolchains/rust/x86_64-unknown-nixos-gnu/BUILD.bazel
@@ -0,0 +1,36 @@
+load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
+
+rust_toolchain(
+ name = "rust_toolchain",
+ binary_ext = "",
+ cargo = "@nix_rust//:cargo",
+ clippy_driver = "@nix_rust//:clippy_driver",
+ default_edition = "2021",
+ dylib_ext = ".so",
+ env = {},
+ exec_triple = "x86_64-unknown-nixos-gnu",
+ extra_exec_rustc_flags = [],
+ extra_rustc_flags = [],
+ rust_doc = "@nix_rust//:rustdoc",
+ rust_std = "@nix_rust//:rust_std-x86_64-unknown-linux-gnu",
+ rustc = "@nix_rust//:rustc",
+ rustc_lib = "@nix_rust//:rustc_lib",
+ staticlib_ext = ".a",
+ stdlib_linkflags = [],
+ tags = ["manual"],
+ target_triple = "x86_64-unknown-linux-gnu",
+)
+
+toolchain(
+ name = "toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:nixos",
+ ],
+ toolchain = ":rust_toolchain",
+ toolchain_type = "@rules_rust//rust:toolchain_type",
+)
diff --git a/examples/nix_cross_compiling/bazel/transitions.bzl b/examples/nix_cross_compiling/bazel/transitions.bzl
new file mode 100644
index 000000000..3960f82f7
--- /dev/null
+++ b/examples/nix_cross_compiling/bazel/transitions.bzl
@@ -0,0 +1,81 @@
+"""
+https://github.com/aspect-build/bazel-lib/blob/main/lib/transitions.bzl
+
+Rules for working with transitions.
+"""
+
+load("@bazel_skylib//lib:paths.bzl", "paths")
+
+def _transition_platform_impl(_, attr):
+ return {"//command_line_option:platforms": str(attr.target_platform)}
+
+# Transition from any input configuration to one that includes the
+# --platforms command-line flag.
+_transition_platform = transition(
+ implementation = _transition_platform_impl,
+ inputs = [],
+ outputs = ["//command_line_option:platforms"],
+)
+
+def _platform_transition_binary_impl(ctx):
+ # We need to forward the DefaultInfo provider from the underlying rule.
+ # Unfortunately, we can't do this directly, because Bazel requires that the executable to run
+ # is actually generated by this rule, so we need to symlink to it, and generate a synthetic
+ # forwarding DefaultInfo.
+
+ result = []
+ binary = ctx.attr.binary[0]
+
+ default_info = binary[DefaultInfo]
+ files = default_info.files
+ new_executable = None
+ original_executable = default_info.files_to_run.executable
+ runfiles = default_info.default_runfiles
+
+ if not original_executable:
+ fail("Cannot transition a 'binary' that is not executable")
+
+ new_executable_name = original_executable.basename
+
+ # In order for the symlink to have the same basename as the original
+ # executable (important in the case of proto plugins), put it in a
+ # subdirectory named after the label to prevent collisions.
+ new_executable = ctx.actions.declare_file(paths.join(ctx.label.name, new_executable_name))
+ ctx.actions.symlink(
+ output = new_executable,
+ target_file = original_executable,
+ is_executable = True,
+ )
+ files = depset(direct = [new_executable], transitive = [files])
+ runfiles = runfiles.merge(ctx.runfiles([new_executable]))
+
+ result.append(
+ DefaultInfo(
+ files = files,
+ runfiles = runfiles,
+ executable = new_executable,
+ ),
+ )
+
+ return result
+
+platform_transition_binary = rule(
+ doc = "Transitions the binary to use the provided platform.",
+ implementation = _platform_transition_binary_impl,
+ attrs = {
+ "binary": attr.label(
+ doc = "The target to transition.",
+ allow_files = True,
+ cfg = _transition_platform,
+ mandatory = True,
+ ),
+ "target_platform": attr.label(
+ doc = "The target platform to transition the binary.",
+ mandatory = True,
+ ),
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+ ),
+ },
+ executable = True,
+)
diff --git a/examples/nix_cross_compiling/cc_binary/BUILD.bazel b/examples/nix_cross_compiling/cc_binary/BUILD.bazel
new file mode 100644
index 000000000..68085d41c
--- /dev/null
+++ b/examples/nix_cross_compiling/cc_binary/BUILD.bazel
@@ -0,0 +1,17 @@
+load("@rules_cc//cc:defs.bzl", "cc_binary")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_binary(
+ name = "cc_binary",
+ srcs = select({
+ # See comment in `cc_binary_wasm32.cc`.
+ "@platforms//os:none": ["cc_binary_wasm32-unknown-unknown.cc"],
+ "//conditions:default": ["cc_binary.cc"],
+ }),
+ tags = ["platform_missing"],
+ deps = [
+ "//cc_library",
+ "//rust_library:rust_library_cc",
+ ],
+)
diff --git a/examples/nix_cross_compiling/cc_binary/cc_binary.cc b/examples/nix_cross_compiling/cc_binary/cc_binary.cc
new file mode 100644
index 000000000..26a84be72
--- /dev/null
+++ b/examples/nix_cross_compiling/cc_binary/cc_binary.cc
@@ -0,0 +1,13 @@
+#include
+
+#include
+
+extern "C" int cc_double_value(int value);
+extern "C" int rust_double_value(int value);
+
+int main() {
+ printf("Hello World!\n");
+ std::cout << "CC: " << cc_double_value(5) << std::endl;
+ std::cout << "Rust: " << rust_double_value(5) << std::endl;
+ return 0;
+}
diff --git a/examples/nix_cross_compiling/cc_binary/cc_binary_wasm32-unknown-unknown.cc b/examples/nix_cross_compiling/cc_binary/cc_binary_wasm32-unknown-unknown.cc
new file mode 100644
index 000000000..2a1959e54
--- /dev/null
+++ b/examples/nix_cross_compiling/cc_binary/cc_binary_wasm32-unknown-unknown.cc
@@ -0,0 +1,10 @@
+extern "C" int cc_double_value(int value);
+extern "C" int rust_double_value(int value);
+
+// `wasm32-unknown-unknown` is very barebones, so we have to define `_start()`
+// and we don't have access to `stdio.h` or `iostream`, so we can't output
+// anything, but we can still call the functions.
+extern "C" void _start() {
+ cc_double_value(5);
+ rust_double_value(5);
+}
diff --git a/examples/nix_cross_compiling/cc_library/BUILD.bazel b/examples/nix_cross_compiling/cc_library/BUILD.bazel
new file mode 100644
index 000000000..db5ffb6dd
--- /dev/null
+++ b/examples/nix_cross_compiling/cc_library/BUILD.bazel
@@ -0,0 +1,11 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+ name = "cc_library",
+ srcs = ["cc_library.cc"],
+ linkstatic = True,
+ tags = ["platform_missing"],
+ deps = [],
+)
diff --git a/examples/nix_cross_compiling/cc_library/cc_library.cc b/examples/nix_cross_compiling/cc_library/cc_library.cc
new file mode 100644
index 000000000..2153c0d09
--- /dev/null
+++ b/examples/nix_cross_compiling/cc_library/cc_library.cc
@@ -0,0 +1 @@
+extern "C" int cc_double_value(int value) { return value * 2; }
diff --git a/examples/nix_cross_compiling/nix/BUILD.bazel b/examples/nix_cross_compiling/nix/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/examples/nix_cross_compiling/nix/README.md b/examples/nix_cross_compiling/nix/README.md
new file mode 100644
index 000000000..04c2f5975
--- /dev/null
+++ b/examples/nix_cross_compiling/nix/README.md
@@ -0,0 +1,9 @@
+# Nix
+
+Nix Flake that supplies toolchains and SDKs for cross compiling.
+
+This is kept in its own package so that when using the Nix `path:` syntax, only
+this directory is copied to the Nix Store instead of the entire `rules_rust`
+repository.
+
+See also: `//bazel/nix_repositories.bzl`
diff --git a/examples/nix_cross_compiling/nix/flake.lock b/examples/nix_cross_compiling/nix/flake.lock
new file mode 100644
index 000000000..dfd30a2f6
--- /dev/null
+++ b/examples/nix_cross_compiling/nix/flake.lock
@@ -0,0 +1,159 @@
+{
+ "nodes": {
+ "android-nixpkgs": {
+ "inputs": {
+ "devshell": "devshell",
+ "flake-utils": "flake-utils",
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1701375499,
+ "narHash": "sha256-hiBAShY1YAztW01Qx846pgomyFZpBzsZ8DUY8LFhtX4=",
+ "owner": "tadfisher",
+ "repo": "android-nixpkgs",
+ "rev": "24efd95411d18a8518b64bd041daaeb5d0a45da4",
+ "type": "github"
+ },
+ "original": {
+ "owner": "tadfisher",
+ "repo": "android-nixpkgs",
+ "type": "github"
+ }
+ },
+ "devshell": {
+ "inputs": {
+ "nixpkgs": [
+ "android-nixpkgs",
+ "nixpkgs"
+ ],
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1700815693,
+ "narHash": "sha256-JtKZEQUzosrCwDsLgm+g6aqbP1aseUl1334OShEAS3s=",
+ "owner": "numtide",
+ "repo": "devshell",
+ "rev": "7ad1c417c87e98e56dcef7ecd0e0a2f2e5669d51",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "devshell",
+ "type": "github"
+ }
+ },
+ "fenix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "rust-analyzer-src": "rust-analyzer-src"
+ },
+ "locked": {
+ "lastModified": 1701325357,
+ "narHash": "sha256-+CF74n9/AlLwgdCTM5WuKsa/4C1YxJSpRDCfz1ErOl0=",
+ "owner": "nix-community",
+ "repo": "fenix",
+ "rev": "07a409ce1fe2c6d6e871793394b0cc0e5e262e3b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "fenix",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems_2"
+ },
+ "locked": {
+ "lastModified": 1694529238,
+ "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1701237617,
+ "narHash": "sha256-Ryd8xpNDY9MJnBFDYhB37XSFIxCPVVVXAbInNPa95vs=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "85306ef2470ba705c97ce72741d56e42d0264015",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "android-nixpkgs": "android-nixpkgs",
+ "fenix": "fenix",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "rust-analyzer-src": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1701186284,
+ "narHash": "sha256-euPBY3EmEy7+Jjm2ToRPlSp/qrj0UL9+PRobxVz6+aQ=",
+ "owner": "rust-lang",
+ "repo": "rust-analyzer",
+ "rev": "c7c582afb57bb802715262d7f1ba73b8a86c1c5a",
+ "type": "github"
+ },
+ "original": {
+ "owner": "rust-lang",
+ "ref": "nightly",
+ "repo": "rust-analyzer",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ },
+ "systems_2": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/examples/nix_cross_compiling/nix/flake.nix b/examples/nix_cross_compiling/nix/flake.nix
new file mode 100644
index 000000000..d329b93da
--- /dev/null
+++ b/examples/nix_cross_compiling/nix/flake.nix
@@ -0,0 +1,156 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ fenix = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ android-nixpkgs = {
+ url = "github:tadfisher/android-nixpkgs";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs = { self, nixpkgs, fenix, android-nixpkgs, ... }:
+ let
+ pkgs = import nixpkgs { system = "x86_64-linux"; };
+
+ llvm = pkgs.llvmPackages_16;
+
+ rust = with fenix.packages."x86_64-linux"; combine [
+ complete.cargo
+ complete.clippy
+ complete.rustc
+ complete.rustfmt
+ complete.rust-src
+ complete.rust-analyzer
+ targets."aarch64-apple-darwin".latest.rust-std
+ targets."aarch64-apple-ios".latest.rust-std
+ targets."aarch64-linux-android".latest.rust-std
+ targets."aarch64-unknown-linux-gnu".latest.rust-std
+ targets."wasm32-unknown-unknown".latest.rust-std
+ targets."wasm32-wasi".latest.rust-std
+ targets."x86_64-apple-darwin".latest.rust-std
+ targets."x86_64-pc-windows-msvc".latest.rust-std
+ targets."x86_64-unknown-linux-gnu".latest.rust-std
+ ];
+
+ fetchVendor = { name, url, sha256, stripComponents ? 0 }:
+ let
+ authorization =
+ if (pkgs.lib.hasPrefix "https://raw.githubusercontent.com//" url) then
+ ''-H "Authorization: Bearer "''
+ else
+ "";
+ in
+ pkgs.runCommandLocal "vendor-${name}"
+ {
+ buildInputs = [ pkgs.cacert ];
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+ outputHash = sha256;
+ } ''
+ # Empty URL special cased for example
+ mkdir --parents $out
+ if [ -n "${url}" ]; then
+ ${pkgs.curl}/bin/curl -s -S -L ${authorization} "${url}" | ${pkgs.libarchive}/bin/bsdtar -C $out -xf - --strip-components ${toString stripComponents}
+ fi
+ '';
+
+ libclang_rt_wasm32 = fetchVendor {
+ name = "libclang_rt_wasm32";
+ url = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/libclang_rt.builtins-wasm32-wasi-20.0.tar.gz";
+ sha256 = "AdRe1XrGeBuai1p5IMUTR7T7nhNlD1RZ8grZjVoHAKs=";
+ };
+
+ sdk_aarch64-unknown-linux-gnu = fetchVendor {
+ name = "sdk_aarch64-unknown-linux-gnu";
+ url = "https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/80fc74e431f37f590d0c85f16a9d8709088929e8/debian_bullseye_arm64_sysroot.tar.xz";
+ sha256 = "VwHx6SjTmnGWvEoevjThR2oxNEe9NIdnSIJ9RBgKPE8=";
+ };
+
+ sdk_universal-apple-darwin = fetchVendor {
+ name = "sdk_universal-apple-darwin";
+ url = ""; # User needs to supply.
+ sha256 = "pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; # User needs to supply.
+ };
+
+ sdk_universal-apple-ios = fetchVendor {
+ name = "sdk_universal-apple-ios";
+ url = ""; # User needs to supply.
+ sha256 = "pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; # User needs to supply.
+ };
+
+ sdk_universal-linux-android = android-nixpkgs.sdk."x86_64-linux" (sdkPkgs: with sdkPkgs; [
+ cmdline-tools-latest
+ build-tools-33-0-2
+ platform-tools
+ platforms-android-33
+ ndk-25-2-9519653
+ ]);
+
+ sdk_wasm32-wasi = fetchVendor {
+ name = "sdk_wasm32-wasi";
+ url = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sysroot-20.0.tar.gz";
+ sha256 = "aePDwDYWopPPDSO802BO3YWM4d/J4a4CmGP/hDPF8FY=";
+ };
+
+ sdk_x86_64-pc-windows-msvc = fetchVendor {
+ name = "sdk_x86_64-pc-windows-msvc";
+ url = ""; # User needs to supply.
+ sha256 = "pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; # User needs to supply.
+ };
+
+ sdk_x86_64-unknown-linux-gnu = fetchVendor {
+ name = "sdk_x86_64-unknown-linux-gnu";
+ url = "https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/f5f68713249b52b35db9e08f67184cac392369ab/debian_bullseye_amd64_sysroot.tar.xz";
+ sha256 = "+pqXDAsKY1BCBGFD3PDqMv1YiU+0/B2LXXryTFIUaWk=";
+ };
+
+ sdk_x86_64-unknown-nixos-gnu = pkgs.symlinkJoin {
+ name = "sdk_x86_64-unknown-nixos-gnu";
+ paths = [
+ llvm.libcxx.out
+ llvm.libcxx.dev
+ llvm.libcxxabi.out
+ llvm.libunwind.out
+ pkgs.gcc13.cc.libgcc.out
+ pkgs.gcc13.cc.libgcc.libgcc
+ pkgs.glibc.dev
+ pkgs.glibc.libgcc.out
+ pkgs.glibc.out
+ ];
+ };
+ in
+ {
+ packages."x86_64-linux".bazel = {
+ config = pkgs.writeTextFile {
+ name = "bazel-config";
+ destination = "/config.bzl";
+ text = ''
+ LLVM = "${llvm.bintools-unwrapped}"
+ CLANG = "${llvm.clang-unwrapped}"
+ CLANG_LIB = "${llvm.clang-unwrapped.lib}"
+ CLANG_LIB_VERSION = "16"
+
+ NIXOS_DYNAMIC_LINKER = "${pkgs.glibc.out}/lib64/ld-linux-x86-64.so.2"
+ LIBCLANG_RT_WASM32 = "${libclang_rt_wasm32}"
+ ANDROID_NDK_VERSION = "25.2.9519653"
+
+ SDK_AARCH64_UNKNOWN_LINUX_GNU = "${sdk_aarch64-unknown-linux-gnu}"
+ SDK_UNIVERSAL_APPLE_DARWIN = "${sdk_universal-apple-darwin}"
+ SDK_UNIVERSAL_APPLE_IOS = "${sdk_universal-apple-ios}"
+ SDK_UNIVERSAL_LINUX_ANDROID = "${sdk_universal-linux-android}"
+ SDK_WASM32_WASI = "${sdk_wasm32-wasi}"
+ SDK_X86_64_PC_WINDOWS_MSVC = "${sdk_x86_64-pc-windows-msvc}"
+ SDK_X86_64_UNKNOWN_LINUX_GNU = "${sdk_x86_64-unknown-linux-gnu}"
+ SDK_X86_64_UNKNOWN_NIXOS_GNU = "${sdk_x86_64-unknown-nixos-gnu}"
+ '';
+ };
+
+ rust = rust;
+ };
+ };
+}
diff --git a/examples/nix_cross_compiling/rust_binary/BUILD.bazel b/examples/nix_cross_compiling/rust_binary/BUILD.bazel
new file mode 100644
index 000000000..71368e7b1
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_binary/BUILD.bazel
@@ -0,0 +1,28 @@
+load("@rules_rust//rust:defs.bzl", "rust_binary")
+
+package(default_visibility = ["//visibility:public"])
+
+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"],
+ deps = [
+ "//cc_library",
+ "//rust_library",
+ "@crate_index//:anyhow",
+ ] + select({
+ "@platforms//os:none": [],
+ # To be removed once the `wasm32-wasi` version of `tokio` can `select()`
+ # over different features.
+ "@platforms//os:wasi": [],
+ "//conditions:default": [
+ "@crate_index//:tokio",
+ ],
+ }),
+)
diff --git a/examples/nix_cross_compiling/rust_binary/rust_binary.rs b/examples/nix_cross_compiling/rust_binary/rust_binary.rs
new file mode 100644
index 000000000..47cd9e0ef
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_binary/rust_binary.rs
@@ -0,0 +1,14 @@
+use anyhow::Result;
+
+use rust_library::rust_double_value;
+
+extern "C" { fn cc_double_value(value: i32) -> i32; }
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ println!("Hello World!");
+ println!("CC: {}", unsafe{ cc_double_value(5) });
+ println!("Rust: {}", rust_double_value(5));
+
+ Ok(())
+}
diff --git a/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-unknown-unknown.rs b/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-unknown-unknown.rs
new file mode 100644
index 000000000..b242ef0bc
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-unknown-unknown.rs
@@ -0,0 +1,17 @@
+use anyhow::Result;
+
+use rust_library::rust_double_value;
+
+extern "C" {
+ fn cc_double_value(value: i32) -> i32;
+}
+
+// `wasm32-unknown-unknown` is very barebones, so we don't have access to
+// printing or `tokio`, so we can't output anything or use `async main`,
+// but we can still call the functions.
+fn main() -> Result<()> {
+ unsafe { cc_double_value(5) };
+ rust_double_value(5);
+
+ Ok(())
+}
diff --git a/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-wasi.rs b/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-wasi.rs
new file mode 100644
index 000000000..8a51ea20e
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_binary/rust_binary_wasm32-wasi.rs
@@ -0,0 +1,22 @@
+use anyhow::Result;
+
+use rust_library::rust_double_value;
+
+extern "C" {
+ fn cc_double_value(value: i32) -> i32;
+}
+
+// `tokio` currently blocked on needing the `wasm32-wasi` version of `tokio`
+// to `select()` over different features.
+
+// `wasm32-wasi` has limited support for `tokio` presently, so we can use the
+// example but only with the single threaded executor.
+// #[tokio::main(flavor = "current_thread")]
+// async fn main() -> Result<()> {
+fn main() -> Result<()> {
+ println!("Hello World!");
+ println!("CC: {}", unsafe { cc_double_value(5) });
+ println!("Rust: {}", rust_double_value(5));
+
+ Ok(())
+}
diff --git a/examples/nix_cross_compiling/rust_library/BUILD.bazel b/examples/nix_cross_compiling/rust_library/BUILD.bazel
new file mode 100644
index 000000000..f7dee8cb8
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_library/BUILD.bazel
@@ -0,0 +1,19 @@
+load("@rules_rust//rust:defs.bzl", "rust_library", "rust_static_library")
+
+package(default_visibility = ["//visibility:public"])
+
+rust_library(
+ name = "rust_library",
+ srcs = ["rust_library.rs"],
+ tags = ["platform_missing"],
+ deps = [],
+)
+
+# CC needs to link against a Rust `staticlib` crate which includes
+# all the Rust `std` symbols.
+rust_static_library(
+ name = "rust_library_cc",
+ srcs = ["rust_library.rs"],
+ tags = ["platform_missing"],
+ deps = [],
+)
diff --git a/examples/nix_cross_compiling/rust_library/rust_library.rs b/examples/nix_cross_compiling/rust_library/rust_library.rs
new file mode 100644
index 000000000..f7b84d98b
--- /dev/null
+++ b/examples/nix_cross_compiling/rust_library/rust_library.rs
@@ -0,0 +1,4 @@
+#[no_mangle]
+pub fn rust_double_value(value: i32) -> i32 {
+ value * 2
+}
diff --git a/nix/BUILD.bazel b/nix/BUILD.bazel
new file mode 100644
index 000000000..e69de29bb
diff --git a/nix/README.md b/nix/README.md
new file mode 100644
index 000000000..691a21687
--- /dev/null
+++ b/nix/README.md
@@ -0,0 +1,9 @@
+# Nix
+
+Nix Flake that declares developer tools when executing in a Nix environment.
+
+This is kept in its own package so that when using the Nix `path:` syntax, only
+this directory is copied to the Nix Store instead of the entire `rules_rust`
+repository.
+
+See also: `//.direnv`
diff --git a/nix/flake.lock b/nix/flake.lock
new file mode 100644
index 000000000..f3c5cbdd9
--- /dev/null
+++ b/nix/flake.lock
@@ -0,0 +1,61 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1694529238,
+ "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1700444282,
+ "narHash": "sha256-s/+tgT+Iz0LZO+nBvSms+xsMqvHt2LqYniG9r+CYyJc=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "3f21a22b5aafefa1845dec6f4a378a8f53d8681c",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/nix/flake.nix b/nix/flake.nix
new file mode 100644
index 000000000..2c9547ea2
--- /dev/null
+++ b/nix/flake.nix
@@ -0,0 +1,25 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { self, nixpkgs, flake-utils, ... }:
+ flake-utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ in
+ {
+ devShells.default = pkgs.mkShell
+ {
+ packages = [
+ pkgs.bazel-buildtools
+ pkgs.bazel_6
+ pkgs.cargo
+ pkgs.rustc
+ pkgs.rustfmt
+ ];
+ };
+ });
+}
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index 481ef2569..d266815ab 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -1460,8 +1460,7 @@ def rustc_compile_action(
else:
providers.extend([crate_info, dep_info])
- if toolchain.target_arch != "wasm32":
- providers += establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration, interface_library)
+ providers += establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_configuration, interface_library)
output_group_info = {}