在 M1 上如何编译为 Linux 的包 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
horizon
V2EX    Rust

在 M1 上如何编译为 Linux 的包

  •  
  •   horizon 2023-03-08 13:01:09 +08:00 2890 次点击

    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_DFAULTS = 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     Solana     898 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 21:50 PVG 05:50 LAX 13:50 JFK 16:50
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86