Skip to content

Commit 860547f

Browse files
authored
config to switch linker to mold for linux target (#51)
* config to switch linker to mold for linux target 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. * add mold to github actions config 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 * change mold path to /usr/local/bin/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. * change linker flag from --ld-path to -fuse-ld 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. Co-authored-by: Abhishek Cherath <[email protected]>
1 parent d1ae1f1 commit 860547f

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[target.x86_64-unknown-linux-gnu]
2+
linker = "/usr/bin/clang"
3+
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v3
18+
- uses: rui314/setup-mold@v1
1819
- uses: Swatinem/rust-cache@v1
1920
with:
2021
cache-on-failure: true

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v3
18+
- uses: rui314/setup-mold@v1
1819
- uses: Swatinem/rust-cache@v1
1920
with:
2021
cache-on-failure: true

0 commit comments

Comments
 (0)