stackpkgs/packages/compileOptimized/C.nix
Ryze ec2fffc12f
Make assert messages more readable
Use lib.assertOneOf and lib.assertMsg
2024-09-20 22:27:44 +03:00

32 lines
560 B
Nix

{ lib }:
{
optimizationLevel ? "O3",
enableLTO ? true,
enableNativeOptimizations ? true,
additionalFlags ? []
}:
pkg:
assert lib.assertOneOf "optimizationLevel" optimizationLevel [
"O0"
"O1"
"O2"
"O3"
"Ofast"
"Os"
"Oz"
"Og"
];
let
flags = [ "-${optimizationLevel}" ]
++ lib.optional enableLTO "-flto"
++ lib.optional enableNativeOptimizations "-march=native"
++ additionalFlags;
in
pkg.overrideAttrs (prevAttrs: {
env.NIX_CFLAGS_COMPILE = (prevAttrs.env.NIX_CFLAGS_COMPILE or "")
+ lib.strings.concatStringsSep " " flags;
})