Search code examples
rustrust-cargo

Specify linker on the command line


I have such a cargo config:

[target.x86_64h-apple-darwin]
linker = "x86_64-apple-darwin14-clang"
ar = "x86_64-apple-darwin14-ar"

Please tell me how I can transfer these parameters to the command line.

cargo +nightly build -Z build-std <THESE PARAMS> --target x86_64h-apple-darwin

<THESE PARAMS> - here I somehow need to specify linker and ar.

All this in order to assemble the std for x86_64h-apple-darwin in my script...

Or maybe this can be done somehow using environment variables?..


Solution

  • I did it like this:

    MACOS_TARGET="x86_64-apple-darwin"
    cargo build --config "target.${MACOS_TARGET}.ar = 'x86_64-apple-darwin14-ar'" --config "target.${MACOS_TARGET}.linker = 'x86_64-apple-darwin14-clang'" --config "profile.release.strip = false"  ...
    

    https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides