From b0951b680501baebb9604e0ac496b748b6f10b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 20 Jan 2024 16:24:08 +0100 Subject: [PATCH] feat: use mold linker through crane --- templates/rust/.cargo/config.toml | 2 -- templates/rust/flake.nix | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) delete mode 100644 templates/rust/.cargo/config.toml diff --git a/templates/rust/.cargo/config.toml b/templates/rust/.cargo/config.toml deleted file mode 100644 index 4b929fe..0000000 --- a/templates/rust/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.x86_64-unknown-linux-gnu] -linker = "clang" diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index 3c67202..fc15b39 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -23,28 +23,36 @@ }; toolchain = fenix.packages.${system}.stable; craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain; + stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; in { - packages.default = + packages = let inherit (pkgs.lib) fileset; - in - craneLib.buildPackage { + without = fs: fileset.difference ./. fs; + nixFiles = fileset.unions [ ./flake.nix ./flake.lock ./.envrc ]; + gitFiles = fileset.gitTracked ./.; src = fileset.toSource { root = ./.; - fileset = fileset.intersection - (fileset.difference ./. - (fileset.unions [ ./.cargo ./flake.nix ./flake.lock ./.envrc ])) - (fileset.gitTracked ./.); + fileset = fileset.intersection (without nixFiles) gitFiles; }; + in + { + default = + craneLib.buildPackage { + inherit src stdenv; + }; }; devShell = pkgs.mkShell.override { - stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv; + inherit stdenv; } { - nativeBuildInputs = with toolchain; [ rustc cargo rust-analyzer clippy ]; + nativeBuildInputs = with toolchain; + [ rustc cargo rust-analyzer clippy ] ++ (with pkgs; + [ ] + ); }; }); }