Skip to content

Commit

Permalink
feat: add support for mold using an env variable (#13)
Browse files Browse the repository at this point in the history
add support for mold using an env variable

Signed-off-by: lee-orr <[email protected]>
  • Loading branch information
lee-orr authored Sep 6, 2023
1 parent f3e85a8 commit 57ea6dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions dexterous_developer_internal/src/hot/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,24 @@ mod linux_host {
use super::*;
pub struct DefaultProvider;

#[cfg(target_arch = "aarch64")]
const LINKER_VAR: &str = "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER";

#[cfg(not(target_arch))]
const LINKER_VAR: &str = "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER";

impl BuildArgsProvider for DefaultProvider {
fn set_env_vars(&self, command: &mut Command) {
command
.env("RUSTC_LINKER", "clang")
.env("RUSTFLAGS", "-Zshare-generics=y -Clink-arg=-fuse-ld=lld");
if let Ok(ld_path) = std::env::var("DEXTEROUS_DEVELOPER_LD_PATH") {
command.env(LINKER_VAR, "clang").env(
"RUSTFLAGS",
format!("-Zshare-generics=y -Clink-arg=-fuse-ld={ld_path}"),
);
} else {
command
.env(LINKER_VAR, "clang")
.env("RUSTFLAGS", "-Zshare-generics=y -Clink-arg=-fuse-ld=lld");
}
}
}

Expand Down Expand Up @@ -152,7 +165,7 @@ mod windows_host {
impl BuildArgsProvider for DefaultProvider {
fn set_env_vars(&self, command: &mut Command) {
command
.env("RUSTC_LINKER", "rust-lld.exe")
.env("CARGO_TARGET_x86_64_PC_WINDOWS_MSVC_LINKER", "rust-lld.exe")
.env("RUSTFLAGS", "-Zshare-generics=n");
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- [Adding Reloadables to your Plugins](reloadables.md)
- [CLI](cli.md)
- [Running Without the CLI](no_cli.md)
- [Mold and Alternative Liners](mold.md)
3 changes: 3 additions & 0 deletions docs/src/mold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mold and Alternative Linkers

When running on Linux, and not cross-compiling, you can pass in alternative linkers like mold using the `DEXTEROUS_DEVELOPER_LD_PATH` environment variable. The value then gets inserted as `link-arg=-fuse-ld={DEXTEROUS_DEVELOPER_LD_PATH}` in the rustc compiler arguments.

0 comments on commit 57ea6dc

Please sign in to comment.