-
Notifications
You must be signed in to change notification settings - Fork 41
config to switch linker to mold for linux target #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PROBLEM: dev hot-rebuilds currently take ~10s on a 4c8t intel laptop from circa 2017. (rustc 1.61.0) SOLUTION: After switching to mold, this time drops to ~3.5s. FURTHER INFORMATION: Profiling via rustc --self-profile reveals that most of the time for a hot reload comes from linking. mold is a faster linker than lld or ld. POSSIBLE IMPROVEMENTS: Switching to rust nightly (currently 1.63.0) yield further 20-30% improvements.
PROBLEM: unit tests and integration tests error out because mold not installed on gh actions machines SOLUTION: Use Rui Ueyama's first party github action https://github.com/rui314/setup-mold
PROBLEM: Ueyama's gh action installs mold to /usr/local/bin/mold whereas cargo configured to look for it at /usr/bin/mold SOLUTION: change cargo path to /usr/local/bin/mold POSSIBLE IMPROVEMENTS: I really wish it was possible to have the config file include macros somehow. (so something like /usr/bin/env mold, or which mold), but that doesn't seem feasible without having a config generator which seems excessive for just this, but might be good if there's more dynamic configuration in the future.
.cargo/config.toml
Outdated
@@ -0,0 +1,3 @@ | |||
[target.x86_64-unknown-linux-gnu] | |||
linker = "/usr/bin/clang" | |||
rustflags = ["-C", "link-arg=--ld-path=/usr/local/bin/mold"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be:
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, it's deprecated, but is fine for now. esp considering stuff like this
rust-lang/rust#94347
PROBLEM: gh-actions clang is old and does not support --ld-path SOLUTION: switch to deprecated -fuse-ld NOTES: I suspect that the rust project will switch to mold as default linker for linux before we have to worry about changing this path anyhow.
OK that should be good. In the future, or if we decide to switch to nightly, something like this might be worthwhile: https://github.com/dimensionhq/fleet |
This reverts commit 860547f. PROBLEM: messes up docker push SOLUTION: remove linker switch NOTE: issues mentioned in 86054 still apply, and will be addressed in this PR.
* Revert "config to switch linker to mold for linux target (#51)" This reverts commit 860547f. PROBLEM: messes up docker push SOLUTION: remove linker switch NOTE: issues mentioned in 86054 still apply, and will be addressed in this PR. * add fast_build script that runs cargo build with the mold linker PROBLEM: as mentioned in 86054, hot-reloads take around 10s, mostly due to linker. SOLUTION: use mold, this time via a fast_build script that sets the necessary cargo env vars, ensures that mold and clang are installed, and runs cargo build with the correct path for the mold linker. POSSIBLE IMPROVEMENTS: may be a good idea to switch the shell script for a zx script. Also would be nice if `cargo build` automatically ran fast_build.sh as a wrapper if the host and profile are correct (ie. linux host, with dev profile) * CLEANUP: remove .cargo from dockerignore Co-authored-by: Abhishek Cherath <[email protected]>
PROBLEM:
dev hot-rebuilds currently take ~10s on a 4c8t intel laptop
from circa 2017. (rustc 1.61.0)
SOLUTION:
After switching to mold, this time drops to ~3.5s.
FURTHER INFORMATION:
Profiling via rustc --self-profile reveals that most of the time
for a hot reload comes from linking. mold is a faster linker than
lld or ld.
POSSIBLE IMPROVEMENTS:
Switching to rust nightly (currently 1.63.0) yield further 20-30%
improvements.