Error: failed to run custom build command for `libc v0.2.150`

Hi! I'm learning Rust and async connection pooling with bb8. Building this project fails:

error: failed to run custom build command for `libc v0.2.150`

Caused by:
  process didn't exit successfully: `.../rust_libc_build_failure/target/debug/build/libc-4f9e2b02a856699f/build-script-build` (exit status: 101)
  --- stdout

  --- stderr
  thread 'main' panicked at .../.cargo/registry/src/
  failed to run rustc: 
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

What's wrong? Can you build it?

The environment:

  • macOS 13.6.1, Apple Silicon M2
  • cargo 1.74.0 (ecb9851af 2023-10-18)
  • rustc 1.74.0 (79e9716c9 2023-11-13)

Looks like it fails to run $RUSTC --version (where $RUSTC is set by cargo to point to the rustc it uses). This should work just fine. Can you provide some more details about your environment? Are you using an x86_64 or arm64 rustc and cargo? Are you using rustup? What is the content of the PATH env var?

I ignored bb8 and pushed to master the version with libc = "0.2.150" as its only dependency.

Are you using an x86_64 or arm64 rustc and cargo?

Both of these have now been tested:

  • cargo build --target aarch64-apple-darwin
  • cargo build --target x86_64-apple-darwin

No luck.

Are you using rustup?

Yes, I do.

What is the content of the PATH env var?

I tested with another user account with a shorter PATH:

% echo $PATH | tr ':' '\n'

Still no luck.

There seems to be a Tracking issue for supporting macOS on Apple Silicon.

I meant which arch rustc itself is compiled for. rustc -vV should show this behind the host field.

It was aarch64-apple-darwin. I switched now to x86_64-apple-darwin by running and chaging default host triple. For some reason cargo build does nothing but dies after 54 seconds:

% time cargo build                                              
error: process didn't exit successfully: `/Users/u0/.rustup/toolchains/stable-x86_64-apple-darwin/bin/rustc -vV` (signal: 9, SIGKILL: kill)
cargo build  0.04s user 0.02s system 0% cpu 54.265 total

SIGKILL can be caused by memory exhaustion. Could you take a look at the resource monitor if there is still free memory when rustc gets killed? It would be pretty weird if rustc -vV causes memory exhaustion though. It barely allocates memory.

During cargo build there's barely no change in the command top output:

SharedLibs: 557M resident, 124M data, 53M linkedit.
MemRegions: 664581 total, 5053M resident, 338M private, 5487M shared.
PhysMem: 20G used (3078M wired, 3657M compressor), 3162M unused.
VM: 391T vsize, 4285M framework vsize, 109702(0) swapins, 286430(0) swapouts.

Here's Activity Monitor during cargo build:

I'm afraid I have no clue what could be going on here. aarch64-apple-darwin rustc is the most likely to work on Apple Silicon as it doesn't use Rosetta 2. But that was exactly where your original issue came from.

I created an issue: Failed to run custom build command for `libc v0.2.150` on macOS Apple silicon (aarch64-apple-darwin) · Issue #118309 · rust-lang/rust · GitHub

After restarting the computer and trying to compile again F-Secure security appliance asked for permission to running build-script-build. After granting permission, libc got compiled fine. Case closed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.