Dolphin
Dolphin

Reputation: 38895

error: failed to run custom build command for `ring v0.16.20`

I want to build rust 1.59 project with musl in macOS Monterey 12.3.1 with M1 chip, then I run this command:

rustup target add x86_64-unknown-linux-musl
cargo build --release --target=x86_64-unknown-linux-musl

but the project build output like this:

error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/Users/foo/source/reddwarf/backend/fortune/target/release/build/ring-98ce1debbcda4321/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-musl")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-unknown-linux-musl = None
  CC_x86_64_unknown_linux_musl = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-unknown-linux-musl = None
  CFLAGS_x86_64_unknown_linux_musl = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/Users/foo/source/reddwarf/backend/fortune/target/x86_64-unknown-linux-musl/release/build/ring-a5403edcb6d58bf6/out/aesni-x86_64-elf.o" "/Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
  thread 'main' panicked at 'failed to execute ["musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/Users/foo/source/reddwarf/backend/fortune/target/x86_64-unknown-linux-musl/release/build/ring-a5403edcb6d58bf6/out/aesni-x86_64-elf.o" "/Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"]: No such file or directory (os error 2)', /Users/foo/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

why did this happen? is it possible to fix this problem? what should I do to fixed this problem?

Upvotes: 21

Views: 18760

Answers (5)

Elijah
Elijah

Reputation: 2203

On Windows run this in the project dir:

rustup override set stable-msvc

Turns out, simply setting default toolchain was not enough as cargo would install the gnu version every time I ran cargo run.

Upvotes: 1

Anshul
Anshul

Reputation: 106

I noticed that you've tagged "alpine-linux", I will assume you're using alpine.

In that case to get musl-gcc to work as mentioned by other commenter you'll need musl-dev package

apk add --no-cache musl-dev

This is how I solved my exact problem in alpine.

Anyone who is using the rust:1-alpine or similar image and facing the same issue, add the following to your Dockerfile

RUN apk update && \
    apk upgrade

RUN apk add --no-cache musl-dev

Upvotes: 2

TDH
TDH

Reputation: 9

If you are on Windows, to solve this issue you need to be using WSL2. Run cargo build under wsl2 and your build will succeed without problems.

Upvotes: -1

xpepermint
xpepermint

Reputation: 36263

You should be able to run cargo build with the commands below:

$ alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
$ rust-musl-builder cargo build --release

Ref: https://stackoverflow.com/a/70628855/132257

Upvotes: 0

GRASBOCK
GRASBOCK

Reputation: 737

This is because most likely you forgot to install.

See if you have musl-gcc on the build host.

$ musl-gcc

Command 'musl-gcc' not found, but can be installed with:

sudo apt install musl-tools

Thanks to mbergkvist

Upvotes: 17

Related Questions