Skip to content

Commit

Permalink
treewide: remove obsolete aligned allocation workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
emilazy committed Jan 3, 2025
1 parent 7f5756b commit b0341c2
Show file tree
Hide file tree
Showing 31 changed files with 25 additions and 208 deletions.
2 changes: 0 additions & 2 deletions pkgs/applications/networking/ids/zeek/broker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ stdenv.mkDerivation rec {
"-DPY_MOD_INSTALL_DIR=${placeholder "py"}/${python3.sitePackages}/"
];

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-faligned-allocation";

meta = with lib; {
description = "Zeek's Messaging Library";
mainProgram = "broker-benchmark";
Expand Down
2 changes: 0 additions & 2 deletions pkgs/applications/networking/ids/zeek/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ stdenv.mkDerivation rec {
"-DLIBKQUEUE_ROOT_DIR=${libkqueue}"
];

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-faligned-allocation";

postInstall = ''
for file in $out/share/zeek/base/frameworks/notice/actions/pp-alarms.zeek $out/share/zeek/base/frameworks/notice/main.zeek; do
substituteInPlace $file \
Expand Down
2 changes: 0 additions & 2 deletions pkgs/by-name/ca/caf/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ stdenv.mkDerivation rec {
"-DCAF_ENABLE_EXAMPLES:BOOL=OFF"
];

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-faligned-allocation";

doCheck = !stdenv.hostPlatform.isDarwin;
checkTarget = "test";

Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/ci/cinny-unwrapped/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ buildNpmPackage rec {

npmDepsHash = "sha256-fDoia6evCmXZgeIKL0coRo3yunX1dfud31ROgmop2Sc=";

# Fix error: no member named 'aligned_alloc' in the global namespace
env.NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinSdkVersion "11.0"
) "-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION=1";

nativeBuildInputs = [
python3
pkg-config
Expand Down
4 changes: 0 additions & 4 deletions pkgs/by-name/lu/luaformatter/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ stdenv.mkDerivation rec {
yaml-cpp
];

env.NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64
) "-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION=1";

meta = with lib; {
description = "Code formatter for Lua";
homepage = "https://github.com/Koihik/LuaFormatter";
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/ma/matrix-authentication-service/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,5 @@ rustPlatform.buildRustPackage rec {
license = lib.licenses.agpl3Only;
maintainers = with lib.maintainers; [ teutat3s ];
mainProgram = "mas-cli";
# Note: broken on x86_64-darwin because of aligned_alloc, can be revisited after
# https://github.com/NixOS/nixpkgs/pull/346043 is merged
badPlatforms = [ "x86_64-darwin" ];
};
}
4 changes: 0 additions & 4 deletions pkgs/by-name/mo/mold/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ stdenv.mkDerivation rec {
"-DMOLD_USE_SYSTEM_TBB:BOOL=ON"
];

env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.hostPlatform.isDarwin [
"-faligned-allocation"
]);

