nix: improve RUSTFLAGS + add overlay

This commit is contained in:
seth 2024-03-31 19:56:13 -04:00
parent 0b0779f8b7
commit 5cfb079e35
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
4 changed files with 22 additions and 13 deletions

View file

@ -47,9 +47,3 @@ pedantic = "warn"
perf = "warn" perf = "warn"
style = "warn" style = "warn"
suspicious = "deny" suspicious = "deny"
[profile.release]
codegen-units = 1
opt-level = "s"
panic = "abort"
strip = "symbols"

View file

@ -28,7 +28,7 @@
buildWith = rustPlatform: buildWith = rustPlatform:
self'.packages.refraction.override { self'.packages.refraction.override {
inherit rustPlatform; inherit rustPlatform;
lto = true; optimizeSize = true;
}; };
in { in {
packages = packages =

View file

@ -4,7 +4,8 @@
rustPlatform, rustPlatform,
darwin, darwin,
self, self,
lto ? false, lto ? true,
optimizeSize ? false,
}: }:
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "refraction"; pname = "refraction";
@ -35,11 +36,22 @@ rustPlatform.buildRustPackage {
SystemConfiguration SystemConfiguration
]); ]);
env = { env = let
CARGO_BUILD_RUSTFLAGS = lib.concatStringsSep " " ( toRustFlags = lib.mapAttrs' (
lib.optionals lto ["-C" "lto=thin" "-C" "embed-bitcode=yes" "-Zdylib-lto"] name:
lib.nameValuePair
"CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}"
); );
}; in
lib.optionalAttrs lto (toRustFlags {
lto = "thin";
})
// lib.optionalAttrs optimizeSize (toRustFlags {
codegen-units = "1";
opt-level = "s";
panic = "abort";
strip = "symbols";
});
meta = with lib; { meta = with lib; {
mainProgram = "refraction"; mainProgram = "refraction";

View file

@ -6,8 +6,11 @@
}: { }: {
packages = { packages = {
refraction = pkgs.callPackage ./derivation.nix {inherit self;}; refraction = pkgs.callPackage ./derivation.nix {inherit self;};
default = self'.packages.refraction; default = self'.packages.refraction;
}; };
}; };
flake.overlays.default = _: prev: {
refraction = prev.callPackage ./derivation.nix {inherit self;};
};
} }