Skip to content

Commit

Permalink
Merge pull request #328586 from reckenrode/darwin-lto
Browse files Browse the repository at this point in the history
tree-wide: enable LTO on Darwin
  • Loading branch information
reckenrode authored Jul 20, 2024
2 parents 726f3ec + d5f6375 commit 59dba7c
Show file tree
Hide file tree
Showing 24 changed files with 12 additions and 91 deletions.
1 change: 0 additions & 1 deletion pkgs/applications/audio/dexed/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ stdenv.mkDerivation rec {

postPatch = ''
# needs special setup on Linux, dunno if it can work on Darwin
# https://github.com/NixOS/nixpkgs/issues/19098
sed -i -e '/juce::juce_recommended_lto_flags/d' Source/CMakeLists.txt
'';

Expand Down
1 change: 0 additions & 1 deletion pkgs/applications/audio/fire/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ stdenv.mkDerivation rec {
postPatch = ''
# 1. Remove hardcoded LTO flags: needs extra setup on Linux,
# possibly broken on Darwin
# https://github.com/NixOS/nixpkgs/issues/19098
# 2. Disable automatic copying of built plugins during buildPhase, it defaults
# into user home and we want to have building & installing separated.
sed -i \
Expand Down
1 change: 0 additions & 1 deletion pkgs/applications/audio/sonobus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ stdenv.mkDerivation (finalAttrs: {

postPatch = lib.optionalString (stdenv.isLinux) ''
# needs special setup on Linux, dunno if it can work on Darwin
# https://github.com/NixOS/nixpkgs/issues/19098
# Also, I get issues with linking without that, not sure why
sed -i -e '/juce::juce_recommended_lto_flags/d' CMakeLists.txt
patchShebangs linux/install.sh
Expand Down
6 changes: 1 addition & 5 deletions pkgs/applications/blockchains/miniscript/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ stdenv.mkDerivation rec {
postPatch = lib.optionalString stdenv.isDarwin ''
# Replace hardcoded g++ with c++ so clang can be used
# on darwin
#
# lto must be disabled on darwin as well due to
# https://github.com/NixOS/nixpkgs/issues/19098
substituteInPlace Makefile \
--replace-fail 'g++' 'c++' \
--replace-fail '-flto' ""
--replace-fail 'g++' 'c++'
'';

installPhase = ''
Expand Down
3 changes: 0 additions & 3 deletions pkgs/applications/emulators/firebird-emu/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ stdenv.mkDerivation rec {
hash = "sha256-ZptjlnOiF+hKuKYvBFJL95H5YQuR99d4biOco/MVEmE=";
};

# work around https://github.com/NixOS/nixpkgs/issues/19098
env.NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && stdenv.isDarwin) "-fno-lto";

nativeBuildInputs = [ wrapQtAppsHook qmake ];

buildInputs = [ qtbase qtdeclarative qtquickcontrols ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ stdenv.mkDerivation rec {

enableParallelBuilding = true;

#link-time optimization fails on darwin
#see https://github.com/NixOS/nixpkgs/issues/19098
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-fno-lto";

postPatch = ''
# Fix gcc-13 build failure due to missing includes:
sed -e '1i #include <cstdint>' -i \
Expand Down
5 changes: 1 addition & 4 deletions pkgs/applications/virtualization/rvvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ stdenv.mkDerivation rec {

makeFlags = [ "PREFIX=$(out)" ]
++ lib.optional enableSDL "USE_SDL=2" # Use SDL2 instead of SDL1
++ lib.optional (!enableSDL && !enableX11) "USE_FB=0"

# work around https://github.com/NixOS/nixpkgs/issues/19098
++ lib.optional (stdenv.cc.isClang && stdenv.isDarwin) "CFLAGS=-fno-lto";
++ lib.optional (!enableSDL && !enableX11) "USE_FB=0";

meta = with lib; {
homepage = "https://github.com/LekKit/RVVM";
Expand Down
4 changes: 1 addition & 3 deletions pkgs/by-name/tr/tracy/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ stdenv.mkDerivation rec {
# ../../../server/TracyView.cpp:649:34, preventing building.
++ lib.optional stdenv.isDarwin "-Wno-format-security"
++ lib.optional stdenv.isLinux "-ltbb"
++ lib.optional stdenv.cc.isClang "-faligned-allocation"
# workaround issue #19098
++ lib.optional (stdenv.cc.isClang && stdenv.isDarwin) "-fno-lto");
++ lib.optional stdenv.cc.isClang "-faligned-allocation");

buildPhase = ''
runHook preBuild
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/ponyc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
, cmake
, coreutils
, libxml2
, lto ? !stdenv.isDarwin
, lto ? true
, makeWrapper
, openssl
, pcre2
Expand Down
1 change: 0 additions & 1 deletion pkgs/development/compilers/rgbds/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ stdenv.mkDerivation rec {
postPatch = ''
patchShebangs --host src/bison.sh
'';
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-fno-lto";
installFlags = [ "PREFIX=${placeholder "out"}" ];

meta = with lib; {
Expand Down
12 changes: 6 additions & 6 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
, enableNoSemanticInterposition ? true

# enabling LTO on 32bit arch causes downstream packages to fail when linking
# enabling LTO on *-darwin causes python3 to fail when linking.
, enableLTO ? stdenv.is64bit && stdenv.isLinux
, enableLTO ? stdenv.isDarwin || (stdenv.is64bit && stdenv.isLinux)

# enable asserts to ensure the build remains reproducible
, reproducibleBuild ? false
Expand Down Expand Up @@ -159,7 +158,7 @@ let
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
buildPackages.stdenv.cc
pythonOnBuildForHost
] ++ optionals (stdenv.cc.isClang && (!stdenv.hostPlatform.useAndroidPrebuilt or false) && (enableLTO || enableOptimizations)) [
] ++ optionals (stdenv.cc.isClang && !stdenv.isDarwin && (!stdenv.hostPlatform.useAndroidPrebuilt or false) && (enableLTO || enableOptimizations)) [
stdenv.cc.cc.libllvm.out
];

Expand Down Expand Up @@ -406,9 +405,6 @@ in with passthru; stdenv.mkDerivation (finalAttrs: {
configureFlags = [
"--without-ensurepip"
"--with-system-expat"
] ++ optionals (!(stdenv.isDarwin && pythonAtLeast "3.12")) [
# ./Modules/_decimal/_decimal.c:4673:6: error: "No valid combination of CONFIG_64, CONFIG_32 and _PyHASH_BITS"
# https://hydra.nixos.org/build/248410479/nixlog/2/tail
"--with-system-libmpdec"
] ++ optionals (openssl != null) [
"--with-openssl=${openssl.dev}"
Expand Down Expand Up @@ -480,6 +476,10 @@ in with passthru; stdenv.mkDerivation (finalAttrs: {
export PYTHON_DECIMAL_WITH_MACHINE=${if stdenv.isAarch64 then "uint128" else "x64"}
# Ensure that modern platform features are enabled on Darwin in spite of having no version suffix.
sed -E -i -e 's|Darwin/\[12\]\[0-9\]\.\*|Darwin/*|' configure
'' + optionalString (pythonAtLeast "3.11") ''
# Also override the auto-detection in `configure`.
substituteInPlace configure \
--replace-fail 'libmpdec_machine=universal' 'libmpdec_machine=${if stdenv.isAarch64 then "uint128" else "x64"}'
'' + optionalString (stdenv.isDarwin && x11Support && pythonAtLeast "3.11") ''
export TCLTK_LIBS="-L${tcl}/lib -L${tk}/lib -l${tcl.libPrefix} -l${tk.libPrefix}"
export TCLTK_CFLAGS="-I${tcl}/include -I${tk}/include"
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/libraries/liblc3/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ stdenv.mkDerivation {
ninja
];

# LTO does not work on Darwin: https://github.com/NixOS/nixpkgs/issues/19098
mesonFlags = lib.optionals stdenv.isDarwin [ "-Db_lto=false" ];

meta = with lib; {
description = "LC3 (Low Complexity Communication Codec) is an efficient low latency audio codec";
homepage = "https://github.com/google/liblc3";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/wolfssl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# requiring to build a special variant for that software. Example: 'haproxy'
, variant ? "all"
, extraConfigureFlags ? []
, enableLto ? !(stdenv.isDarwin || stdenv.hostPlatform.isStatic || stdenv.cc.isClang)
, enableLto ? !(stdenv.hostPlatform.isStatic || stdenv.cc.isClang)
}:
stdenv.mkDerivation (finalAttrs: {
pname = "wolfssl-${variant}";
Expand Down
5 changes: 0 additions & 5 deletions pkgs/development/python-modules/cocotb/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ buildPythonPackage rec {
# remove circular dependency cocotb-bus from setup.py
substituteInPlace setup.py --replace "'cocotb-bus<1.0'" ""
''
+ lib.optionalString stdenv.isDarwin ''
# disable lto on darwin
# https://github.com/NixOS/nixpkgs/issues/19098
substituteInPlace cocotb_build_libs.py --replace "-flto" ""
'';

patches = [
Expand Down
6 changes: 0 additions & 6 deletions pkgs/development/python-modules/levenshtein/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ buildPythonPackage rec {

buildInputs = [ rapidfuzz-cpp ];

env.NIX_CFLAGS_COMPILE = toString (
lib.optionals (stdenv.cc.isClang && stdenv.isDarwin) [
"-fno-lto" # work around https://github.com/NixOS/nixpkgs/issues/19098
]
);

dependencies = [ rapidfuzz ];

nativeCheckInputs = [ pytestCheckHook ];
Expand Down
15 changes: 0 additions & 15 deletions pkgs/development/python-modules/nuitka/darwin-lto.patch

This file was deleted.

3 changes: 0 additions & 3 deletions pkgs/development/python-modules/nuitka/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ buildPythonPackage rec {
hash = "sha256-nKdCMgA92v9VsSgfktXDbSh3DyKsGlcTjpn0Y7u4rxU=";
};

# default lto off for darwin
patches = [ ./darwin-lto.patch ];

build-system = [
setuptools
wheel
Expand Down
6 changes: 0 additions & 6 deletions pkgs/development/python-modules/rapidfuzz/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ buildPythonPackage rec {
export CMAKE_ARGS="-DCMAKE_CXX_COMPILER_AR=$AR -DCMAKE_CXX_COMPILER_RANLIB=$RANLIB"
'';

env.NIX_CFLAGS_COMPILE = toString (
lib.optionals (stdenv.cc.isClang && stdenv.isDarwin) [
"-fno-lto" # work around https://github.com/NixOS/nixpkgs/issues/19098
]
);

passthru.optional-dependencies = {
full = [ numpy ];
};
Expand Down
5 changes: 1 addition & 4 deletions pkgs/development/ruby-modules/gem-config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,7 @@ in
substituteInPlace lib/sassc/native.rb \
--replace 'gem_root = spec.gem_dir' 'gem_root = File.join(__dir__, "../../")'
'';
} // (lib.optionalAttrs stdenv.isDarwin {
# https://github.com/NixOS/nixpkgs/issues/19098
buildFlags = [ "--disable-lto" ];
});
};

sass-embedded = attrs: {
# Patch the Rakefile to use our dart-sass and not try to fetch anything.
Expand Down
3 changes: 0 additions & 3 deletions pkgs/games/eduke32/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ in stdenv.mkDerivation (finalAttrs: {

makeFlags = [
"SDLCONFIG=${SDL2}/bin/sdl2-config"
] ++ lib.optionals stdenv.isDarwin [
# broken, see: https://github.com/NixOS/nixpkgs/issues/19098
"LTO=0"
];

buildFlags = [
Expand Down
6 changes: 0 additions & 6 deletions pkgs/games/stockfish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ stdenv.mkDerivation rec {
sha256 = "sha256-ASy2vIP94lnSKgxixK1GoC84yAysaJpxeyuggV4MrP4=";
};

# This addresses a linker issue with Darwin
# https://github.com/NixOS/nixpkgs/issues/19098
preBuild = lib.optionalString stdenv.isDarwin ''
sed -i.orig '/^\#\#\# 3.*Link Time Optimization/,/^\#\#\# 3/d' Makefile
'';

postUnpack = ''
sourceRoot+=/src
echo ${nnue}
Expand Down
3 changes: 0 additions & 3 deletions pkgs/tools/misc/remind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ tcl.mkTclDerivation rec {
'';

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin (toString [
# Disable clang link time optimization until the following issue is resolved:
# https://github.com/NixOS/nixpkgs/issues/19098
"-fno-lto"
# On Darwin setenv and unsetenv are defined in stdlib.h from libSystem
"-DHAVE_SETENV"
"-DHAVE_UNSETENV"
Expand Down
1 change: 0 additions & 1 deletion pkgs/tools/package-management/lix/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ stdenv.mkDerivation {
mesonFlags =
[
# LTO optimization
(lib.mesonBool "b_lto" (!stdenv.isDarwin))
(lib.mesonEnable "gc" true)
(lib.mesonBool "enable-tests" true)
(lib.mesonBool "enable-docs" enableDocumentation)
Expand Down
5 changes: 0 additions & 5 deletions pkgs/tools/system/bfs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ stdenv.mkDerivation rec {

buildInputs = [ oniguruma ] ++ lib.optionals stdenv.isLinux [ libcap acl liburing ];

# Disable LTO on darwin. See https://github.com/NixOS/nixpkgs/issues/19098
preConfigure = lib.optionalString stdenv.isDarwin ''
substituteInPlace GNUMakefile --replace "-flto=auto" ""
'';

makeFlags = [ "PREFIX=$(out)" ];
buildFlags = [ "release" ]; # "release" enables compiler optimizations

Expand Down

0 comments on commit 59dba7c

Please sign in to comment.