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

5

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?

Cleareyed answered 1/6, 2022 at 11:31 Comment(4)
Are you trying to cross-compile your program (compile for a target which is different from the host), or are you just trying to run it locally?Grus
I am trying to cross compile, I just read the docs found it will be a little bit complex. I am still learning. I am not femiliar with these lib about musl. @JeremyMeadowsCleareyed
Any update on this? I have a similar problem. How did you continue?Horne
Ok, found it. Posted the answer below.Horne
H
16

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

Horne answered 28/6, 2022 at 19:22 Comment(2)
Building on Debian with musl-tools and then deploying on Alpine solved my problem. Thank youPick
is there a compatible tool on Windows?Tarsus
K
2

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
Killiecrankie answered 3/3, 2023 at 14:49 Comment(0)
A
1

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.

Abshier answered 10/10, 2023 at 1:35 Comment(0)
M
0

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://mcmap.net/q/664142/-rust-sorry-unimplemented-64-bit-mode-not-compiled-in

Monometallism answered 6/8, 2022 at 7:1 Comment(0)
U
-1

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.

Unweighed answered 3/9, 2022 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.