Last active
November 2, 2021 01:19
-
-
Save ivan/1f78de3a4ebd78b6d2e145f70bbc75ed to your computer and use it in GitHub Desktop.
cargo wrapper script to use lld via RUSTFLAGS="-C link-arg=-fuse-ld=lld" for all projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# cargo wrapper to use lld on all projects, which is 2-4x faster to link than bfd: | |
# https://github.com/rust-lang/rust/issues/39915#issuecomment-538049306 | |
# Note that the advised `-C linker=clang` does not actually make it use lld. | |
# | |
# Place this into an executable ~/bin/cargo and edit the real cargo path at the | |
# end of the wrapper. Remove the nice and choom if not desired. | |
# | |
# You will also need to symlink a recent clang to ~/bin/cc so that -fuse-ld=lld works. | |
# | |
# If a project or any of its dependencies link to openssl, it will probably also need: | |
# openssl = { version = "0.10", features = [ "vendored" ] } | |
set -e | |
# Don't touch RUSTFLAGS when building wasm, because lld does not work. | |
# ("note: rust-lld: error: unknown argument: -fuse-ld=lld") | |
# | |
# Don't touch RUSTFLAGS if `-C link-arg=-fuse-ld=lld` is already in RUSTFLAGS, because | |
# otherwise `cargo clippy` builds with `-C link-arg=-fuse-ld=lld -C link-arg=-fuse-ld=lld` | |
# and spends a lot of time recompiling with "different" compiler options. | |
# | |
if [[ | |
" $* " != *" --target wasm32-unknown-unknown "* && | |
" $RUSTFLAGS " != *" -C link-arg=-fuse-ld=lld "* | |
]]; then | |
export RUSTFLAGS="-C link-arg=-fuse-ld=lld ${RUSTFLAGS:-}" | |
fi | |
# Make sure ~/bin is in PATH because it's the presumed location for the cc -> clang symlink. | |
# You can remove this if your cc is always clang by some other means. | |
if [[ :$PATH: != *:"$HOME/bin":* ]]; then | |
export PATH=$HOME/bin:$PATH | |
fi | |
exec nice -n 2 -- choom -n 750 -- /run/current-system/sw/bin/cargo "$@" |
@vporton let me know if you find a workaround. does global cargo configuration to set -C link-arg=-fuse-ld=lld
work?
@vporton let me know if you find a workaround. does global cargo configuration to set
-C link-arg=-fuse-ld=lld
work?
How to set it?
@vporton maybe something like
[build]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
in ~/.cargo/config
I've added the above mentioned config and it seems that cargo
uses ld
not lld
.
This lld-using wrapper is now obsoleted by the mold-using wrapper https://gist.github.com/ivan/594026bee196cb290764ca7af861b138
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It does not work for projects that build both native and WASM things.