passthru = {
updateScript = nix-update-script { };
tests =
Expand Down
12 changes: 4 additions & 8 deletions pkgs/by-name/na/naja/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ stdenv.mkDerivation {
tbb_2021_11
];

cmakeFlags =
[
(lib.cmakeBool "CPPTRACE_USE_EXTERNAL_LIBDWARF" true)
(lib.cmakeBool "CPPTRACE_USE_EXTERNAL_ZSTD" true)
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
(lib.cmakeFeature "CMAKE_OSX_DEPLOYMENT_TARGET" "10.14") # For aligned allocation
];
cmakeFlags = [
(lib.cmakeBool "CPPTRACE_USE_EXTERNAL_LIBDWARF" true)
(lib.cmakeBool "CPPTRACE_USE_EXTERNAL_ZSTD" true)
];

doCheck = true;

Expand Down
8 changes: 0 additions & 8 deletions pkgs/by-name/ng/nghttp2/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ stdenv.mkDerivation rec {
(lib.enableFeature enableHttp3 "http3")
];

env.NIX_CFLAGS_COMPILE = toString (
lib.optionals
(stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13")
[
"-faligned-allocation"
]
);

# Unit tests require CUnit and setting TZDIR environment variable
doCheck = enableTests;
nativeCheckInputs = lib.optionals (enableTests) [
Expand Down
8 changes: 0 additions & 8 deletions pkgs/by-name/p2/p2pool/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ stdenv.mkDerivation rec {

cmakeFlags = [ "-DWITH_LTO=OFF" ];

env.NIX_CFLAGS_COMPILE = toString (
lib.optionals
(stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13")
[
"-faligned-allocation"
]
);

installPhase = ''
runHook preInstall
Expand Down
9 changes: 2 additions & 7 deletions pkgs/by-name/re/renovate/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
yq-go,
}:

let
# fix build error, `no member named 'aligned_alloc'` on x86_64-darwin
# https://github.com/NixOS/nixpkgs/issues/272156#issuecomment-1839904283
stdenv' = if stdenv.hostPlatform.isDarwin then overrideSDK stdenv "11.0" else stdenv;
in
stdenv'.mkDerivation (finalAttrs: {
stdenv.mkDerivation (finalAttrs: {
pname = "renovate";
version = "39.90.2";

Expand All @@ -41,7 +36,7 @@ stdenv'.mkDerivation (finalAttrs: {
pnpm_9.configHook
python3
yq-go
] ++ lib.optional stdenv'.hostPlatform.isDarwin xcbuild;
] ++ lib.optional stdenv.hostPlatform.isDarwin xcbuild;

pnpmDeps = pnpm_9.fetchDeps {
inherit (finalAttrs) pname version src;
Expand Down
6 changes: 0 additions & 6 deletions pkgs/by-name/ro/rocksdb/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ stdenv.mkDerivation (finalAttrs: {
"tools"
];

env.NIX_CFLAGS_COMPILE = toString (
lib.optionals stdenv.cc.isClang [
"-faligned-allocation"
]
);

cmakeFlags = [
"-DPORTABLE=1"
"-DWITH_JEMALLOC=${if enableJemalloc then "1" else "0"}"
Expand Down
5 changes: 0 additions & 5 deletions pkgs/by-name/ro/root/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,6 @@ stdenv.mkDerivation rec {
}"
'';

# error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.13 or newer
env.CXXFLAGS = lib.optionalString (
stdenv.hostPlatform.system == "x86_64-darwin"
) "-faligned-allocation";

# workaround for
# https://github.com/root-project/root/issues/14778
env.NIX_LDFLAGS = lib.optionalString (
Expand Down
2 changes: 0 additions & 2 deletions pkgs/by-name/so/sonic-server/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ rustPlatform.buildRustPackage rec {
rustPlatform.bindgenHook
];

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-faligned-allocation";

postPatch = ''
substituteInPlace src/main.rs \
--replace-fail "./config.cfg" "$out/etc/sonic/config.cfg"
Expand Down
2 changes: 0 additions & 2 deletions pkgs/by-name/sp/spades/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ stdenv.mkDerivation (finalAttrs: {
readline
];

env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-faligned-allocation";

doCheck = true;

strictDeps = true;
Expand Down
3 changes: 0 additions & 3 deletions pkgs/by-name/tr/tracy/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ stdenv.mkDerivation rec {
env.NIX_CFLAGS_COMPILE = toString (
[ ]
++ lib.optional stdenv.hostPlatform.isLinux "-ltbb"
++ lib.optional (
stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
) "-fno-aligned-allocation"
# Workaround for https://github.com/NixOS/nixpkgs/issues/19098
++ lib.optional (stdenv.cc.isClang && stdenv.hostPlatform.isDarwin) "-fno-lto"
);
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/compilers/clasp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ stdenv.mkDerivation rec {
"x86_64-linux"
"x86_64-darwin"
];
# Upstream claims support, but breaks with:
# error: use of undeclared identifier 'aligned_alloc'
broken = stdenv.hostPlatform.isDarwin;
homepage = "https://github.com/clasp-developers/clasp";
mainProgram = "clasp";
};
Expand Down
32 changes: 8 additions & 24 deletions pkgs/development/compilers/halide/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,14 @@ stdenv.mkDerivation rec {
hash = "sha256-BPalUh9EgdCqVaWC1HoreyyRcPQc4QMIYnLrRoNDDCI=";
};

postPatch =
''
# See https://github.com/halide/Halide/issues/7785
substituteInPlace 'src/runtime/HalideRuntime.h' \
--replace '#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#define HALIDE_CPP_COMPILER_HAS_FLOAT16' \
'#if defined(__x86_64__) || defined(__i386__)
#define HALIDE_CPP_COMPILER_HAS_FLOAT16'
''
# Note: on x86_64-darwin, clang fails to find AvailabilityVersions.h, so we remove it.
# Halide uses AvailabilityVersions.h and TargetConditionals.h to determine whether
# ::aligned_alloc is available. For us, it isn't.
+ lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) ''
substituteInPlace 'src/runtime/HalideBuffer.h' \
--replace '#ifdef __APPLE__
#include <AvailabilityVersions.h>
#include <TargetConditionals.h>
#endif' \
' ' \
--replace 'TARGET_OS_OSX && (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_15)' \
'1' \
--replace 'TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_14_0)' \
'0'
'';
postPatch = ''
# See https://github.com/halide/Halide/issues/7785
substituteInPlace 'src/runtime/HalideRuntime.h' \
--replace '#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#define HALIDE_CPP_COMPILER_HAS_FLOAT16' \
'#if defined(__x86_64__) || defined(__i386__)
#define HALIDE_CPP_COMPILER_HAS_FLOAT16'
'';

cmakeFlags = [
"-DWARNINGS_AS_ERRORS=OFF"
Expand Down
13 changes: 3 additions & 10 deletions pkgs/development/libraries/libfive/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,9 @@ stdenv.mkDerivation {
export XDG_CACHE_HOME=$(mktemp -d)/.cache
'';

cmakeFlags =
[
"-DGUILE_CCACHE_DIR=${placeholder "out"}/${guile.siteCcacheDir}"
]
++ lib.optionals
(stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "11")
[
# warning: 'aligned_alloc' is only available on macOS 10.15 or newer
"-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"
];
cmakeFlags = [
"-DGUILE_CCACHE_DIR=${placeholder "out"}/${guile.siteCcacheDir}"
];

env = lib.optionalAttrs stdenv.cc.isClang {
NIX_CFLAGS_COMPILE = "-Wno-error=enum-constexpr-conversion";
Expand Down
2 changes: 0 additions & 2 deletions pkgs/development/libraries/lief/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ stdenv.mkDerivation rec {
scikit-build-core
];

env.CXXFLAGS = toString (lib.optional stdenv.hostPlatform.isDarwin [ "-faligned-allocation" "-fno-aligned-new" "-fvisibility=hidden" ]);

postBuild = ''
pushd ../api/python
${pyEnv.interpreter} -m build --no-isolation --wheel --skip-dependency-check --config-setting=--parallel=$NIX_BUILD_CORES
Expand Down
12 changes: 0 additions & 12 deletions pkgs/development/libraries/openvdb/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ stdenv.mkDerivation rec {
"-DOPENVDB_BUILD_NANOVDB=ON"
];

# error: aligned deallocation function of type 'void (void *, std::align_val_t) noexcept' is only available on macOS 10.13 or newer
env =
lib.optionalAttrs
(
stdenv.hostPlatform.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
&& lib.versionAtLeast tbb.version "2021.8.0"
)
{
NIX_CFLAGS_COMPILE = "-faligned-allocation";
};

postFixup = ''
substituteInPlace $dev/lib/cmake/OpenVDB/FindOpenVDB.cmake \
--replace \''${OPENVDB_LIBRARYDIR} $out/lib \
Expand Down
3 changes: 0 additions & 3 deletions pkgs/development/libraries/qt-6/modules/qtquick3dphysics.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ qtModule {
qtbase
qtquick3d
];
env.NIX_CFLAGS_COMPILE = lib.optionalString (
stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64
) "-faligned-allocation";
meta.mainProgram = "cooker";
}
14 changes: 0 additions & 14 deletions pkgs/development/ocaml-modules/hacl-star/aligned-alloc.patch

This file was deleted.

4 changes: 0 additions & 4 deletions pkgs/development/ocaml-modules/hacl-star/raw.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ stdenv.mkDerivation rec {
stripRoot = false;
};

patches = [
./aligned-alloc.patch
];

# strictoverflow is disabled because it breaks aarch64-darwin
hardeningDisable = [ "strictoverflow" ];

Expand Down
23 changes: 0 additions & 23 deletions pkgs/development/python-modules/pybind11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ let
pythonSitePackages = "${python}/${python.sitePackages}";
};
} ./setup-hook.sh;

# clang 16 defaults to C++17, which results in the use of aligned allocations by pybind11.
# libc++ supports aligned allocations via `posix_memalign`, which is available since 10.6,
# but clang has a check hard-coded requiring 10.13 because that’s when Apple first shipped a
# support for C++17 aligned allocations on macOS.
# Tell clang we’re targeting 10.13 on x86_64-darwin while continuing to use the default SDK.
stdenv' =
if stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64 then
python.stdenv.override (oldStdenv: {
buildPlatform = oldStdenv.buildPlatform // {
darwinMinVersion = "10.13";
};
targetPlatform = oldStdenv.targetPlatform // {
darwinMinVersion = "10.13";
};
hostPlatform = oldStdenv.hostPlatform // {
darwinMinVersion = "10.13";
};
})
else
python.stdenv;
in
buildPythonPackage rec {
pname = "pybind11";
Expand All @@ -69,8 +48,6 @@ buildPythonPackage rec {
buildInputs = lib.optionals (pythonOlder "3.9") [ libxcrypt ];
propagatedNativeBuildInputs = [ setupHook ];

stdenv = stdenv';

dontUseCmakeBuildDir = true;

# Don't build tests if not needed, read the doInstallCheck value at runtime
Expand Down
12 changes: 1 addition & 11 deletions pkgs/development/python-modules/torch/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,7 @@ buildPythonPackage rec {
# until https://github.com/pytorch/pytorch/issues/76082 is addressed
+ lib.optionalString cudaSupport ''
rm cmake/Modules/FindCUDAToolkit.cmake
''
# error: no member named 'aligned_alloc' in the global namespace; did you mean simply 'aligned_alloc'
# This lib overrided aligned_alloc hence the error message. Tltr: his function is linkable but not in header.
+
lib.optionalString
(stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinSdkVersion "11.0")
''
substituteInPlace third_party/pocketfft/pocketfft_hdronly.h --replace-fail '#if (__cplusplus >= 201703L) && (!defined(__MINGW32__)) && (!defined(_MSC_VER))
inline void *aligned_alloc(size_t align, size_t size)' '#if 0
inline void *aligned_alloc(size_t align, size_t size)'
'';
'';

# NOTE(@connorbaker): Though we do not disable Gloo or MPI when building with CUDA support, caution should be taken
# when using the different backends. Gloo's GPU support isn't great, and MPI and CUDA can't be used at the same time
Expand Down
6 changes: 0 additions & 6 deletions pkgs/servers/mail/mailpit/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ let
hash = source.npmDepsHash;
};

env = lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) {
# Make sure libc++ uses `posix_memalign` instead of `aligned_alloc` on x86_64-darwin.
# Otherwise, nodejs would require the 11.0 SDK and macOS 10.15+.
NIX_CFLAGS_COMPILE = "-D__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__=101300";
};

nativeBuildInputs = [
nodejs
python3
Expand Down
Loading

0 comments on commit b0341c2

Please sign in to comment.