V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
horizon
V2EX  ›  Rust

在 M1 上如何编译为 Linux 的包

  •  
  •   horizon · 2023-03-08 13:01:09 +08:00 · 2269 次点击
    这是一个创建于 636 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    15 条回复    2023-03-15 09:01:34 +08:00
    liuxu
        1
    liuxu  
       2023-03-08 18:12:29 +08:00
    horizon
        2
    horizon  
    OP
       2023-03-09 09:20:54 +08:00
    @liuxu
    我的 target 为 x86_64-unknown-linux-gnu
    给我报这个错误
    https://imgur.com/a/yVuU169
    horizon
        3
    horizon  
    OP
       2023-03-09 09:22:09 +08:00
    [img][/img]
    liuxu
        4
    liuxu  
       2023-03-09 11:21:13 +08:00
    horizon
        5
    horizon  
    OP
       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
        6
    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
        7
    horizon  
    OP
       2023-03-09 12:27:47 +08:00
    @liuxu [img][/img]
    安装了的
    liuxu
        8
    liuxu  
       2023-03-09 17:03:20 +08:00   ❤️ 1
    @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
        9
    horizon  
    OP
       2023-03-09 17:17:42 +08:00
    @liuxu 非常感谢
    whoami9894
        10
    whoami9894  
       2023-03-09 17:25:04 +08:00
    交叉编译 ring 这种非 pure Rust 项目需要对应的 cc 工具链,报错这么明显告诉你 x86_64-linux-gnu-gcc: No such file
    horizon
        11
    horizon  
    OP
       2023-03-09 18:17:51 +08:00
    @whoami9894 谢谢
    horizon
        12
    horizon  
    OP
       2023-03-09 20:37:26 +08:00
    @whoami9894 感谢,安装了 llvm 好了
    horizon
        13
    horizon  
    OP
       2023-03-10 11:20:23 +08:00
    再补充一下,可以在 cargo.toml 内设置 target 和 linker
    [img][/img]
    proxytoworld
        14
    proxytoworld  
       2023-03-15 01:05:11 +08:00   ❤️ 1
    这是编译成了 musl ,不是 gnu target
    horizon
        15
    horizon  
    OP
       2023-03-15 09:01:34 +08:00
    @proxytoworld
    是的,我问题问错了,我是要 musl 的
    哈哈,纯小白。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1395 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 17:38 · PVG 01:38 · LAX 09:38 · JFK 12:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.