From d43029cf4520812d5bd64635f58602ed53386516 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 31 May 2023 09:27:53 -0700 Subject: [PATCH 01/33] lib/systems: replicate cygwin/msvc parsing hack when unparsing For almost a decade nixpkgs has parsed `*-*-{cygwin,msvc}` as being ABIs for a common kernel (windows), rather than as kernels. It isn't really reasonable to change nixpkgs' handling at this point, so this commit replicates the special-case hack when unparsing, in order to ensure that `(unparse . parse)==id`. --- lib/systems/parse.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index b69ad669e1874..f43b9065b7eb1 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -507,7 +507,15 @@ rec { gnuNetBSDDefaultExecFormat cpu != kernel.execFormat) kernel.execFormat.name; optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}"; - in "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}"; + in + # gnu-config considers "mingw32" and "cygwin" to be kernels. + # This is obviously bogus, which is why nixpkgs has historically + # parsed them differently. However for regression testing + # reasons (see lib/tests/triples.nix) we need to replicate this + # quirk when unparsing in order to round-trip correctly. + if abi == abis.cygnus then "${cpu.name}-${vendor.name}-cygwin" + else if kernel == kernels.windows then "${cpu.name}-${vendor.name}-mingw32" + else "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}"; ################################################################################ From 9a2c5b16da6e7cae830cf4eecb9fdaabcc6eba37 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 18:12:05 -0700 Subject: [PATCH 02/33] lib/systems: factor tripleFromSkeleton out of tripleFromSystem tripleFromSkeleton contains the same logic found in tripleFromSystem, but is capable of operating on unvalidated attrsets-of-strings. --- lib/systems/parse.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index f43b9065b7eb1..6fd72885ab976 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -506,16 +506,29 @@ rec { lib.optionalString (kernel.name == "netbsd" && gnuNetBSDDefaultExecFormat cpu != kernel.execFormat) kernel.execFormat.name; - optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}"; + in + tripleFromSkeleton { + cpu = cpu.name; + vendor = vendor.name; + kernel = kernelName kernel; + inherit optExecFormat; + abi = abi.name; + }; + + tripleFromSkeleton = { cpu, vendor, kernel, optExecFormat?"", abi }: let + optAbi = lib.optionalString (abi != "unknown") "-${abi}"; + + # this allows to print a "vendorless" skeleton + optVendor = lib.optionalString (vendor != null) "-${vendor}"; in # gnu-config considers "mingw32" and "cygwin" to be kernels. # This is obviously bogus, which is why nixpkgs has historically # parsed them differently. However for regression testing # reasons (see lib/tests/triples.nix) we need to replicate this # quirk when unparsing in order to round-trip correctly. - if abi == abis.cygnus then "${cpu.name}-${vendor.name}-cygwin" - else if kernel == kernels.windows then "${cpu.name}-${vendor.name}-mingw32" - else "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}"; + if abi == "cygnus" then "${cpu}${optVendor}-cygwin" + else if kernel == "windows" then "${cpu}${optVendor}-mingw32" + else "${cpu}${optVendor}-${kernel}${optExecFormat}${optAbi}"; ################################################################################ From 89007a7ce4f9f35c7f0a0ab4f49d86357350f332 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 19:29:49 -0700 Subject: [PATCH 03/33] lib/systems: rename vendors.none -> vendors."" gnu-config does not recognize `none` as a vendor -- that string describes a *kernel* --- lib/systems/parse.nix | 12 ++-- pkgs/build-support/rust/lib/default.nix | 85 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 6fd72885ab976..617727e4bacee 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -236,7 +236,10 @@ rec { # bottom of https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/ w64 = {}; - none = {}; + # gnu-config distinguishes between `foo-bar-baz` and + # `foo-unknown-bar-baz`; we use `""` to represent the + # former case. + "" = { name = ""; }; unknown = {}; }; @@ -422,7 +425,7 @@ rec { else if elemAt l 1 == "windows" then { cpu = elemAt l 0; kernel = "windows"; abi = "msvc"; } else if (elemAt l 1) == "elf" - then { cpu = elemAt l 0; vendor = "unknown"; kernel = "none"; abi = elemAt l 1; } + then { cpu = elemAt l 0; kernel = "none"; abi = elemAt l 1; } else { cpu = elemAt l 0; kernel = elemAt l 1; }; "3" = # cpu-kernel-environment @@ -432,7 +435,6 @@ rec { cpu = elemAt l 0; kernel = elemAt l 1; abi = elemAt l 2; - vendor = "unknown"; } # cpu-vendor-os else if elemAt l 1 == "apple" || @@ -517,9 +519,7 @@ rec { tripleFromSkeleton = { cpu, vendor, kernel, optExecFormat?"", abi }: let optAbi = lib.optionalString (abi != "unknown") "-${abi}"; - - # this allows to print a "vendorless" skeleton - optVendor = lib.optionalString (vendor != null) "-${vendor}"; + optVendor = lib.optionalString (vendor != "") "-${vendor}"; in # gnu-config considers "mingw32" and "cygwin" to be kernels. # This is obviously bogus, which is why nixpkgs has historically diff --git a/pkgs/build-support/rust/lib/default.nix b/pkgs/build-support/rust/lib/default.nix index dad8ab5282357..48e218b313653 100644 --- a/pkgs/build-support/rust/lib/default.nix +++ b/pkgs/build-support/rust/lib/default.nix @@ -5,6 +5,91 @@ }: rec { + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch + toTargetArch = platform: + /**/ if platform ? rustc.platform then platform.rustc.platform.arch + else if platform.isAarch32 then "arm" + else if platform.isMips64 then "mips64" # never add "el" suffix + else if platform.isPower64 then "powerpc64" # never add "le" suffix + else platform.parsed.cpu.name; + + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_os + toTargetOs = platform: + /**/ if platform ? rustc.platform then platform.rustc.platform.os or "none" + else if platform.isDarwin then "macos" + else platform.parsed.kernel.name; + + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_family + toTargetFamily = platform: + if platform ? rustc.platform.target-family + then + ( + # Since https://github.com/rust-lang/rust/pull/84072 + # `target-family` is a list instead of single value. + let + f = platform.rustc.platform.target-family; + in + if builtins.isList f then f else [ f ] + ) + else lib.optional platform.isUnix "unix" + ++ lib.optional platform.isWindows "windows"; + + # https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor + toTargetVendor = platform: if platform.isDarwin then "apple" else let + inherit (platform.parsed) vendor; + in + platform.rustc.platform.vendor or { + "w64" = "pc"; + "" = "unknown"; + }.${vendor.name} or vendor.name; + + # Returns the name of the rust target, even if it is custom. Adjustments are + # because rust has slightly different naming conventions than we do. + toRustTarget = platform: let + inherit (platform.parsed) cpu kernel abi; + cpu_ = platform.rustc.platform.arch or { + "armv7a" = "armv7"; + "armv7l" = "armv7"; + "armv6l" = "arm"; + "armv5tel" = "armv5te"; + "riscv64" = "riscv64gc"; + }.${cpu.name} or cpu.name; + vendor_ = toTargetVendor platform; + in platform.rustc.config + or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + + # Returns the name of the rust target if it is standard, or the json file + # containing the custom target spec. + toRustTargetSpec = platform: + if platform ? rustc.platform + then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) + else toRustTarget platform; + + # Returns the name of the rust target if it is standard, or the + # basename of the file containing the custom target spec, without + # the .json extension. + # + # This is the name used by Cargo for target subdirectories. + toRustTargetSpecShort = platform: + lib.removeSuffix ".json" + (baseNameOf "${toRustTargetSpec platform}"); + + # When used as part of an environment variable name, triples are + # uppercased and have all hyphens replaced by underscores: + # + # https://github.com/rust-lang/cargo/pull/9169 + # https://github.com/rust-lang/cargo/issues/8285#issuecomment-634202431 + # + toRustTargetForUseInEnvVars = platform: + lib.strings.replaceStrings ["-"] ["_"] + (lib.strings.toUpper + (toRustTargetSpecShort platform)); + + # Returns true if the target is no_std + # https://github.com/rust-lang/rust/blob/2e44c17c12cec45b6a682b1e53a04ac5b5fcc9d2/src/bootstrap/config.rs#L415-L421 + IsNoStdTarget = platform: let rustTarget = toRustTarget platform; in + builtins.any (t: lib.hasInfix t rustTarget) ["-none" "nvptx" "switch" "-uefi"]; + # These environment variables must be set when using `cargo-c` and # several other tools which do not deal well with cross # compilation. The symptom of the problem they fix is errors due From c03ef39a190071f85c1ea8cc4aac44f7aef0b8e8 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 22:53:36 -0700 Subject: [PATCH 04/33] lib/systems: introduce tripleFromSystemLossy Unfortunately gnu-config triples are, in some rare cases, sensitive to whether the vendor was specified as `unknown` or was omitted. In other words, there are situations where these are not handled exactly the same way: - `mips-linux-gnu` - `mips-unknown-linux-gnu` This commit introduces `lib.systems.tripleFromSystemLossy`, which returns `"mips-unknown-linux-gnu"` for both of the platforms above. This is almost always what you want to use. --- lib/systems/default.nix | 2 +- lib/systems/parse.nix | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 0d21175914a3d..9894d2e570b47 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -52,7 +52,7 @@ rec { parsed = parse.mkSystemFromString (if args ? config then args.config else args.system); # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds. system = parse.doubleFromSystem final.parsed; - config = parse.tripleFromSystem final.parsed; + config = parse.tripleFromSystemLossy final.parsed; # Determine whether we can execute binaries built for the provided platform. canExecute = platform: final.isAndroid == platform.isAndroid && diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 617727e4bacee..5e8ed1ac7d1d7 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -503,6 +503,7 @@ rec { else if kernel.families ? darwin then "${cpu.name}-darwin" else "${cpu.name}-${kernelName kernel}"; + # Convert a system into a string triple tripleFromSystem = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; let optExecFormat = lib.optionalString (kernel.name == "netbsd" && @@ -517,6 +518,15 @@ rec { abi = abi.name; }; + # Convert a system into a string triple, erasing the distinction + # between vendors."" and vendors.unknown -- i.e. `mips-linux-gnu` + # and `mips-unknown-linux-gnu` both become + # `"mips-unknown-linux-gnu"`. + tripleFromSystemLossy = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; + tripleFromSystem (sys // lib.optionalAttrs (sys.vendor == vendors."") { + vendor = vendors.unknown; + }); + tripleFromSkeleton = { cpu, vendor, kernel, optExecFormat?"", abi }: let optAbi = lib.optionalString (abi != "unknown") "-${abi}"; optVendor = lib.optionalString (vendor != "") "-${vendor}"; From bda7ba84abf2f8b1fcb35df24f901548699ade45 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 18 Jun 2023 21:23:33 -0700 Subject: [PATCH 05/33] lib/systems: accomodate nonstandard `vc4-elf` triple Since 4aa1ffae041bb9c65eb3067e9dbaaa70710ed100 we have been shipping reverse-engineered out-of-tree forks of gcc and binutils for the Broadcom VC4. Upstream for those forks chose the nonstandard `vc4-elf` triple to identify their system. GNU config rejects this triple (and all `vc4-*` triples). This commit deals with the fallout from that. Mainly this commit ensures that we are consistent in using `vc4-elf` instead of `vc4-none`, and makes sure that parsing->unparsing round-trips properly. --- lib/systems/doubles.nix | 4 +++- lib/systems/parse.nix | 3 ++- pkgs/development/tools/misc/binutils/2.38/default.nix | 2 +- pkgs/development/tools/misc/binutils/default.nix | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index 13f029ee1f40b..194eae36c0b64 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -43,7 +43,9 @@ let "aarch64_be-none" "aarch64-none" "arm-none" "armv6l-none" "avr-none" "i686-none" "microblaze-none" "microblazeel-none" "mips-none" "mips64-none" "msp430-none" "or1k-none" "m68k-none" "powerpc-none" "powerpcle-none" "riscv32-none" "riscv64-none" "rx-none" - "s390-none" "s390x-none" "vc4-none" "x86_64-none" + "s390-none" "s390x-none" + "vc4-elf" # nonstandard triple, requires many hacks + "x86_64-none" # OpenBSD "i686-openbsd" "x86_64-openbsd" diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 5e8ed1ac7d1d7..c903ddb2bb293 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -498,9 +498,10 @@ rec { kernelName = kernel: kernel.name + toString (kernel.version or ""); - doubleFromSystem = { cpu, kernel, abi, ... }: + doubleFromSystem = { cpu, kernel, abi, ... }@platform: /**/ if abi == abis.cygnus then "${cpu.name}-cygwin" else if kernel.families ? darwin then "${cpu.name}-darwin" + else if isVc4 platform then "${cpu.name}-${abi.name}" # hack for nonstandard triple else "${cpu.name}-${kernelName kernel}"; # Convert a system into a string triple diff --git a/pkgs/development/tools/misc/binutils/2.38/default.nix b/pkgs/development/tools/misc/binutils/2.38/default.nix index 1194cbeb2453f..ad51854881f28 100644 --- a/pkgs/development/tools/misc/binutils/2.38/default.nix +++ b/pkgs/development/tools/misc/binutils/2.38/default.nix @@ -39,7 +39,7 @@ let url = "mirror://gnu/binutils/binutils-${version}.tar.bz2"; sha256 = "sha256-Bw7HHPB3pqWOC5WfBaCaNQFTeMLYpR6Q866r/jBZDvg="; }; - vc4-none = fetchFromGitHub { + vc4-elf = fetchFromGitHub { owner = "itszor"; repo = "binutils-vc4"; rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36"; diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index fe9ec6a865f93..9057087b78389 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -40,7 +40,7 @@ let url = "mirror://gnu/binutils/binutils-${version}.tar.bz2"; hash = "sha256-+CmOsVOks30RLpRapcsoUAQLzyaj6mW1pxXIOv4F5Io="; }; - vc4-none = fetchFromGitHub { + vc4-elf = fetchFromGitHub { owner = "itszor"; repo = "binutils-vc4"; rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36"; From 26c22f7d72762b8353c2c7a1c70ad2cab5d9ed91 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 18 Jun 2023 21:32:22 -0700 Subject: [PATCH 06/33] lib/systems: handle Solaris properly GNU config (correctly) considers Solaris to be a BSD, and therefore appends its version to the kernel name, which should be `solaris2` not `solaris`. This commit updates `lib/systems` to do the same. --- lib/systems/doubles.nix | 2 +- lib/systems/inspect.nix | 2 +- lib/systems/parse.nix | 2 +- lib/tests/systems.nix | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index 194eae36c0b64..f6e92890b298f 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -19,7 +19,7 @@ let "aarch64-genode" "i686-genode" "x86_64-genode" # illumos - "x86_64-solaris" + "x86_64-solaris2" # JS "javascript-ghcjs" diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 073df78797c72..8aba8f8913711 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -73,7 +73,7 @@ rec { isMacOS = { kernel = kernels.macos; }; isiOS = { kernel = kernels.ios; }; isLinux = { kernel = kernels.linux; }; - isSunOS = { kernel = kernels.solaris; }; + isSunOS = { kernel = kernels.solaris2; }; isFreeBSD = { kernel = { name = "freebsd"; }; }; isNetBSD = { kernel = kernels.netbsd; }; isOpenBSD = { kernel = kernels.openbsd; }; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index c903ddb2bb293..d33e1362c90b9 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -304,7 +304,7 @@ rec { netbsd = { execFormat = elf; families = { inherit bsd; }; }; none = { execFormat = unknown; families = { }; }; openbsd = { execFormat = elf; families = { inherit bsd; }; }; - solaris = { execFormat = elf; families = { }; }; + solaris2 = { execFormat = elf; families = { }; name = "solaris"; version = 2; }; wasi = { execFormat = wasm; families = { }; }; redox = { execFormat = elf; families = { }; }; windows = { execFormat = pe; families = { }; }; diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index e142ff307fbd4..35f4f61b0f46c 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -48,7 +48,7 @@ lib.runTests ( testriscv32 = mseteq riscv32 [ "riscv32-linux" "riscv32-netbsd" "riscv32-none" ]; testriscv64 = mseteq riscv64 [ "riscv64-linux" "riscv64-netbsd" "riscv64-none" ]; tests390x = mseteq s390x [ "s390x-linux" "s390x-none" ]; - testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd13" "x86_64-genode" "x86_64-redox" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" "x86_64-none" ]; + testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd13" "x86_64-genode" "x86_64-redox" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris2" "x86_64-windows" "x86_64-none" ]; testcygwin = mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ]; testdarwin = mseteq darwin [ "x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin" ]; @@ -56,7 +56,7 @@ lib.runTests ( testgenode = mseteq genode [ "aarch64-genode" "i686-genode" "x86_64-genode" ]; testredox = mseteq redox [ "x86_64-redox" ]; testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */); - testillumos = mseteq illumos [ "x86_64-solaris" ]; + testillumos = mseteq illumos [ "x86_64-solaris2" ]; testlinux = mseteq linux [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-linux" "loongarch64-linux" "m68k-linux" "microblaze-linux" "microblazeel-linux" "mips-linux" "mips64-linux" "mips64el-linux" "mipsel-linux" "powerpc64-linux" "powerpc64le-linux" "riscv32-linux" "riscv64-linux" "s390-linux" "s390x-linux" "x86_64-linux" ]; testnetbsd = mseteq netbsd [ "aarch64-netbsd" "armv6l-netbsd" "armv7a-netbsd" "armv7l-netbsd" "i686-netbsd" "m68k-netbsd" "mipsel-netbsd" "powerpc-netbsd" "riscv32-netbsd" "riscv64-netbsd" "x86_64-netbsd" ]; testopenbsd = mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ]; From 7c77d76f6713530a0b7bf9e34a0d1f14afd6a50c Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 18 Jun 2023 21:35:23 -0700 Subject: [PATCH 07/33] lib/systems: add TODO regarding execFormats --- lib/systems/parse.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index d33e1362c90b9..6c4e3cd8c7945 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -290,6 +290,9 @@ rec { types.kernel = enum (attrValues kernels); + # TODO (@amjoseph): we should eliminate execFormats or move it to + # abis; executable format is a property of the ABI not the kernel. + # This will also clear up the netbsd kludge in tripleFromSystem. kernels = with execFormats; with kernelFamilies; setTypes types.openKernel { # TODO(@Ericson2314): Don't want to mass-rebuild yet to keeping 'darwin' as # the normalized name for macOS. From b14dc66589381feed74a73b5e2d06e0bae517d9e Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 18 Jun 2023 21:35:42 -0700 Subject: [PATCH 08/33] lib/systems: add and check valid kernels for each abi Each kernel supports only a subset of the universe of possible ABIs. This commit explicitly lists (opt-in) the allowable abis for each kernel. Attempting to parse a kernel with an abi which is not on the list will fail. This "search space pruning" is essential to getting our gnu-config agreement tests down to a manageable set of test cases. It also lets us reject nonsense triples instead of trying to handle them exactly the same way gnu-config does. --- lib/systems/parse.nix | 58 +++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 6c4e3cd8c7945..587c260d48b44 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -332,21 +332,21 @@ rec { types.abi = enum (attrValues abis); - abis = setTypes types.openAbi { - cygnus = {}; - msvc = {}; + abis = setTypes types.openAbi rec { + cygnus = { kernels = [ "windows" ]; }; + msvc = { kernels = [ "windows" ]; }; # Note: eabi is specific to ARM and PowerPC. # On PowerPC, this corresponds to PPCEABI. # On ARM, this corresponds to ARMEABI. - eabi = { float = "soft"; }; - eabihf = { float = "hard"; }; + eabi = { float = "soft"; kernels = builtins.attrNames kernels; }; + eabihf = { float = "hard"; kernels = builtins.attrNames kernels; }; # Other architectures should use ELF in embedded situations. - elf = {}; + elf = { kernels = [ ]; }; - androideabi = {}; - android = { + androideabi = { inherit (android) kernels; }; + android = { kernels = [ "linux" ]; assertions = [ { assertion = platform: !platform.isAarch32; message = '' @@ -356,9 +356,9 @@ rec { ]; }; - gnueabi = { float = "soft"; }; - gnueabihf = { float = "hard"; }; - gnu = { + gnueabi = { float = "soft"; inherit (gnu) kernels; }; + gnueabihf = { float = "hard"; inherit (gnu) kernels; }; + gnu = { kernels = [ "freebsd12" "freebsd13" "linux" ]; assertions = [ { assertion = platform: !platform.isAarch32; message = '' @@ -372,27 +372,28 @@ rec { } ]; }; - gnuabi64 = { abi = "64"; }; - muslabi64 = { abi = "64"; }; + gnuabi64 = { abi = "64"; inherit (gnu) kernels; }; + muslabi64 = { abi = "64"; kernels = [ "linux" ]; }; # NOTE: abi=n32 requires a 64-bit MIPS chip! That is not a typo. # It is basically the 64-bit abi with 32-bit pointers. Details: # https://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf - gnuabin32 = { abi = "n32"; }; - muslabin32 = { abi = "n32"; }; + gnuabin32 = { abi = "n32"; inherit (gnu) kernels; }; + muslabin32 = { abi = "n32"; inherit (musl) kernels; }; - gnuabielfv2 = { abi = "elfv2"; }; - gnuabielfv1 = { abi = "elfv1"; }; + gnuabielfv2 = { abi = "elfv2"; kernels = [ "linux" ]; }; + gnuabielfv1 = { abi = "elfv1"; kernels = [ "linux" ]; }; - musleabi = { float = "soft"; }; - musleabihf = { float = "hard"; }; - musl = {}; + musleabi = { float = "soft"; inherit (musl) kernels; }; + musleabihf = { float = "hard"; inherit (musl) kernels; }; + musl = { kernels = [ "linux" ]; }; - uclibceabi = { float = "soft"; }; - uclibceabihf = { float = "hard"; }; - uclibc = {}; + uclibceabi = { float = "soft"; inherit (uclibc) kernels; }; + uclibceabihf = { float = "hard"; inherit (uclibc) kernels; }; + uclibc = { kernels = [ "linux" ]; }; - unknown = {}; + # in gnu-config triples, this abi is actually the empty string "" rather than "-unknown" + unknown = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "openbsd" "redox" "wasi" ]; }; }; ################################################################################ @@ -412,6 +413,15 @@ rec { mkSystem = components: assert types.parsedPlatform.check components; + assert ((components.kernel == kernels.ghcjs) != (components.cpu == cpuTypes.javascript)) + -> throw "cpu==\"javascript\" and kernel==\"ghcjs\" are valid only with each other; you attempted to use cpu==\"${components.cpu.name}\" with kernel==\"${components.kernel.name}\""; + assert !(lib.elem components.kernel.name (components.abi.kernels or [ components.kernel.name ])) && !(isVc4 components) + -> throw "kernel ${components.kernel.name} does not allow abi ${components.abi.name}"; + assert !(isVc4 components -> (with components; vendor.name == "" && kernel.name == "" && abi.name == "elf")) + -> throw (with components; "Broadcom VC4 CPUs may be used only in the grandfathered nonstandard triple `vc4-elf`; you tried to create ${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}"); + assert !(isJavaScript components -> (with components; (vendor.name == "unknown" || vendor.name == "") && kernel == kernels.ghcjs && abi == abis.unknown)) + -> throw (with components; "The special `javascript` \"cpu\" may be used only in the grandfathered nonstandard triple `javascript-unknown-ghcjs`; you tried to create ${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}"); + setType "system" components; mkSkeletonFromList = l: { From 109454aa0e6d4c1ea6cc92c28f4bb311058a7d92 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 18:43:30 -0700 Subject: [PATCH 09/33] lib/systems: move powerpc64-be ABI-defaulting out of the parser In PR #182807 we decided that big-endian PowerPC64 should default to the new elfv2 ABI. The implementation in that PR did the defaulting by adding two lines in the *triple parser*, which is turning out to be problematic; it means that our parse-then-unparse roundtrip disagrees with gnu-config. This commit therefore reverts just those two lines. If the defaulting logic needs to be moved elsewhere that should be done. https://github.com/NixOS/nixpkgs/pull/182807/files#r1234650738 --- lib/systems/parse.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 587c260d48b44..bb1c99292781f 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -498,8 +498,6 @@ rec { if lib.versionAtLeast (parsed.cpu.version or "0") "6" then abis.gnueabihf else abis.gnueabi - # Default ppc64 BE to ELFv2 - else if isPower64 parsed && isBigEndian parsed then abis.gnuabielfv2 else abis.gnu else abis.unknown; }; From 637cc8af145b0a21e719f2aeb907f36513d39b31 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 18:50:07 -0700 Subject: [PATCH 10/33] lib/systems: default arm-apple-linux to -gnu ABI This is required for agreement with gnu-config. --- lib/systems/parse.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index bb1c99292781f..c1c38e2a7c9b7 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -495,7 +495,8 @@ rec { /**/ if args ? abi then getAbi args.abi else if isLinux parsed || isWindows parsed then if isAarch32 parsed then - if lib.versionAtLeast (parsed.cpu.version or "0") "6" + if parsed.vendor == vendors.apple then abis.gnu + else if lib.versionAtLeast (parsed.cpu.version or "0") "6" then abis.gnueabihf else abis.gnueabi else abis.gnu From 9413a2c3a575e8df60053b87646cd769197942ee Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 18:51:50 -0700 Subject: [PATCH 11/33] lib/systems: add vendors.{ibm,xilinx} --- lib/systems/parse.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index c1c38e2a7c9b7..3cf12f7731679 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -230,7 +230,9 @@ rec { vendors = setTypes types.openVendor { apple = {}; pc = {}; + ibm = {}; knuth = {}; + xilinx = {}; # Actually matters, unlocking some MinGW-w64-specific options in GCC. See # bottom of https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/ From dc332ea6362aa29251339c74f90ba988af710d18 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 19:05:00 -0700 Subject: [PATCH 12/33] lib/systems: omit optExecFormat from triples gnu-config doesn't include this. --- lib/systems/parse.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 3cf12f7731679..a2e3efdeca545 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -529,7 +529,7 @@ rec { cpu = cpu.name; vendor = vendor.name; kernel = kernelName kernel; - inherit optExecFormat; + #inherit optExecFormat; abi = abi.name; }; From a3cf669407915d24ef1f8a874af742dfa55af50d Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 20 Jun 2023 04:24:43 -0700 Subject: [PATCH 13/33] lib/systems: fix abi inference for aarch32-linux --- lib/systems/parse.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index a2e3efdeca545..46743822f77f1 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -498,6 +498,7 @@ rec { else if isLinux parsed || isWindows parsed then if isAarch32 parsed then if parsed.vendor == vendors.apple then abis.gnu + else if isLinux parsed then abis.gnu else if lib.versionAtLeast (parsed.cpu.version or "0") "6" then abis.gnueabihf else abis.gnueabi From eee685f8e3952aae29065a35995acc6b012e05ec Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 19 Jun 2023 18:56:11 -0700 Subject: [PATCH 14/33] lib/systems: fix vendor fallback logic This commit fixes the logic for handling missing/unknown vendor fields in triples, and extends it to handle mmix and microblaze CPU-types. --- lib/systems/parse.nix | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 46743822f77f1..7e4815c7015a5 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -471,9 +471,7 @@ rec { # This should revert the job done by config.guess from the gcc compiler. mkSystemFromSkeleton = { cpu - , # Optional, but fallback too complex for here. - # Inferred below instead. - vendor ? assert false; null + , vendor ? "" , kernel , # Also inferred below abi ? assert false; null @@ -483,13 +481,36 @@ rec { getKernel = name: kernels.${name} or (throw "Unknown kernel: ${name}"); getAbi = name: abis.${name} or (throw "Unknown ABI: ${name}"); + vendor_ = getVendor vendor; + + # These the three CPUs for which gnu-config will sometimes + # clobber an explicitly-specified `-unknown` vendor with + # something else. + clobberedVendor = + if isS390 parsed then vendors.ibm + else if isMicroBlaze parsed then vendors.xilinx + else if isMmix parsed then vendors.knuth + else if isVc4 parsed then vendors."" # hack for nonstandard triple + else vendors.unknown; + parsed = { cpu = getCpu args.cpu; vendor = - /**/ if args ? vendor then getVendor args.vendor - else if isDarwin parsed then vendors.apple - else if isWindows parsed then vendors.pc - else vendors.unknown; + if vendor_ == vendors.unknown then clobberedVendor + else if vendor_ != vendors."" then vendor_ + else if (isx86_64 parsed || isi686 parsed) && + parsed.abi == abis.gnu then + vendors.unknown # nixpkgs-specific behavior + else if (isx86_64 parsed || isAarch64 parsed) && + isLittleEndian parsed && + parsed.kernel == kernels.darwin && + parsed.abi == abis.unknown then + vendors.apple # nixpkgs-specific behavior + else if isx86 parsed && isLinux parsed then vendors.pc + else if (args?abi && (args.abi=="eabi" || args.abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ + else if isx86 parsed then vendors.pc + else clobberedVendor; + kernel = if hasPrefix "darwin" args.kernel then getKernel "darwin" else if hasPrefix "netbsd" args.kernel then getKernel "netbsd" else getKernel (removeAbiSuffix args.kernel); From 2a244cd46673223f8f9f23aaa794b93b64f62ade Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 18 Jun 2023 22:07:53 -0700 Subject: [PATCH 15/33] lib/tests/triples.nix: add gnu-config conformance test suite This commit adds lib/tests/triples.nix, which exhaustively tests that our platform triple parse-then-unparse round-trip agrees with gnu-config for all inputs that it accepts (it may -- and does -- reject triples which `gnu-config` accepts). --- lib/systems/parse.nix | 8 +++ lib/tests/release.nix | 12 ++++ lib/tests/triples.nix | 157 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 lib/tests/triples.nix diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 7e4815c7015a5..b0fdf81e77c41 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -577,6 +577,14 @@ rec { else if kernel == "windows" then "${cpu}${optVendor}-mingw32" else "${cpu}${optVendor}-${kernel}${optExecFormat}${optAbi}"; + # To "canonicalize" a triple is to parse it and then unparse (turn + # back into a string) it. + canonicalize = triple: + lib.pipe triple [ + mkSystemFromString # parse + tripleFromSystem # unparse + ]; + ################################################################################ } diff --git a/lib/tests/release.nix b/lib/tests/release.nix index 843180490bb2b..43d8580c69219 100644 --- a/lib/tests/release.nix +++ b/lib/tests/release.nix @@ -8,6 +8,13 @@ let lib = import ../.; + + # This should be built once and kept in OfBorg's long-running + # store (not the ephemeral store which is `nix-store --init`ed + # below). This is generating the *expected* test results, so it + # doesn't matter what version of Nix is used. + triples-expected = (import ./triples.nix).expected-output-from-gnu-config; + testWithNix = nix: pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}" { buildInputs = [ @@ -60,6 +67,11 @@ let echo "Running lib/tests/systems.nix" [[ $(nix-instantiate --eval --strict lib/tests/systems.nix | tee /dev/stderr) == '[ ]' ]]; + echo "Running lib/tests/triples.nix" + set -x + [[ $(nix-instantiate --eval --strict -E '(import ${../..}/lib/tests/triples.nix).tests ${triples-expected.outPath}' | tee /dev/stderr) == '[ ]' ]]; + set +x + mkdir $out echo success > $out/${nix.version} ''; diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix new file mode 100644 index 0000000000000..83fa5cfe52416 --- /dev/null +++ b/lib/tests/triples.nix @@ -0,0 +1,157 @@ +# Run: +# [nixpkgs]$ nix-build -o expected-output lib/tests/triples.nix -A expected-output-from-gnu-config +# [nixpkgs]$ nix-instantiate --eval --strict -E '(import lib/tests/triples.nix).tests ./expected-output' +# Expected output: [], or the failed cases +# Two steps are required to avoid IFD. +# +# This file tests our triple-parser, but it needs access to `pkgs` +# because `pkgs.gnu-config` is our source of truth for the +# correctness of parsing. This file does not test `pkgs`; it tests +# `lib`. +# +# The tests below attempt to verify that parsing followed by +# unparsing behaves the same way as `gnu-config`, except in the +# rare and unusual cases where nixpkgs has carefully and +# deliberately decided to diverge from it. +# +# We use `gnu-config` as our source of ground truth not because it +# is elegant (it isn't) or sensible (it isn't), but because it: +# +# 1. has an executable (i.e. unambiguous) specification +# 2. covers a superset of the systems on which nixpkgs could be useful +# 3. is *not* under nixpkgs' control (bickering/drama avoidance) +# 4. emanates from an organization (GNU) which understands that +# the taxonomy is not merely an implementation detail of one of +# their software products, and has demonstrated this +# understanding over an extended period of time (multiple +# decades). +# + +let + lib = import ../default.nix; + pkgs = import ../.. {}; + + inherit (lib.systems.parse) canonicalize; + + filtered-triples = lib.pipe null [ + + # start with the lists of known possibilities for each field + (_: with lib.systems.parse; { + cpu = cpuTypes; + vendor = vendors; + kernel = kernels; + abi = abis; + }) + + # drop the structure; keep only the `name` attribute for each possibility + (builtins.mapAttrs (_: lib.mapAttrsToList (k: v: v.name or k))) + + # generate every possible {cpu,vendor,kernel,abi} combination + lib.cartesianProductOfSets + + # Then form a string triple for each of them + (map lib.systems.parse.tripleFromSkeleton) + + # Filter out any triples for which nixpkgs throws while + # attempting to parse. This makes the tests much faster since + # gnu-config needs to fork() a shell for each test case. This is + # safe since it is okay for nixpkgs' set of acceptable triples to + # be a subset of gnu-config's set of acceptable triples. + (lib.filter (triple: + (builtins.tryEval (canonicalize triple)) + .success)) + + # + # The following are triples which we have deliberately + # chosen to accept differently than gnu-config. Entries here + # impose an ongoing burden on nixpkgs, so PRs which add new + # triples here should allow for a longer review period and + # should be advertised widely. + # + (lib.filter (v: + + # gnu-config infers the vendor "pc" for these Nix doubles, but + # nixpkgs has used ${cpu}-unknown-linux-gnu for a very long time. + v != "x86_64-linux" && v != "i686-linux" && + v != "x86_64-linux-gnu" && v != "i686-linux-gnu" && + v != "x86_64-darwin" && v != "aarch64-darwin" && + + # We have been shipping Broadcom VC4 forks of gcc/binutils + # using nonstandard triples since 4aa1ffae041bb9c65eb3067e9dbaaa70710ed100 + (canonicalize v) != "vc4-elf" + + # This triple is special to GHC/Cabal/GHCJS and not recognized by autotools + # See: https://gitlab.haskell.org/ghc/ghc/-/commit/6636b670233522f01d002c9b97827d00289dbf5c + # https://github.com/ghcjs/ghcjs/issues/53 + && (canonicalize v) != "javascript-unknown-ghcjs" + )) + ]; +in { + # This derivation invokes `gnu-config` on `$NIX_BUILD_CORES`-many + # cores to generate the expected test results. The entire result + # set is saved as a single outpath, and is only rebuilt when the + # set of valid {cpus, vendors, kernels, abis} changes, which + # happens very infrequently. + # + expected-output-from-gnu-config = + pkgs.runCommandLocal "testTripleFromString" { } ( + + # We create a `Makefile` with a target for each test as a + # cheap way of using multiple cores + '' + echo '%:; ${pkgs.gnu-config}/config.sub $* &> results/$* || true' > Makefile + '' + + # Now we run `make` on a gigantic list of targets (one for + # each triple we want to test) + + '' + mkdir results + make -j$NIX_BUILD_CORES --no-builtin-rules --keep-going ${lib.concatStringsSep " " filtered-triples} + '' + + # And then dump all the results as a single JSON file. This + # ensures that even for jillions of test cases, only a single + # derivation and outpath will be left on OfBorg and Hydra. + + '' + cd results + (echo '{' + for triple in *; do + echo '"'$triple'":' + echo -n '"' + cat $triple + echo '",' + done + echo '"":""}') | tr -d "\n" > $out + ''); + + # colordiff -u <(nix eval --json -f lib/tests/triples.nix results-from-nixpkgs | jq) + results-from-nixpkgs = + lib.pipe filtered-triples [ + (map + (triple: lib.nameValuePair + triple + (canonicalize triple))) + lib.listToAttrs + ]; + + # Construct a test case for each element of `filtered-triples`. + # The `expected-output` is taken as a parameter rather than from + # the sibling attribute above in order to avoid IFD (see + # `lib/tests/release.nix`). + tests = expected-output: + let expected-parsed = builtins.fromJSON (builtins.readFile expected-output); + in lib.runTests + (lib.pipe filtered-triples [ + (map + (triple: + let + testName = "testTripleFromString_${triple}"; + in lib.nameValuePair testName { + expected = expected-parsed.${triple}; + expr = canonicalize triple; + }) + ) + builtins.listToAttrs + ]); +} + From 19d9620d234cdcc55ecb597880b8415d952ac3a4 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 20 Jun 2023 16:03:04 -0700 Subject: [PATCH 16/33] lib/systems: add vendors.solo5 With this commit, we now parse or reject the following identically to gnu-config: - aarch64-solo5-none (accept) - aarch64-solo5-none-elf (reject) Closes #165836. --- lib/systems/parse.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index b0fdf81e77c41..c727763ef1f31 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -233,6 +233,7 @@ rec { ibm = {}; knuth = {}; xilinx = {}; + solo5 = {}; # Actually matters, unlocking some MinGW-w64-specific options in GCC. See # bottom of https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/ @@ -453,6 +454,7 @@ rec { } # cpu-vendor-os else if elemAt l 1 == "apple" || + elemAt l 1 == "solo5" || elem (elemAt l 2) [ "wasi" "redox" "mmixware" "ghcjs" "mingw32" ] || hasPrefix "freebsd" (elemAt l 2) || hasPrefix "netbsd" (elemAt l 2) || From b414cc9947e642593cbfdbb83c3652494b0a5035 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 20 Jun 2023 16:22:58 -0700 Subject: [PATCH 17/33] lib/systems: add kernels."", distinct from kernels.none This commit adds support for triples with a missing kernel, rather than kernel="none". It also adds a parser case for triples which have a vendor and abi, but no kernel. This allows to parse "*-unknown-elf" triples. Closes #230160. --- lib/systems/inspect.nix | 2 +- lib/systems/parse.nix | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 8aba8f8913711..fc98bcfd051a5 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -84,7 +84,7 @@ rec { isRedox = { kernel = kernels.redox; }; isGhcjs = { kernel = kernels.ghcjs; }; isGenode = { kernel = kernels.genode; }; - isNone = { kernel = kernels.none; }; + isNone = [ { kernel = kernels.none; } { kernel = kernels.""; } ]; isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; isGnu = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ]; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index c727763ef1f31..6556eef9897cc 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -309,6 +309,7 @@ rec { linux = { execFormat = elf; families = { }; }; netbsd = { execFormat = elf; families = { inherit bsd; }; }; none = { execFormat = unknown; families = { }; }; + "" = { execFormat = unknown; families = { }; }; openbsd = { execFormat = elf; families = { inherit bsd; }; }; solaris2 = { execFormat = elf; families = { }; name = "solaris"; version = 2; }; wasi = { execFormat = wasm; families = { }; }; @@ -346,7 +347,7 @@ rec { eabihf = { float = "hard"; kernels = builtins.attrNames kernels; }; # Other architectures should use ELF in embedded situations. - elf = { kernels = [ ]; }; + elf = { kernels = [ "" ]; }; androideabi = { inherit (android) kernels; }; android = { kernels = [ "linux" ]; @@ -396,7 +397,7 @@ rec { uclibc = { kernels = [ "linux" ]; }; # in gnu-config triples, this abi is actually the empty string "" rather than "-unknown" - unknown = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "openbsd" "redox" "wasi" ]; }; + unknown = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "wasi" ]; }; }; ################################################################################ @@ -441,12 +442,21 @@ rec { else if elemAt l 1 == "windows" then { cpu = elemAt l 0; kernel = "windows"; abi = "msvc"; } else if (elemAt l 1) == "elf" - then { cpu = elemAt l 0; kernel = "none"; abi = elemAt l 1; } + then { cpu = elemAt l 0; kernel = ""; abi = elemAt l 1; } else { cpu = elemAt l 0; kernel = elemAt l 1; }; "3" = + # cpu-vendor-""-abi + if elemAt l 1 == "unknown" && elemAt l 2 == "elf" + then { + cpu = elemAt l 0; + vendor = elemAt l 1; + kernel = ""; + abi = elemAt l 2; + } # cpu-kernel-environment - if elemAt l 1 == "linux" || - elem (elemAt l 2) ["eabi" "eabihf" "elf" "gnu"] + else if elemAt l 1 == "linux" || + elemAt l 1 == "none" || + elem (elemAt l 2) ["eabi" "eabihf" "elf" "gnu"] then { cpu = elemAt l 0; kernel = elemAt l 1; @@ -569,6 +579,7 @@ rec { tripleFromSkeleton = { cpu, vendor, kernel, optExecFormat?"", abi }: let optAbi = lib.optionalString (abi != "unknown") "-${abi}"; optVendor = lib.optionalString (vendor != "") "-${vendor}"; + optKernel = lib.optionalString (kernel != "") "-${kernel}"; in # gnu-config considers "mingw32" and "cygwin" to be kernels. # This is obviously bogus, which is why nixpkgs has historically @@ -577,7 +588,7 @@ rec { # quirk when unparsing in order to round-trip correctly. if abi == "cygnus" then "${cpu}${optVendor}-cygwin" else if kernel == "windows" then "${cpu}${optVendor}-mingw32" - else "${cpu}${optVendor}-${kernel}${optExecFormat}${optAbi}"; + else "${cpu}${optVendor}${optKernel}${optExecFormat}${optAbi}"; # To "canonicalize" a triple is to parse it and then unparse (turn # back into a string) it. From b8da7cd02e5cc094b5211ede1f24dae02892441d Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 27 Jun 2023 21:14:50 -0700 Subject: [PATCH 18/33] implement formatting suggestion from @RaitoBezarius --- lib/systems/parse.nix | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 6556eef9897cc..4f160510a307e 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -417,14 +417,35 @@ rec { mkSystem = components: assert types.parsedPlatform.check components; - assert ((components.kernel == kernels.ghcjs) != (components.cpu == cpuTypes.javascript)) - -> throw "cpu==\"javascript\" and kernel==\"ghcjs\" are valid only with each other; you attempted to use cpu==\"${components.cpu.name}\" with kernel==\"${components.kernel.name}\""; - assert !(lib.elem components.kernel.name (components.abi.kernels or [ components.kernel.name ])) && !(isVc4 components) - -> throw "kernel ${components.kernel.name} does not allow abi ${components.abi.name}"; - assert !(isVc4 components -> (with components; vendor.name == "" && kernel.name == "" && abi.name == "elf")) - -> throw (with components; "Broadcom VC4 CPUs may be used only in the grandfathered nonstandard triple `vc4-elf`; you tried to create ${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}"); - assert !(isJavaScript components -> (with components; (vendor.name == "unknown" || vendor.name == "") && kernel == kernels.ghcjs && abi == abis.unknown)) - -> throw (with components; "The special `javascript` \"cpu\" may be used only in the grandfathered nonstandard triple `javascript-unknown-ghcjs`; you tried to create ${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}"); + assert with components; + (kernel == kernels.ghcjs) != (cpu == cpuTypes.javascript) + -> throw '' + cpu "javascript" and kernel "ghcjs" are valid only with each other; + you attempted to use cpu "${components.cpu.name}" with kernel + "${components.kernel.name}" + ''; + assert with components; + !(lib.elem kernel.name (abi.kernels or [ kernel.name ])) && + !(isVc4 components) + -> throw '' + kernel ${components.kernel.name} does not allow abi ${components.abi.name} + ''; + assert with components; + !(isVc4 components -> (with components; vendor.name == "" && kernel.name == "" && abi.name == "elf")) + -> throw '' + Broadcom VC4 CPUs may be used only in the nonstandard triple "vc4-elf". + You tried to create "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}". + ''; + assert with components; + !(isJavaScript components -> + (vendor.name == "unknown" || vendor.name == "") && + kernel == kernels.ghcjs && + abi == abis.unknown) + -> throw '' + The special "javascript" cpu may be used only in the nonstandard triple + "javascript-unknown-ghcjs". You tried to create + "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}" + ''; setType "system" components; From 0e3ad85d19ddf0e9ee933c2d325167e42dd3caee Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 19 Aug 2023 14:10:00 -0700 Subject: [PATCH 19/33] lib.systems: clean up abi defaulting --- lib/systems/parse.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 4f160510a307e..40c70ac3d49b7 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -507,7 +507,7 @@ rec { , vendor ? "" , kernel , # Also inferred below - abi ? assert false; null + abi ? null } @ args: let getCpu = name: cpuTypes.${name} or (throw "Unknown CPU type: ${name}"); getVendor = name: vendors.${name} or (throw "Unknown vendor: ${name}"); @@ -540,7 +540,7 @@ rec { parsed.abi == abis.unknown then vendors.apple # nixpkgs-specific behavior else if isx86 parsed && isLinux parsed then vendors.pc - else if (args?abi && (args.abi=="eabi" || args.abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ + else if ((abi=="eabi" || abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ else if isx86 parsed then vendors.pc else clobberedVendor; @@ -548,7 +548,7 @@ rec { else if hasPrefix "netbsd" args.kernel then getKernel "netbsd" else getKernel (removeAbiSuffix args.kernel); abi = - /**/ if args ? abi then getAbi args.abi + /**/ if abi != null then getAbi abi else if isLinux parsed || isWindows parsed then if isAarch32 parsed then if parsed.vendor == vendors.apple then abis.gnu From 494246cb831d205773d28c93655d1b6112751446 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 18 Aug 2023 23:32:16 -0700 Subject: [PATCH 20/33] lib.systems: allow *-none-elf --- lib/systems/parse.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 40c70ac3d49b7..c9764293b96b4 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -347,7 +347,7 @@ rec { eabihf = { float = "hard"; kernels = builtins.attrNames kernels; }; # Other architectures should use ELF in embedded situations. - elf = { kernels = [ "" ]; }; + elf = { kernels = [ "none" "" ]; }; androideabi = { inherit (android) kernels; }; android = { kernels = [ "linux" ]; @@ -446,7 +446,11 @@ rec { "javascript-unknown-ghcjs". You tried to create "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}" ''; - + # The following assertions can (and must) be removed when our gnu-config is bumped to at least 2023-07-31 + assert with components; vendor.name != "" && kernel.name == "none" && abi.name == "elf" + -> throw "two component *-*-none-elf triples are not allowed; please omit the vendor"; + assert with components; cpu.name != "vc4" && vendor.name == "" && kernel.name == "" && abi.name == "elf" + -> throw "two component *-elf triples are not allowed, except for vc4-elf"; setType "system" components; mkSkeletonFromList = l: { @@ -542,6 +546,7 @@ rec { else if isx86 parsed && isLinux parsed then vendors.pc else if ((abi=="eabi" || abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ else if isx86 parsed then vendors.pc + else if isNone parsed && vendor_ == vendors."" && abi == "elf" then vendors."" else clobberedVendor; kernel = if hasPrefix "darwin" args.kernel then getKernel "darwin" From 85835813172f978184ac1a926473d367f7572845 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 18 Aug 2023 20:15:21 -0700 Subject: [PATCH 21/33] lib.systems.parse: rename abis.unknown to abis."" --- lib/systems/parse.nix | 20 ++++++--- lib/tests/triples.nix | 2 +- pkgs/build-support/rust/lib/default.nix | 2 +- .../gnu-config/javascript-unknown-ghcjs.patch | 43 +++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 pkgs/development/libraries/gnu-config/javascript-unknown-ghcjs.patch diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index c9764293b96b4..e9b4d139b4813 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -334,7 +334,7 @@ rec { merge = mergeOneOption; }; - types.abi = enum (attrValues abis); + types.abi = enum (attrValues (builtins.removeAttrs abis ["unknown"])); abis = setTypes types.openAbi rec { cygnus = { kernels = [ "windows" ]; }; @@ -396,8 +396,14 @@ rec { uclibceabihf = { float = "hard"; inherit (uclibc) kernels; }; uclibc = { kernels = [ "linux" ]; }; + "" = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "wasi" ]; }; + # in gnu-config triples, this abi is actually the empty string "" rather than "-unknown" - unknown = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "wasi" ]; }; + unknown = + # Added 2023-08-18. When removing, please also remove the + # `removeAttrs ["unknown"]` in lib.tests.triples and + # lib.systems.types.abi + abis."" // { assertions = lib.warn "please use abis.\"\" instead; \"unknown\" is not a valid ABI." [ ]; }; }; ################################################################################ @@ -440,7 +446,7 @@ rec { !(isJavaScript components -> (vendor.name == "unknown" || vendor.name == "") && kernel == kernels.ghcjs && - abi == abis.unknown) + abi == abis."") -> throw '' The special "javascript" cpu may be used only in the nonstandard triple "javascript-unknown-ghcjs". You tried to create @@ -455,7 +461,7 @@ rec { mkSkeletonFromList = l: { "1" = if elemAt l 0 == "avr" - then { cpu = elemAt l 0; kernel = "none"; abi = "unknown"; } + then { cpu = elemAt l 0; kernel = "none"; abi = ""; } else throw "Target specification with 1 components is ambiguous"; "2" = # We only do 2-part hacks for things Nix already supports if elemAt l 1 == "cygwin" @@ -541,7 +547,7 @@ rec { else if (isx86_64 parsed || isAarch64 parsed) && isLittleEndian parsed && parsed.kernel == kernels.darwin && - parsed.abi == abis.unknown then + parsed.abi == abis."" then vendors.apple # nixpkgs-specific behavior else if isx86 parsed && isLinux parsed then vendors.pc else if ((abi=="eabi" || abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ @@ -562,7 +568,7 @@ rec { then abis.gnueabihf else abis.gnueabi else abis.gnu - else abis.unknown; + else abis.""; }; in mkSystem parsed; @@ -603,7 +609,7 @@ rec { }); tripleFromSkeleton = { cpu, vendor, kernel, optExecFormat?"", abi }: let - optAbi = lib.optionalString (abi != "unknown") "-${abi}"; + optAbi = lib.optionalString (abi != "") "-${abi}"; optVendor = lib.optionalString (vendor != "") "-${vendor}"; optKernel = lib.optionalString (kernel != "") "-${kernel}"; in diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index 83fa5cfe52416..31930f4e749dd 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -40,7 +40,7 @@ let cpu = cpuTypes; vendor = vendors; kernel = kernels; - abi = abis; + abi = builtins.removeAttrs abis [ "unknown" ]; # abis.unknown is a deprecation warning }) # drop the structure; keep only the `name` attribute for each possibility diff --git a/pkgs/build-support/rust/lib/default.nix b/pkgs/build-support/rust/lib/default.nix index 48e218b313653..2c0458cffed47 100644 --- a/pkgs/build-support/rust/lib/default.nix +++ b/pkgs/build-support/rust/lib/default.nix @@ -56,7 +56,7 @@ rec { }.${cpu.name} or cpu.name; vendor_ = toTargetVendor platform; in platform.rustc.config - or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "") "-${abi.name}"}"; # Returns the name of the rust target if it is standard, or the json file # containing the custom target spec. diff --git a/pkgs/development/libraries/gnu-config/javascript-unknown-ghcjs.patch b/pkgs/development/libraries/gnu-config/javascript-unknown-ghcjs.patch new file mode 100644 index 0000000000000..4a43180520770 --- /dev/null +++ b/pkgs/development/libraries/gnu-config/javascript-unknown-ghcjs.patch @@ -0,0 +1,43 @@ +diff --git a/config.sub b/config.sub +index 6ae2502..c2c9200 100755 +--- a/config.sub ++++ b/config.sub +@@ -1200,6 +1200,7 @@ case $cpu-$vendor in + | d10v | d30v | dlx | dsp16xx \ + | e2k | elxsi | epiphany \ + | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \ ++ | javascript \ + | h8300 | h8500 \ + | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ +@@ -1702,6 +1703,11 @@ case $os in + # VxWorks passes extra cpu info in the 4th filed. + simlinux | simwindows | spe) + ;; ++ # The "javascript-unknown-ghcjs" triple is used by GHC; we ++ # accept it here in order to tolerate that, but reject any ++ # variations. ++ ghcjs) ++ ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. +@@ -1884,6 +1890,18 @@ case $vendor in + ;; + esac + ++# Here we handle the constraint that a (synthetic) cpu and os are ++# valid only in combination with each other and nowhere else. ++case $cpu-$os in ++ javascript-ghcjs) ++ ;; ++ javascript-* | *-ghcjs) ++ echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os'" 1>&2 ++ exit 1 ++ ;; ++esac ++ ++ + echo "$cpu-$vendor-${kernel:+$kernel-}$os" + exit + From 30d295fc6f0c25ace82a3386bb205d46885051a8 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 21 Oct 2023 23:55:42 -0700 Subject: [PATCH 22/33] lib.systems.parse: abis.gnu: allow kernels.windows --- lib/systems/parse.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index e9b4d139b4813..8f610d5cdcf91 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -362,7 +362,7 @@ rec { gnueabi = { float = "soft"; inherit (gnu) kernels; }; gnueabihf = { float = "hard"; inherit (gnu) kernels; }; - gnu = { kernels = [ "freebsd12" "freebsd13" "linux" ]; + gnu = { kernels = [ "freebsd12" "freebsd13" "linux" "windows" ]; assertions = [ { assertion = platform: !platform.isAarch32; message = '' From 9f2a61fcd7cd9cf4cbb66a67b2802e0fd7bb5f3e Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 21 Oct 2023 23:56:09 -0700 Subject: [PATCH 23/33] lib.systems.parse: remove assertion now that gnu-config has bumped --- lib/systems/parse.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 8f610d5cdcf91..5a059292b50bf 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -452,11 +452,6 @@ rec { "javascript-unknown-ghcjs". You tried to create "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}" ''; - # The following assertions can (and must) be removed when our gnu-config is bumped to at least 2023-07-31 - assert with components; vendor.name != "" && kernel.name == "none" && abi.name == "elf" - -> throw "two component *-*-none-elf triples are not allowed; please omit the vendor"; - assert with components; cpu.name != "vc4" && vendor.name == "" && kernel.name == "" && abi.name == "elf" - -> throw "two component *-elf triples are not allowed, except for vc4-elf"; setType "system" components; mkSkeletonFromList = l: { From f3441fcb28d5c4ce9f34df39eeb3298969a32c41 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 22 Oct 2023 05:50:57 -0700 Subject: [PATCH 24/33] lib.systems.inspect: exclude kernel="" from isNone --- lib/systems/inspect.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index fc98bcfd051a5..8aba8f8913711 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -84,7 +84,7 @@ rec { isRedox = { kernel = kernels.redox; }; isGhcjs = { kernel = kernels.ghcjs; }; isGenode = { kernel = kernels.genode; }; - isNone = [ { kernel = kernels.none; } { kernel = kernels.""; } ]; + isNone = { kernel = kernels.none; }; isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; isGnu = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ]; From 21882ca62be7d7634326c373a541c062a584436f Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 22 Oct 2023 05:51:25 -0700 Subject: [PATCH 25/33] lib.systems.parse: do not infer vendor="pc" for *-elf --- lib/systems/parse.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 5a059292b50bf..185a36af0f981 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -546,8 +546,8 @@ rec { vendors.apple # nixpkgs-specific behavior else if isx86 parsed && isLinux parsed then vendors.pc else if ((abi=="eabi" || abi=="eabihf")) && !(isLinux parsed || isNetBSD parsed) then vendor_ - else if isx86 parsed then vendors.pc else if isNone parsed && vendor_ == vendors."" && abi == "elf" then vendors."" + else if isx86 parsed then vendors.pc else clobberedVendor; kernel = if hasPrefix "darwin" args.kernel then getKernel "darwin" From 7b6cd7d3ecfcb4ba6714d6277c23cbf9df7d3324 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 22 Oct 2023 06:10:00 -0700 Subject: [PATCH 26/33] lib.tests.systems: include lib.systems.doubles.vc4 --- lib/tests/systems.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index 35f4f61b0f46c..ba40b4e11d1b3 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -36,7 +36,7 @@ lib.runTests ( # sanity check before committing :). (with lib.systems.doubles; { - testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ mmix ++ js ++ genode ++ redox); + testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ mmix ++ js ++ genode ++ redox ++ vc4); testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv6l-netbsd" "armv6l-none" "armv7a-linux" "armv7a-netbsd" "armv7l-linux" "armv7l-netbsd" "arm-none" "armv7a-darwin" ]; testarmv7 = mseteq armv7 [ "armv7a-darwin" "armv7a-linux" "armv7l-linux" "armv7a-netbsd" "armv7l-netbsd" ]; From 8707d2cf20162885629bb480385687f6770b6bcf Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 22 Oct 2023 15:32:54 -0700 Subject: [PATCH 27/33] lib.systems.triples: remove exception for ghcjs-javascript (gnu-config now understands it) gnu-config commit 6c78704d542cebfb56d17474fe9f8395e9defb94 added upstream support for ghc's javascript triple, so we can remove the exception now. --- lib/tests/triples.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index 31930f4e749dd..fa87a58581ab1 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -79,11 +79,6 @@ let # We have been shipping Broadcom VC4 forks of gcc/binutils # using nonstandard triples since 4aa1ffae041bb9c65eb3067e9dbaaa70710ed100 (canonicalize v) != "vc4-elf" - - # This triple is special to GHC/Cabal/GHCJS and not recognized by autotools - # See: https://gitlab.haskell.org/ghc/ghc/-/commit/6636b670233522f01d002c9b97827d00289dbf5c - # https://github.com/ghcjs/ghcjs/issues/53 - && (canonicalize v) != "javascript-unknown-ghcjs" )) ]; in { From 62b5c357c7c8b7252eb4ea429020ab1e7730ef80 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 30 Oct 2023 00:03:05 -0700 Subject: [PATCH 28/33] lib/systems/parse.nix: remove commented-out obsolete attribute --- lib/systems/parse.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 185a36af0f981..f45d402d3e062 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -590,7 +590,6 @@ rec { cpu = cpu.name; vendor = vendor.name; kernel = kernelName kernel; - #inherit optExecFormat; abi = abi.name; }; From 95d0b0ed69987e6712e61ba2d6c14215f64ecd4e Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 30 Oct 2023 00:04:23 -0700 Subject: [PATCH 29/33] lib/tests/triples.nix: reword comment --- lib/tests/triples.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index fa87a58581ab1..5e04563016441 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -19,7 +19,7 @@ # # 1. has an executable (i.e. unambiguous) specification # 2. covers a superset of the systems on which nixpkgs could be useful -# 3. is *not* under nixpkgs' control (bickering/drama avoidance) +# 3. is *not* under nixpkgs' control, to minimize bikeshedding/debate # 4. emanates from an organization (GNU) which understands that # the taxonomy is not merely an implementation detail of one of # their software products, and has demonstrated this From dd58ed9d87eb72d0dfc04aaab1050ccffe9ad5ba Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 30 Oct 2023 00:17:44 -0700 Subject: [PATCH 30/33] lib/tests/triples.nix: add --silent to make invocation --- lib/tests/triples.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index 5e04563016441..4f7a32cae53c6 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -101,7 +101,7 @@ in { # each triple we want to test) + '' mkdir results - make -j$NIX_BUILD_CORES --no-builtin-rules --keep-going ${lib.concatStringsSep " " filtered-triples} + make --silent -j$NIX_BUILD_CORES --no-builtin-rules --keep-going ${lib.concatStringsSep " " filtered-triples} '' # And then dump all the results as a single JSON file. This From 014902ce4b4fa9fbe725e553de88e50e35155a9c Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 1 Nov 2023 00:09:29 -0700 Subject: [PATCH 31/33] lib/tests/triples.nix: add *-*-uefi exception --- lib/systems/doubles.nix | 3 +++ lib/systems/inspect.nix | 1 + lib/systems/parse.nix | 8 +++++++- lib/tests/triples.nix | 13 +++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index f6e92890b298f..4323518798425 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -53,6 +53,9 @@ let # Redox "x86_64-redox" + # UEFI + "x86_64-uefi" "i686-uefi" "aarch64-uefi" + # WASI "wasm64-wasi" "wasm32-wasi" diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 8aba8f8913711..f4c29e49f00ca 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -85,6 +85,7 @@ rec { isGhcjs = { kernel = kernels.ghcjs; }; isGenode = { kernel = kernels.genode; }; isNone = { kernel = kernels.none; }; + isUefi = { kernel = kernels.uefi; }; isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; isGnu = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ]; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index f45d402d3e062..81a1e7064621a 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -318,6 +318,7 @@ rec { ghcjs = { execFormat = unknown; families = { }; }; genode = { execFormat = elf; families = { }; }; mmixware = { execFormat = unknown; families = { }; }; + uefi = { execFormat = pe; families = { }; }; } // { # aliases # 'darwin' is the kernel for all of them. We choose macOS by default. darwin = kernels.macos; @@ -396,7 +397,7 @@ rec { uclibceabihf = { float = "hard"; inherit (uclibc) kernels; }; uclibc = { kernels = [ "linux" ]; }; - "" = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "wasi" ]; }; + "" = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "uefi" "wasi" ]; }; # in gnu-config triples, this abi is actually the empty string "" rather than "-unknown" unknown = @@ -452,6 +453,11 @@ rec { "javascript-unknown-ghcjs". You tried to create "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}" ''; + assert with components; + isUefi components + && (!(vendor.name == "unknown" || vendor.name == "") || + !(cpu.name == "aarch64" || isx86_64 components || isx86_32 components)) + -> throw "{x86_64,i686,aarch64}-unknown-uefi are nixpkgs-specific exceptions; no other uefi triples are currently allowed"; setType "system" components; mkSkeletonFromList = l: { diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index 4f7a32cae53c6..f322626f2c020 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -79,6 +79,19 @@ let # We have been shipping Broadcom VC4 forks of gcc/binutils # using nonstandard triples since 4aa1ffae041bb9c65eb3067e9dbaaa70710ed100 (canonicalize v) != "vc4-elf" + + # These are the triples used by LLVM, and a patch to recognize + # them has been submitted to (but not accepted by) gnu-config: + # + # https://lists.gnu.org/archive/html/config-patches/2023-10/msg00013.html + # + # In order to not further delay + # https://github.com/NixOS/nixpkgs/pull/231951 we are adding + # these as exceptions, hoping that a future version-bump of + # gnu-config will allow us to remove the exceptions. + && (canonicalize v) != "x86_64-unknown-uefi" + && (canonicalize v) != "i686-unknown-uefi" + && (canonicalize v) != "aarch64-unknown-uefi" )) ]; in { From a364aea0f38a2076eb666f5aa7734ad19dd2f7b5 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 1 Nov 2023 23:19:31 -0700 Subject: [PATCH 32/33] Revert "lib/tests/triples.nix: add *-*-uefi exception" This reverts commit 20a384ee5c642021786bb5981bb613d95273bb6e. --- lib/systems/doubles.nix | 3 --- lib/systems/inspect.nix | 1 - lib/systems/parse.nix | 8 +------- lib/tests/triples.nix | 13 ------------- 4 files changed, 1 insertion(+), 24 deletions(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index 4323518798425..f6e92890b298f 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -53,9 +53,6 @@ let # Redox "x86_64-redox" - # UEFI - "x86_64-uefi" "i686-uefi" "aarch64-uefi" - # WASI "wasm64-wasi" "wasm32-wasi" diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index f4c29e49f00ca..8aba8f8913711 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -85,7 +85,6 @@ rec { isGhcjs = { kernel = kernels.ghcjs; }; isGenode = { kernel = kernels.genode; }; isNone = { kernel = kernels.none; }; - isUefi = { kernel = kernels.uefi; }; isAndroid = [ { abi = abis.android; } { abi = abis.androideabi; } ]; isGnu = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ]; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 81a1e7064621a..f45d402d3e062 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -318,7 +318,6 @@ rec { ghcjs = { execFormat = unknown; families = { }; }; genode = { execFormat = elf; families = { }; }; mmixware = { execFormat = unknown; families = { }; }; - uefi = { execFormat = pe; families = { }; }; } // { # aliases # 'darwin' is the kernel for all of them. We choose macOS by default. darwin = kernels.macos; @@ -397,7 +396,7 @@ rec { uclibceabihf = { float = "hard"; inherit (uclibc) kernels; }; uclibc = { kernels = [ "linux" ]; }; - "" = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "uefi" "wasi" ]; }; + "" = { kernels = [ "darwin" "freebsd12" "freebsd13" "freebsd" "genode" "solaris2" "solaris" "ghcjs" "mmixware" "netbsd" "none" "" "openbsd" "redox" "wasi" ]; }; # in gnu-config triples, this abi is actually the empty string "" rather than "-unknown" unknown = @@ -453,11 +452,6 @@ rec { "javascript-unknown-ghcjs". You tried to create "${cpu.name}-${vendor.name}-${kernel.name}-${abi.name}" ''; - assert with components; - isUefi components - && (!(vendor.name == "unknown" || vendor.name == "") || - !(cpu.name == "aarch64" || isx86_64 components || isx86_32 components)) - -> throw "{x86_64,i686,aarch64}-unknown-uefi are nixpkgs-specific exceptions; no other uefi triples are currently allowed"; setType "system" components; mkSkeletonFromList = l: { diff --git a/lib/tests/triples.nix b/lib/tests/triples.nix index f322626f2c020..4f7a32cae53c6 100644 --- a/lib/tests/triples.nix +++ b/lib/tests/triples.nix @@ -79,19 +79,6 @@ let # We have been shipping Broadcom VC4 forks of gcc/binutils # using nonstandard triples since 4aa1ffae041bb9c65eb3067e9dbaaa70710ed100 (canonicalize v) != "vc4-elf" - - # These are the triples used by LLVM, and a patch to recognize - # them has been submitted to (but not accepted by) gnu-config: - # - # https://lists.gnu.org/archive/html/config-patches/2023-10/msg00013.html - # - # In order to not further delay - # https://github.com/NixOS/nixpkgs/pull/231951 we are adding - # these as exceptions, hoping that a future version-bump of - # gnu-config will allow us to remove the exceptions. - && (canonicalize v) != "x86_64-unknown-uefi" - && (canonicalize v) != "i686-unknown-uefi" - && (canonicalize v) != "aarch64-unknown-uefi" )) ]; in { From 021526a36435f0497daf1bd3d9b4cfecdb408fce Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 30 Nov 2023 01:40:45 -0800 Subject: [PATCH 33/33] lib/systems/default.nix: fix darwin missing bootstrap url for platform x86_64-apple-darwin- --- lib/systems/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 9894d2e570b47..acc1291db73f5 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -325,7 +325,7 @@ rec { }.${cpu.name} or cpu.name; vendor_ = final.rust.platform.vendor; in rust.config - or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + or "${cpu_}-${vendor_}-${kernel.name}${lib.optionalString (abi.name != "unknown" && abi.name != "") "-${abi.name}"}"; # The name of the rust target if it is standard, or the json file # containing the custom target spec.