From fd7f08a43cdd04242d75012daf683f526ddee389 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 7 Aug 2026 22:20:15 +0100 Subject: [PATCH] use nightly rust and improve dev build time --- Cargo.toml | 11 +++++++++++ flake.nix | 34 +++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 293921f..a38e912 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,17 @@ edition = "2021" name = "server" path = "src/main.rs" +[profile.dev] +debug = "line-tables-only" + +# We never step into dependencies, and their debuginfo dominates link time. +[profile.dev.package."*"] +debug = 0 + +[profile.debugging] +inherits = "dev" +debug = "full" + [dependencies] axum = "0.8" maud = { version = "0.27", features = ["axum"] } diff --git a/flake.nix b/flake.nix index 040c26b..80af8e7 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,19 @@ "clippy" ]; }; + devToolchain = pkgs.rust-bin.selectLatestNightlyWith ( + toolchain: + toolchain.default.override { + extensions = [ + "rust-src" + "rust-analyzer" + "clippy" + ] + ++ lib.optionals useCranelift [ "rustc-codegen-cranelift-preview" ]; + } + ); + useCranelift = pkgs.stdenv.hostPlatform.isx86_64 || pkgs.stdenv.hostPlatform.isAarch64; + useMold = pkgs.stdenv.isLinux; rustBuildInputs = [ pkgs.openssl pkgs.libiconv @@ -80,13 +93,24 @@ devShells.default = pkgs.mkShell { name = "starhaven-dev"; buildInputs = rustBuildInputs; - nativeBuildInputs = with pkgs; [ - rustToolchain - sqlx-cli - ]; + nativeBuildInputs = [ + devToolchain + pkgs.sqlx-cli + ] + ++ lib.optionals useMold [ pkgs.mold ]; shellHook = '' # For rust-analyzer 'hover' tooltips to work. - export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"; + export RUST_SRC_PATH="${devToolchain}/lib/rustlib/src/rust/library"; + + # parallel frontend stops paying off after 8 threads + rustc_threads=$(( $(nproc) < 8 ? $(nproc) : 8 )) + + export RUSTFLAGS="${lib.optionalString useMold "-Clink-arg=-fuse-ld=mold "}-Zthreads=$rustc_threads" + '' + + lib.optionalString useCranelift '' + export CARGO_UNSTABLE_CODEGEN_BACKEND=true + export CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift + export CARGO_PROFILE_DEBUGGING_CODEGEN_BACKEND=llvm ''; }; }; -- 2.51.2