bazelbuild / bazelbuild/rules_rust

Document how to do cross-compilation

Open
#276 17 comments 2 reactions 0 assignees View on GitHub
help wanted needs-triage question
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

The readme mentions how to cross compile for wasm, but doesn't explain cross compilation for any other platforms.

I am using rules_rust in conjunction with rules_docker and would like to compile with macOS as the host, targeting linux. Currently, without modifications, the docker image is build for macOS and fails on launch:

```
standard_init_linux.go:211: exec user process caused "exec format error"
```

My current attempt adds an entry to the .bazelrc file which specifies the platform for the image target.

```
build:image --platforms=//server:docker_platform
```

The platform is defined as such:

```
platform(
name = "docker_platform",
constraint_values = [
"@platforms//os:linux",
]
)
```

The error on build is

```
ERROR: While resolving toolchains for target //server:image_binary: no matching toolchains found for types @io_bazel_rules_rust//rust:toolchain
ERROR: Analysis of target '//server:image' failed; build aborted: no matching toolchains found for types @io_bazel_rules_rust//rust:toolchain
INFO: Elapsed time: 0.152s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 146 targets configured)
```

### Edit

I have loaded a custom toolchain in the WORKSPACE which seems like a step in the right direction but I am still hitting the same error.

```
rust_repository_set(
name = "rust_darwin_x86_64",
exec_triple = "x86_64-apple-darwin",
extra_target_triples = ["x86_64-unknown-linux-gnu"],
version = "1.39.0",
)
```

And updated .bazelrc, having tried both `@io_bazel_rules_rust//rust/platform:linux` and `//server:docker_platform` for the platforms argument

```
build:image --extra_toolchains=@rust_darwin_x86_64_toolchains//:toolchain_for_x86_64-unknown-linux-gnu --platforms=...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.