开发者问题收集

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

2022-06-01
16172

我想在搭载 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

为什么会发生这种情况?有可能修复此问题吗?我应该怎么做才能修复此问题?

3个回答

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

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

感谢 mbergkvist

GRASBOCK
2022-06-28

我注意到您已标记“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
Anshul
2023-03-03

在 Windows 上,在项目目录中运行此命令:

rustup override set stable-msvc

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

Elijah
2023-10-10