在 M1 上如何编译为 Linux 的包

2023-03-08 13:01:09 +08:00
 horizon

RT 安装了 https://github.com/messense/homebrew-macos-cross-toolchains 似乎也不好使,有没有大佬帮帮我

2022 次点击
所在节点    Rust
15 条回复
liuxu
2023-03-08 18:12:29 +08:00
horizon
2023-03-09 09:20:54 +08:00
@liuxu
我的 target 为 x86_64-unknown-linux-gnu
给我报这个错误
https://imgur.com/a/yVuU169
horizon
2023-03-09 09:22:09 +08:00
[img][/img]
liuxu
2023-03-09 11:21:13 +08:00
horizon
2023-03-09 11:44:39 +08:00
@liuxu 感谢解答。
错误如下:
```
Caused by:
process didn't exit successfully: `/Users/linctex/Workspace/dufs/target/debug/build/ring-e3146748fc8e5aed/build-script-build` (exit status: 101)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("aarch64-apple-darwin")
cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
CC_x86_64-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
CC_x86_64_unknown_linux_gnu = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
RUSTC_LINKER = None
cargo:rerun-if-env-changed=CROSS_COMPILE
CROSS_COMPILE = None
cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
CFLAGS_x86_64-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
CFLAGS_x86_64_unknown_linux_gnu = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

--- stderr
running "x86_64-linux-gnu-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-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" "-DNDEBUG" "-c" "-o/Users/linctex/Workspace/dufs/target/x86_64-unknown-linux-gnu/debug/build/ring-574835f3f1e4e3d0/out/aesni-x86_64-elf.o" "/Users/linctex/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
thread 'main' panicked at 'failed to execute ["x86_64-linux-gnu-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-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" "-DNDEBUG" "-c" "-o/Users/linctex/Workspace/dufs/target/x86_64-unknown-linux-gnu/debug/build/ring-574835f3f1e4e3d0/out/aesni-x86_64-elf.o" "/Users/linctex/.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/linctex/.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...
```
liuxu
2023-03-09 12:01:53 +08:00
看上去是没有 x86_64_unknown_linux_gnu 编译工具链,rustup target list 看看你安装了没,没有就 rustup target add x86_64-unknown-linux-gnu 安装下
horizon
2023-03-09 12:27:47 +08:00
@liuxu [img][/img]
安装了的
liuxu
2023-03-09 17:03:20 +08:00
@horizon 我也是 M1 ,这个应该就是 CC_x86_64_unknown_linux_gnu 编译器和连接器不对的原因,依赖有问题的项目是 https://github.com/briansmith/ring
用 CC_x86_64_unknown_linux_gnu=clang cargo build...是可以过掉这个 aesni-x86_64-elf.S 文件编译的
还编译不过我感觉需要给 homebrew-macos-cross-toolchains 或者 briansmith/ring 发 issue
horizon
2023-03-09 17:17:42 +08:00
@liuxu 非常感谢
whoami9894
2023-03-09 17:25:04 +08:00
交叉编译 ring 这种非 pure Rust 项目需要对应的 cc 工具链,报错这么明显告诉你 x86_64-linux-gnu-gcc: No such file
horizon
2023-03-09 18:17:51 +08:00
@whoami9894 谢谢
horizon
2023-03-09 20:37:26 +08:00
@whoami9894 感谢,安装了 llvm 好了
horizon
2023-03-10 11:20:23 +08:00
再补充一下,可以在 cargo.toml 内设置 target 和 linker
[img][/img]
proxytoworld
2023-03-15 01:05:11 +08:00
这是编译成了 musl ,不是 gnu target
horizon
2023-03-15 09:01:34 +08:00
@proxytoworld
是的,我问题问错了,我是要 musl 的
哈哈,纯小白。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/922206

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX