错误:无法为“ring v0.16.20”运行自定义构建命令

问题描述 投票:0回答:5

我想在带有 M1 芯片的 macOS Monterey 12.3.1 中使用 musl 构建 rust 1.59 项目,然后运行以下命令:

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

但是项目构建输出如下:

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

为什么会发生这种事?有可能解决这个问题吗?我应该怎么做才能解决这个问题?

rust rust-cargo alpine-linux musl
5个回答
12
投票

这很可能是因为您忘记安装了。

查看构建主机上是否有 musl-gcc。

$ musl-gcc

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

sudo apt install musl-tools

感谢mbergkvist


2
投票

我注意到您已标记“alpine-linux”,我假设您正在使用 alpine。

在这种情况下,要让 musl-gcc 按照其他评论者提到的方式工作,您需要

musl-dev

apk add --no-cache musl-dev

这就是我在 alpine 中解决我的确切问题的方法。

任何使用

rust:1-alpine
或类似镜像并面临相同问题的人,请将以下内容添加到您的 Dockerfile 中

RUN apk update && \
    apk upgrade

RUN apk add --no-cache musl-dev

0
投票

您应该能够使用以下命令运行

cargo build

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

参考:https://stackoverflow.com/a/70628855/132257


0
投票

Windows 修复:

rustup override set stable-msvc

事实证明,仅仅设置默认工具链是不够的,因为每次我运行 Cargo run 时,Cargo 都会安装 GNU 版本。


-1
投票

如果您使用的是 Windows,要解决此问题,您需要使用 WSL2。 在 wsl2 下运行

cargo build
,您的构建将会成功,不会出现任何问题。

© www.soinside.com 2019 - 2024. All rights reserved.