From 66aa02f190d17b4e7c4bf0f7f891984647a38234 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 31 Oct 2022 08:35:51 -0400 Subject: lib/systems: Support FreeBSD A tricky thing about FreeBSD is that there is no stable ABI across versions. That means that putting in the version as part of the config string is paramount. We have a parsed represenation that separates name versus version to accomplish this. We include FreeBSD versions 12 and 13 to demonstrate how it works. --- doc/stdenv/meta.chapter.md | 4 ++-- lib/systems/default.nix | 3 ++- lib/systems/doubles.nix | 2 +- lib/systems/examples.nix | 5 +++++ lib/systems/inspect.nix | 2 +- lib/systems/parse.nix | 15 ++++++++++++--- lib/tests/systems.nix | 6 +++--- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/stdenv/meta.chapter.md b/doc/stdenv/meta.chapter.md index a83aa0bd90f..f4d8ed2919d 100644 --- a/doc/stdenv/meta.chapter.md +++ b/doc/stdenv/meta.chapter.md @@ -44,8 +44,8 @@ $ nix-env -qa hello --json "mips32-linux", "x86_64-darwin", "i686-cygwin", - "i686-freebsd", - "x86_64-freebsd", + "i686-freebsd13", + "x86_64-freebsd13", "i686-openbsd", "x86_64-openbsd" ], diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 233174d4083..24f90b4565e 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -47,9 +47,10 @@ rec { else if final.isUClibc then "uclibc" else if final.isAndroid then "bionic" else if final.isLinux /* default */ then "glibc" + else if final.isFreeBSD then "fblibc" + else if final.isNetBSD then "nblibc" else if final.isAvr then "avrlibc" else if final.isNone then "newlib" - else if final.isNetBSD then "nblibc" # TODO(@Ericson2314) think more about other operating systems else "native/impure"; # Choose what linker we wish to use by default. Someday we might also diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index 709b67607f7..23a44d02e85 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -13,7 +13,7 @@ let "x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin" # FreeBSD - "i686-freebsd" "x86_64-freebsd" + "i686-freebsd13" "x86_64-freebsd13" # Genode "aarch64-genode" "i686-genode" "x86_64-genode" diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 61a67072a85..de5adad3ca5 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -303,6 +303,11 @@ rec { # BSDs + x86_64-freebsd = { + config = "x86_64-unknown-freebsd13"; + useLLVM = true; + }; + x86_64-netbsd = { config = "x86_64-unknown-netbsd"; }; diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index ee213438e04..4e0bb8e672e 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -59,7 +59,7 @@ rec { isiOS = { kernel = kernels.ios; }; isLinux = { kernel = kernels.linux; }; isSunOS = { kernel = kernels.solaris; }; - isFreeBSD = { kernel = kernels.freebsd; }; + isFreeBSD = { kernel = { name = "freebsd"; }; }; isNetBSD = { kernel = kernels.netbsd; }; isOpenBSD = { kernel = kernels.openbsd; }; isWindows = { kernel = kernels.windows; }; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index ac450534fe1..d8ba251503a 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -290,7 +290,11 @@ rec { # the normalized name for macOS. macos = { execFormat = macho; families = { inherit darwin; }; name = "darwin"; }; ios = { execFormat = macho; families = { inherit darwin; }; }; - freebsd = { execFormat = elf; families = { inherit bsd; }; }; + # A tricky thing about FreeBSD is that there is no stable ABI across + # versions. That means that putting in the version as part of the + # config string is paramount. + freebsd12 = { execFormat = elf; families = { inherit bsd; }; name = "freebsd"; version = 12; }; + freebsd13 = { execFormat = elf; families = { inherit bsd; }; name = "freebsd"; version = 13; }; linux = { execFormat = elf; families = { }; }; netbsd = { execFormat = elf; families = { inherit bsd; }; }; none = { execFormat = unknown; families = { }; }; @@ -431,6 +435,8 @@ rec { then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = "redox"; } else if (elemAt l 2 == "mmixware") then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = "mmixware"; } + else if hasPrefix "freebsd" (elemAt l 2) + then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; } else if hasPrefix "netbsd" (elemAt l 2) then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; } else if (elem (elemAt l 2) ["eabi" "eabihf" "elf"]) @@ -485,10 +491,13 @@ rec { mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s)); + kernelName = kernel: + kernel.name + toString (kernel.version or ""); + doubleFromSystem = { cpu, kernel, abi, ... }: /**/ if abi == abis.cygnus then "${cpu.name}-cygwin" else if kernel.families ? darwin then "${cpu.name}-darwin" - else "${cpu.name}-${kernel.name}"; + else "${cpu.name}-${kernelName kernel}"; tripleFromSystem = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; let optExecFormat = @@ -496,7 +505,7 @@ rec { gnuNetBSDDefaultExecFormat cpu != kernel.execFormat) kernel.execFormat.name; optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}"; - in "${cpu.name}-${vendor.name}-${kernel.name}${optExecFormat}${optAbi}"; + in "${cpu.name}-${vendor.name}-${kernelName kernel}${optExecFormat}${optAbi}"; ################################################################################ diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index 4175dc68841..27c5ff565ca 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -16,17 +16,17 @@ with lib.systems.doubles; lib.runTests { testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ mmix ++ js ++ genode ++ redox); testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv6l-netbsd" "armv6l-none" "armv7a-linux" "armv7a-netbsd" "armv7l-linux" "armv7l-netbsd" "arm-none" "armv7a-darwin" ]; - testi686 = mseteq i686 [ "i686-linux" "i686-freebsd" "i686-genode" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ]; + testi686 = mseteq i686 [ "i686-linux" "i686-freebsd13" "i686-genode" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ]; testmips = mseteq mips [ "mips64el-linux" "mipsel-linux" "mipsel-netbsd" ]; testmmix = mseteq mmix [ "mmix-mmixware" ]; testriscv = mseteq riscv [ "riscv32-linux" "riscv64-linux" "riscv32-netbsd" "riscv64-netbsd" "riscv32-none" "riscv64-none" ]; testriscv32 = mseteq riscv32 [ "riscv32-linux" "riscv32-netbsd" "riscv32-none" ]; testriscv64 = mseteq riscv64 [ "riscv64-linux" "riscv64-netbsd" "riscv64-none" ]; - testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "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-solaris" "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" ]; - testfreebsd = mseteq freebsd [ "i686-freebsd" "x86_64-freebsd" ]; + testfreebsd = mseteq freebsd [ "i686-freebsd13" "x86_64-freebsd13" ]; testgenode = mseteq genode [ "aarch64-genode" "i686-genode" "x86_64-genode" ]; testredox = mseteq redox [ "x86_64-redox" ]; testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */); -- cgit 1.4.1