rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Error when compiling Rust on Aarch64 MacOS

Open tyb0807 opened this issue 1 year ago • 3 comments

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?

tyb0807 avatar Apr 10 '24 08:04 tyb0807

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?

illicitonion avatar Apr 10 '24 14:04 illicitonion

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:

  • https://github.com/uber/hermetic_cc_toolchain/issues/10
    • this shows that the OSX SDK isn't being picked up, and that the team isn't willing to pull from the host
  • https://github.com/ziglang/zig/issues/10299#issuecomment-2045669073
    • this shows that the SDK's are available from apple, so theoretically this could be integrated into the hermetic cc project if the macos toolchain is enabled ... or something

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.

DhashS avatar Jun 14 '24 06:06 DhashS

@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

marvin-hansen avatar Jun 24 '24 16:06 marvin-hansen