bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
667 stars 431 forks source link

Error when compiling Rust on Aarch64 MacOS #2611

Open tyb0807 opened 7 months ago

tyb0807 commented 7 months ago

Hi,

I'm very new to the field, so please let me know if the information I communicate here is useful enough for debugging.

I have the following dependency in MODULE.bazel

bazel_dep(name = "rules_rust", version = "0.41.1")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
    edition = "2024",
    versions = ["1.77.2"],
)
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")

When running a simple blaze test command, I get the following error (I've omitted the more verbose parts):

ERROR: .../external/rules_rust~/util/process_wrapper/BUILD.bazel:31:36: Compiling Rust (without process_wrapper) bin process_wrapper (6 files) [for tool] failed: (Exit 1): sandbox-exec failed: error executing Rustc command 
  ...
error: linking with `external/zig_sdk/tools/aarch64-macos-none/c++` failed: exit status: 1
  |
  = note: env -u ...
  = note: error: unable to find dynamic system library 'resolv' using strategy 'paths_first'. searched paths: ...

Does anybody know what's happening here, and how to fix this please?

illicitonion commented 7 months ago

Welcome, and thanks for the issue! If you can post a full git repo we can clone and run, that'd help to be able to debug. It looks like you're wiring up a zig C++ toolchain?

DhashS commented 4 months ago

I'm also seeing this (albeit with a WORKSPACE based config) when trying to use zig to make a hermetic cc toolchain work. The core of the issue seems to be the fact that a hermetic cc_toolchain kinda by definition needs to not depend on the host -- generally where one receives the host SDK from.

The relevant issue are these ones:

This really only crops up if you try and go full hermetic with BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 since otherwise the host sysroot is picked up via probably some xcrun shenanigans.

Until then (or until the rules_rust team drops https://github.com/bazelbuild/rules_rust/blob/67b3571d7e5e341de337317d84a6bec6b9d02ed7/rust/platform/triple_mappings.bzl#L180 this line) it'll be impossible to compile with a no-host hermetic CC toolchain since the don't detect host toolchain thing is an --action_env thing, which makes it global in a way that i'm unable to see how to specifically exclude rules_rust from.

marvin-hansen commented 4 months ago

@DhashS consider trying a LLVM toolchain setup with sysroot as it usually creates less fuzz.

See this example: https://github.com/marvin-hansen/examples/tree/main/rust-tutorial/01-hello-clang

For a LLVM with sysroot, see the cross compile example: https://github.com/marvin-hansen/examples/tree/main/rust-tutorial/02-hello-cross