diff --git a/home/Projects/optimized-pre-config-rust/.cargo/config.toml b/home/Projects/optimized-pre-config-rust/.cargo/config.toml deleted file mode 100644 index 833fb84..0000000 --- a/home/Projects/optimized-pre-config-rust/.cargo/config.toml +++ /dev/null @@ -1 +0,0 @@ -rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold", "-Z", "threads=8" ] # Change '/path/to/mold', use with nightly version of Rust diff --git a/home/Projects/optimized-pre-config-rust/Cargo.toml b/home/Projects/optimized-pre-config-rust/Cargo.toml index 46f0188..241f051 100644 --- a/home/Projects/optimized-pre-config-rust/Cargo.toml +++ b/home/Projects/optimized-pre-config-rust/Cargo.toml @@ -1,8 +1,8 @@ ### Cargo code snippets for different optimizations ## Dev build compilation speed optimization (more https://benw.is/posts/how-i-improved-my-rust-compile-times-by-seventy-five-percent) -# Work only with nightly version of Rust by the time when it was written, also DON'T use it in production for now -cargo-features = ["codegen-backend"] +# Work only with the nightly version of Rust by the time it was written; it is recommended NOT to use it in production for now +cargo-features = [ "codegen-backend", "profile-rustflags" ] # Important: It provides less useful error messages during compilation [profile.dev] opt-level = 1 @@ -11,10 +11,17 @@ codegen-backend = "cranelift" opt-level = 3 codegen-backend = "cranelift" +[profile.dev.build-override] +rustflags = [ "-Z", "threads=8", "-C", "link-arg=-fuse-ld=/run/current-system/sw/bin/mold" ] # `/run/current-system/sw/bin/mold` is an absolute path to the mold executable + ## Release build size optimization (more https://github.com/johnthagen/min-sized-rust) +# You can also use programs such as `upx` for size optimization [profile.release] strip = true -opt-level = "z" # Also can try 's' instead of 'z' +opt-level = "z" # You can try 's' instead of 'z' if you want to optimize for speed lto = true codegen-units = 1 -panic = "abort" +panic = "abort" # DELETE extra unwinding code that provides helpful backtrace information for runtime errors + +[profile.release.build-override] +rustflags = [ "-Z", "location-detail=none" ] # DELETE a useful traceback information such as file, line, and column information for panic!() and [track_caller] diff --git a/home/Projects/optimized-pre-config-rust/flake.lock b/home/Projects/optimized-pre-config-rust/flake.lock new file mode 100644 index 0000000..d512402 --- /dev/null +++ b/home/Projects/optimized-pre-config-rust/flake.lock @@ -0,0 +1,130 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701253981, + "narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1701397143, + "narHash": "sha256-nYUJxZXwCWWVBYZXPgRxGDuQcZRhKTtD/Jp5Jl+9EWU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "bb71557c93cad40f5921b2342d7fd69f9e6497ab", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/home/Projects/optimized-pre-config-rust/flake.nix b/home/Projects/optimized-pre-config-rust/flake.nix index 5805233..7c82522 100644 --- a/home/Projects/optimized-pre-config-rust/flake.nix +++ b/home/Projects/optimized-pre-config-rust/flake.nix @@ -7,7 +7,7 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + outputs = { nixpkgs, rust-overlay, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; @@ -19,12 +19,11 @@ { devShells.default = mkShell { buildInputs = [ + just (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml) mold - pkg-config - openssl - sqlite cargo-deny + cargo-watch cargo-audit cargo-update cargo-edit @@ -37,9 +36,13 @@ cargo-spellcheck cargo-modules cargo-bloat + cargo-unused-features taplo bacon helix + pkg-config + openssl + sqlite ]; }; } diff --git a/home/Projects/optimized-pre-config-rust/justfile b/home/Projects/optimized-pre-config-rust/justfile new file mode 100644 index 0000000..23fbc1c --- /dev/null +++ b/home/Projects/optimized-pre-config-rust/justfile @@ -0,0 +1,42 @@ +set export + +set shell := ["fish", "-c"] + +alias w := watch +alias b := build +alias r := release +alias l := lint +alias t := test +alias c := coverage + +# run `just --list` for project +default: + just --list + +# run `cargo watch` for project +watch: + cargo watch + +# run `cargo build` for project +build: + cargo build + +# run `cargo build --release` for project +release: test + cargo build --release + +# run `cargo zigbuild --target {target} --release` for project +cross target: test + cargo zigbuild --target $target --release + +# run `cargo clippy` for project +lint: + cargo clippy + +# run `carog nextest run` for project +test: + cargo nextest run + +# run `cargo tarpaulin` for project +coverage: + cargo tarpaulin