-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change allows `cc_binary()`, `cc_library()`, etc. targets to depend on `rust_libary()`, `rust_static_library()`, etc. targets when targeting `wasm32`.
- Loading branch information
1 parent
6874b8d
commit 0a4c4df
Showing
73 changed files
with
6,997 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ crate_universe | |
crate_universe_unnamed | ||
ios | ||
ios_build | ||
nix_cross_compiling | ||
zig_cross_compiling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Nix + Bazel Cross Compiling | ||
|
||
Blog Post: <https://blog.consumingchaos.com/posts/nix-bazel-cross-compiling/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
) |
Empty file.
Empty file.
Oops, something went wrong.