Skip to content

Commit

Permalink
Implement Local Remote Execution for Rust
Browse files Browse the repository at this point in the history
This change implements ~40 Rust toolchains that reuse Nix's executables
and make them available via Bazel.

The new setup is fully reproducible, supports musl and glibc and
works from all nix-supported hosts to all sensible crosscompilation
targets seamlessly through remote and local execution.

For instance, you can now run this command on a MacOS host to build a
statically linked executable for x86_64-linux on a remote arm worker:

```bash
bazel build \
    nativelink \
    --extra_execution_platforms=@local-remote-execution//lre-rs:aarch64-unknown-linux-gnu \
    --platforms=@local-remote-execution//lre-rs:x86_64-unknown-linux-musl
```
  • Loading branch information
aaronmondal committed Dec 2, 2024
1 parent 1b7d059 commit 1be0c4e
Show file tree
Hide file tree
Showing 17 changed files with 1,540 additions and 103 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ bazel-testlogs
bazel-nativelink
local-remote-execution/generated-cc
local-remote-execution/generated-java
local-remote-execution/lre-rs
44 changes: 26 additions & 18 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module(

bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_python", version = "0.36.0")
bazel_dep(name = "rules_python", version = "0.40.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
Expand All @@ -20,6 +20,12 @@ use_repo(python, python = "python_versions")

bazel_dep(name = "rules_rust", version = "0.54.1")

# TODO(aaronmondal): REMOVE
local_path_override(
module_name = "rules_rust",
path = "../rules_rust",
)

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
Expand All @@ -40,19 +46,19 @@ rust.toolchain(
"2024-11-23/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz": "ac2a8fff891473220d36c9e62afc2dc0d5aebaefbb8489584bd2446a37d6fd7b",
},
versions = [
"1.82.0",
"nightly/2024-11-23",
# "1.82.0",
# "nightly/2024-11-23",
],
)

rust_host_tools = use_extension(
"@rules_rust//rust:extension.bzl",
"rust_host_tools",
)
rust_host_tools.host_tools(
edition = "2021",
version = "1.82.0",
)
# rust_host_tools = use_extension(
# "@rules_rust//rust:extension.bzl",
# "rust_host_tools",
# )
# rust_host_tools.host_tools(
# edition = "2021",
# version = "1.82.0",
# )

use_repo(rust, "rust_toolchains")

Expand All @@ -64,23 +70,25 @@ crate.from_cargo(
supported_platform_triples = [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"arm-unknown-linux-gnueabi",
"armv7-unknown-linux-gnueabi",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
],
)
use_repo(crate, "crates")

rust_analyzer = use_extension(
"@rules_rust//tools/rust_analyzer:extension.bzl",
"rust_analyzer_dependencies",
)
rust_analyzer.rust_analyzer_dependencies()
# rust_analyzer = use_extension(
# "@rules_rust//tools/rust_analyzer:extension.bzl",
# "rust_analyzer_dependencies",
# )
# rust_analyzer.rust_analyzer_dependencies()

bazel_dep(name = "protobuf", version = "27.5", repo_name = "com_google_protobuf")
bazel_dep(name = "toolchains_protoc", version = "0.3.3")
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")
bazel_dep(name = "toolchains_protoc", version = "0.3.4")

protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
protoc.toolchain(
Expand Down
Loading

0 comments on commit 1be0c4e

Please sign in to comment.