From 9370e93a8dd2e9cc72c6bc48b7689146bd3a4405 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 13 Jul 2024 23:03:29 -0400 Subject: [PATCH] nix: try to make x86-64-v2 optimised builds if target is x86_64 Signed-off-by: strawberry --- nix/pkgs/main/cross-compilation-env.nix | 3 +++ nix/pkgs/main/default.nix | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nix/pkgs/main/cross-compilation-env.nix b/nix/pkgs/main/cross-compilation-env.nix index 83fe6ed6..70d0e51c 100644 --- a/nix/pkgs/main/cross-compilation-env.nix +++ b/nix/pkgs/main/cross-compilation-env.nix @@ -13,6 +13,9 @@ lib.optionalAttrs stdenv.hostPlatform.isStatic { lib.concatStringsSep " " ([] + ++ lib.optionals + stdenv.targetPlatform.isx86_64 + [ "-C" "target-cpu=x86-64-v2" ] # This disables PIE for static builds, which isn't great in terms # of security. Unfortunately, my hand is forced because nixpkgs' # `libstdc++.a` is built without `-fPIE`, which precludes us from diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index ffb1de96..6e3e82d7 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -71,10 +71,23 @@ buildDepsOnlyEnv = # which breaks Darwin entirely enableLiburing = enableLiburing; }).overrideAttrs (old: { - # TODO: static rocksdb fails to build on darwin + # TODO: static rocksdb fails to build on darwin, also see # build log at meta.broken = stdenv.hostPlatform.isStatic && stdenv.isDarwin; + enableLiburing = enableLiburing; + + sse42Support = stdenv.targetPlatform.isx86_64; + + cmakeFlags = if stdenv.targetPlatform.isx86_64 + then lib.subtractLists [ "-DPORTABLE=1" ] old.cmakeFlags + ++ lib.optionals stdenv.targetPlatform.isx86_64 [ + "-DPORTABLE=x86-64-v2" + "-DUSE_SSE=1" + "-DHAVE_SSE=1" + "-DHAVE_SSE42=1" + ] + else old.cmakeFlags; }); in { @@ -101,7 +114,9 @@ buildPackageEnv = { # Only needed in static stdenv because these are transitive dependencies of rocksdb CARGO_BUILD_RUSTFLAGS = buildDepsOnlyEnv.CARGO_BUILD_RUSTFLAGS + lib.optionalString (enableLiburing && stdenv.hostPlatform.isStatic) - " -L${lib.getLib liburing}/lib -luring"; + " -L${lib.getLib liburing}/lib -luring" + + lib.optionalString stdenv.targetPlatform.isx86_64 + " -Ctarget-cpu=x86-64-v2"; };