From 3736cfc5abbdd63532f4901729731f4e8d9b0496 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 13 Apr 2025 14:21:51 +0200 Subject: [PATCH] update nix & project files to use mold --- .cargo/config.toml | 11 +++++++++++ Cargo.toml | 4 ---- shell.nix | 10 +++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..38354f6 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,11 @@ +# Target specification ensures these settings apply only when building for this architecture. +[target.x86_64-unknown-linux-gnu] + +# Tell rustc to use 'clang' (from nativeBuildInputs) as the linker driver. +linker = "clang" + +# Pass flags to rustc (-C flag). +# 'link-arg' passes the subsequent argument directly to the linker driver ('clang'). +# '-fuse-ld=mold' tells clang to use the 'mold' executable as the actual linker. +# Nix ensures the 'mold' found in PATH is the wrapped version from 'mold-wrapped'. +rustflags = ["-C", "link-arg=-fuse-ld=mold"] diff --git a/Cargo.toml b/Cargo.toml index 36c1991..157e0ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,3 @@ inherits = "release" opt-level = "s" # Strip all debugging information from the binary to slightly reduce file size. strip = "debuginfo" - -[target.x86_64-unknown-linux-gnu] -linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] diff --git a/shell.nix b/shell.nix index 943656c..a359f59 100644 --- a/shell.nix +++ b/shell.nix @@ -1,15 +1,23 @@ -{ pkgs ? import { } }: +{ pkgs? import { } }: with pkgs; mkShell rec { + # Tools needed to build the project nativeBuildInputs = [ pkg-config + # Add the wrapped mold linker + mold-wrapped + # Add clang, needed to drive mold via -fuse-ld= + llvmPackages.clang # Or just `clang` ]; + + # Libraries the project links against or needs at runtime buildInputs = [ udev alsa-lib vulkan-loader xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature libxkbcommon wayland # To use the wayland feature ]; + LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; }