Skip to content

Commit

Permalink
feat(flake): enable lld as linker in all builds except wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron committed Nov 27, 2024
1 parent 47b8e5c commit a0354e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
2 changes: 1 addition & 1 deletion flake-modules/devshell/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ localFlake: { ... }: {
# dependencies for local rust builds
pkg-config
openssl
gcc
clang lld # faster linking + gcc for some crates
];

motd = "\n Welcome to the {2}picturepro{reset} dev shell. Run {1}menu{reset} for commands.\n";
Expand Down
18 changes: 10 additions & 8 deletions flake-modules/rust-builds/leptos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
inherit (rust-workspace.workspace-base-args) src;
inherit (rust-toolchain) craneLib;

# get the leptos options from the Cargo.toml
workspace-cargo-manifest = builtins.fromTOML (builtins.readFile ../../Cargo.toml);
leptos-options = builtins.elemAt workspace-cargo-manifest.workspace.metadata.leptos 0;

# get the style node_modules for the frontend
js2nix = pkgs.callPackage (pkgs.fetchgit {
url = "https://github.com/canva-public/js2nix";
hash = "sha256-Bmv0ERVeb6vjYzy4MuCDgSiz9fSm/Bhg+Xk3AxPisBw=";
}) { };
style-root = ../../crates/site-app/style/tailwind;

style-node-env = (js2nix {
package-json = style-root + "/package.json";
yarn-lock = style-root + "/yarn.lock";
}).nodeModules;

# options for both the frontend and server builds
common-args = {
inherit src;
pname = leptos-options.bin-package;
version = "0.1.0";

doCheck = false;

nativeBuildInputs = [
pkgs.pkg-config
pkgs.binaryen # provides wasm-opt for cargo-leptos
] ++ pkgs.lib.optionals (system == "x86_64-linux") [
nativeBuildInputs = (with pkgs; [
pkg-config
binaryen # provides wasm-opt for cargo-leptos
clang lld
]) ++ pkgs.lib.optionals (system == "x86_64-linux") [
pkgs.nasm # wasm compiler only for x86_64-linux
];
buildInputs = [
];
buildInputs = [ ];
};
# build the deps for the frontend bundle, and export the target folder
site-frontend-deps = craneLib.mkCargoDerivation (common-args // {
Expand Down Expand Up @@ -78,7 +80,7 @@
./crates/site-app/style/tailwind/node_modules
'';

# enable hash_files again
# enable hash_files again, so we generate `hash.txt`
buildPhaseCargoCommand = ''
LEPTOS_HASH_FILES=true cargo leptos build --release -vvv
'';
Expand Down
2 changes: 1 addition & 1 deletion flake-modules/rust-builds/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# inputs assumed to be relevant for all crates
nativeBuildInputs = with pkgs; [
pkg-config
pkg-config clang lld
];
buildInputs = [ ];
};
Expand Down

0 comments on commit a0354e4

Please sign in to comment.