nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, targetPlatform }:
2
3let
4 isAarch64Darwin = targetPlatform.isDarwin && targetPlatform.isAarch64;
5 gcc = targetPlatform.gcc or {};
6 p = gcc
7 // targetPlatform.parsed.abi;
8in lib.concatLists [
9 # --with-arch= is unknown flag on x86_64 and aarch64-darwin.
10 (lib.optional (!targetPlatform.isx86_64 && !isAarch64Darwin && p ? arch) "--with-arch=${p.arch}")
11 # --with-cpu on aarch64-darwin fails with "Unknown cpu used in --with-cpu=apple-a13".
12 (lib.optional (!isAarch64Darwin && p ? cpu) "--with-cpu=${p.cpu}")
13 (lib.optional (p ? abi) "--with-abi=${p.abi}")
14 (lib.optional (p ? fpu) "--with-fpu=${p.fpu}")
15 (lib.optional (p ? float) "--with-float=${p.float}")
16 (lib.optional (p ? mode) "--with-mode=${p.mode}")
17 (lib.optionals targetPlatform.isPower64
18 # musl explicitly rejects 128-bit long double on
19 # powerpc64; see musl/arch/powerpc64/bits/float.h
20 (lib.optionals
21 (!targetPlatform.isMusl
22 && (targetPlatform.isLittleEndian ||
23 # "... --with-long-double-format is only supported if the default cpu is power7 or newer"
24 # https://github.com/NixOS/nixpkgs/pull/170215#issuecomment-1202164709
25 (lib.lists.elem
26 (lib.strings.substring 0 6 (p.cpu or ""))
27 [ "power7" "power8" "power9" "power1"/*0, 11, etc*/ ]))) [
28 "--with-long-double-128"
29 "--with-long-double-format=${gcc.long-double-format or "ieee"}"
30 ]))
31 (lib.optional targetPlatform.isMips64n32 "--disable-libsanitizer") # libsanitizer does not compile on mips64n32
32]