2017-05-17 09:04:27 -06:00
|
|
|
# Define the list of system with their properties.
|
|
|
|
#
|
|
|
|
# See https://clang.llvm.org/docs/CrossCompilation.html and
|
|
|
|
# http://llvm.org/docs/doxygen/html/Triple_8cpp_source.html especially
|
|
|
|
# Triple::normalize. Parsing should essentially act as a more conservative
|
|
|
|
# version of that last function.
|
2018-01-29 15:50:13 -07:00
|
|
|
#
|
|
|
|
# Most of the types below come in "open" and "closed" pairs. The open ones
|
|
|
|
# specify what information we need to know about systems in general, and the
|
|
|
|
# closed ones are sub-types representing the whitelist of systems we support in
|
|
|
|
# practice.
|
|
|
|
#
|
|
|
|
# Code in the remainder of nixpkgs shouldn't rely on the closed ones in
|
|
|
|
# e.g. exhaustive cases. Its more a sanity check to make sure nobody defines
|
|
|
|
# systems that overlap with existing ones and won't notice something amiss.
|
|
|
|
#
|
2017-07-28 18:05:35 -06:00
|
|
|
{ lib }:
|
|
|
|
with lib.lists;
|
|
|
|
with lib.types;
|
|
|
|
with lib.attrsets;
|
|
|
|
with (import ./inspect.nix { inherit lib; }).predicates;
|
2009-11-19 10:19:39 -07:00
|
|
|
|
|
|
|
let
|
2018-01-29 15:50:13 -07:00
|
|
|
inherit (lib.options) mergeOneOption;
|
|
|
|
|
|
|
|
setTypes = type:
|
2009-11-19 10:19:39 -07:00
|
|
|
mapAttrs (name: value:
|
2018-01-29 15:50:13 -07:00
|
|
|
assert type.check value;
|
|
|
|
setType type.name ({ inherit name; } // value));
|
2017-02-09 14:09:47 -07:00
|
|
|
|
2009-11-19 10:19:39 -07:00
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
2018-04-13 19:41:04 -06:00
|
|
|
types.openSignificantByte = mkOptionType {
|
2018-01-29 15:50:13 -07:00
|
|
|
name = "significant-byte";
|
|
|
|
description = "Endianness";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
types.significantByte = enum (attrValues significantBytes);
|
|
|
|
|
2018-04-13 19:41:04 -06:00
|
|
|
significantBytes = setTypes types.openSignificantByte {
|
2009-11-19 10:19:39 -07:00
|
|
|
bigEndian = {};
|
|
|
|
littleEndian = {};
|
|
|
|
};
|
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Reasonable power of 2
|
|
|
|
types.bitWidth = enum [ 8 16 32 64 128 ];
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openCpuType = mkOptionType {
|
|
|
|
name = "cpu-type";
|
|
|
|
description = "instruction set architecture name and information";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
check = x: types.bitWidth.check x.bits
|
|
|
|
&& (if 8 < x.bits
|
|
|
|
then types.significantByte.check x.significantByte
|
|
|
|
else !(x ? significantByte));
|
|
|
|
};
|
|
|
|
|
|
|
|
types.cpuType = enum (attrValues cpuTypes);
|
|
|
|
|
|
|
|
cpuTypes = with significantBytes; setTypes types.openCpuType {
|
2017-02-09 14:09:47 -07:00
|
|
|
arm = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
|
|
|
armv5tel = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
2018-05-06 13:10:46 -06:00
|
|
|
armv6m = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
2017-02-09 14:09:47 -07:00
|
|
|
armv6l = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
|
|
|
armv7a = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
2018-05-06 13:10:46 -06:00
|
|
|
armv7r = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
|
|
|
armv7m = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
2017-02-09 14:09:47 -07:00
|
|
|
armv7l = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
2018-05-06 13:10:46 -06:00
|
|
|
armv8a = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
|
|
|
armv8r = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
|
|
|
armv8m = { bits = 32; significantByte = littleEndian; family = "arm"; };
|
treewide: isArm -> isAarch32
Following legacy packing conventions, `isArm` was defined just for
32-bit ARM instruction set. This is confusing to non packagers though,
because Aarch64 is an ARM instruction set.
The official ARM overview for ARMv8[1] is surprisingly not confusing,
given the overall state of affairs for ARM naming conventions, and
offers us a solution. It divides the nomenclature into three levels:
```
ISA: ARMv8 {-A, -R, -M}
/ \
Mode: Aarch32 Aarch64
| / \
Encoding: A64 A32 T32
```
At the top is the overall v8 instruction set archicture. Second are the
two modes, defined by bitwidth but differing in other semantics too, and
buttom are the encodings, (hopefully?) isomorphic if they encode the
same mode.
The 32 bit encodings are mostly backwards compatible with previous
non-Thumb and Thumb encodings, and if so we can pun the mode names to
instead mean "sets of compatable or isomorphic encodings", and then
voilà we have nice names for 32-bit and 64-bit arm instruction sets
which do not use the word ARM so as to not confused either laymen or
experienced ARM packages.
[1]: https://developer.arm.com/products/architecture/a-profile
(cherry picked from commit ba52ae50488de85a9cf60a3a04f1c9ca7122ec74)
2018-03-19 20:41:06 -06:00
|
|
|
aarch64 = { bits = 64; significantByte = littleEndian; family = "arm"; };
|
2017-02-09 14:09:47 -07:00
|
|
|
i686 = { bits = 32; significantByte = littleEndian; family = "x86"; };
|
|
|
|
x86_64 = { bits = 64; significantByte = littleEndian; family = "x86"; };
|
2017-12-05 03:27:45 -07:00
|
|
|
mips = { bits = 32; significantByte = bigEndian; family = "mips"; };
|
|
|
|
mipsel = { bits = 32; significantByte = littleEndian; family = "mips"; };
|
|
|
|
mips64 = { bits = 64; significantByte = bigEndian; family = "mips"; };
|
|
|
|
mips64el = { bits = 64; significantByte = littleEndian; family = "mips"; };
|
2017-07-09 13:12:32 -06:00
|
|
|
powerpc = { bits = 32; significantByte = bigEndian; family = "power"; };
|
2018-01-25 14:30:03 -07:00
|
|
|
riscv32 = { bits = 32; significantByte = littleEndian; family = "riscv"; };
|
|
|
|
riscv64 = { bits = 64; significantByte = littleEndian; family = "riscv"; };
|
|
|
|
wasm32 = { bits = 32; significantByte = littleEndian; family = "wasm"; };
|
|
|
|
wasm64 = { bits = 64; significantByte = littleEndian; family = "wasm"; };
|
2017-02-09 14:09:47 -07:00
|
|
|
};
|
2009-11-19 10:19:39 -07:00
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openVendor = mkOptionType {
|
|
|
|
name = "vendor";
|
|
|
|
description = "vendor for the platform";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
types.vendor = enum (attrValues vendors);
|
|
|
|
|
|
|
|
vendors = setTypes types.openVendor {
|
2017-02-09 14:09:47 -07:00
|
|
|
apple = {};
|
|
|
|
pc = {};
|
2017-05-17 09:04:27 -06:00
|
|
|
|
2017-02-09 14:09:47 -07:00
|
|
|
unknown = {};
|
|
|
|
};
|
2009-11-19 10:19:39 -07:00
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openExecFormat = mkOptionType {
|
|
|
|
name = "exec-format";
|
|
|
|
description = "executable container used by the kernel";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
types.execFormat = enum (attrValues execFormats);
|
|
|
|
|
|
|
|
execFormats = setTypes types.openExecFormat {
|
2009-11-19 10:19:39 -07:00
|
|
|
aout = {}; # a.out
|
|
|
|
elf = {};
|
|
|
|
macho = {};
|
|
|
|
pe = {};
|
2017-05-17 09:04:27 -06:00
|
|
|
|
2017-02-09 14:09:47 -07:00
|
|
|
unknown = {};
|
2009-11-19 10:19:39 -07:00
|
|
|
};
|
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openKernelFamily = mkOptionType {
|
|
|
|
name = "exec-format";
|
|
|
|
description = "executable container used by the kernel";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
types.kernelFamily = enum (attrValues kernelFamilies);
|
|
|
|
|
|
|
|
kernelFamilies = setTypes types.openKernelFamily {
|
2017-02-09 14:09:47 -07:00
|
|
|
bsd = {};
|
2018-03-18 22:16:25 -06:00
|
|
|
darwin = {};
|
2009-11-19 10:19:39 -07:00
|
|
|
};
|
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openKernel = mkOptionType {
|
|
|
|
name = "kernel";
|
|
|
|
description = "kernel name and information";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
check = x: types.execFormat.check x.execFormat
|
|
|
|
&& all types.kernelFamily.check (attrValues x.families);
|
|
|
|
};
|
|
|
|
|
|
|
|
types.kernel = enum (attrValues kernels);
|
|
|
|
|
|
|
|
kernels = with execFormats; with kernelFamilies; setTypes types.openKernel {
|
2018-03-18 22:16:25 -06:00
|
|
|
# TODO(@Ericson2314): Don't want to mass-rebuild yet to keeping 'darwin' as
|
|
|
|
# the nnormalized name for macOS.
|
|
|
|
macos = { execFormat = macho; families = { inherit darwin; }; name = "darwin"; };
|
|
|
|
ios = { execFormat = macho; families = { inherit darwin; }; };
|
2017-06-12 11:27:10 -06:00
|
|
|
freebsd = { execFormat = elf; families = { inherit bsd; }; };
|
|
|
|
hurd = { execFormat = elf; families = { }; };
|
|
|
|
linux = { execFormat = elf; families = { }; };
|
|
|
|
netbsd = { execFormat = elf; families = { inherit bsd; }; };
|
|
|
|
none = { execFormat = unknown; families = { }; };
|
|
|
|
openbsd = { execFormat = elf; families = { inherit bsd; }; };
|
|
|
|
solaris = { execFormat = elf; families = { }; };
|
2017-05-17 09:04:27 -06:00
|
|
|
windows = { execFormat = pe; families = { }; };
|
|
|
|
} // { # aliases
|
2018-03-18 22:16:25 -06:00
|
|
|
# 'darwin' is the kernel for all of them. We choose macOS by default.
|
|
|
|
darwin = kernels.macos;
|
2017-04-25 21:25:37 -06:00
|
|
|
# TODO(@Ericson2314): Handle these Darwin version suffixes more generally.
|
2018-03-18 22:16:25 -06:00
|
|
|
darwin10 = kernels.macos;
|
|
|
|
darwin14 = kernels.macos;
|
|
|
|
watchos = kernels.ios;
|
|
|
|
tvos = kernels.ios;
|
2017-05-17 09:04:27 -06:00
|
|
|
win32 = kernels.windows;
|
2017-02-09 14:09:47 -07:00
|
|
|
};
|
2009-11-19 10:19:39 -07:00
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
types.openAbi = mkOptionType {
|
|
|
|
name = "abi";
|
|
|
|
description = "binary interface for compiled code and syscalls";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
types.abi = enum (attrValues abis);
|
|
|
|
|
|
|
|
abis = setTypes types.openAbi {
|
2018-05-10 15:31:07 -06:00
|
|
|
cygnus = {};
|
|
|
|
msvc = {};
|
|
|
|
eabi = {};
|
|
|
|
|
|
|
|
androideabi = {};
|
|
|
|
android = {};
|
|
|
|
|
|
|
|
gnueabi = { float = "soft"; };
|
|
|
|
gnueabihf = { float = "hard"; };
|
2018-05-10 16:13:00 -06:00
|
|
|
gnu = {
|
2018-05-09 16:50:51 -06:00
|
|
|
assertions = [
|
|
|
|
{ assertion = platform: !platform.isAarch32;
|
|
|
|
message = ''
|
|
|
|
The "gnu" ABI is ambiguous on 32-bit ARM. Use "gnueabi" or "gnueabihf" instead.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2018-05-10 15:31:07 -06:00
|
|
|
|
|
|
|
musleabi = { float = "soft"; };
|
|
|
|
musleabihf = { float = "hard"; };
|
|
|
|
musl = {};
|
|
|
|
|
|
|
|
uclibceabihf = { float = "soft"; };
|
|
|
|
uclibceabi = { float = "hard"; };
|
|
|
|
uclibc = {};
|
2017-05-17 09:04:27 -06:00
|
|
|
|
2017-02-09 14:09:47 -07:00
|
|
|
unknown = {};
|
2009-11-19 10:19:39 -07:00
|
|
|
};
|
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
2018-04-05 13:22:45 -06:00
|
|
|
types.parsedPlatform = mkOptionType {
|
2018-01-29 15:50:13 -07:00
|
|
|
name = "system";
|
|
|
|
description = "fully parsed representation of llvm- or nix-style platform tuple";
|
|
|
|
merge = mergeOneOption;
|
|
|
|
check = { cpu, vendor, kernel, abi }:
|
|
|
|
types.cpuType.check cpu
|
|
|
|
&& types.vendor.check vendor
|
|
|
|
&& types.kernel.check kernel
|
|
|
|
&& types.abi.check abi;
|
|
|
|
};
|
|
|
|
|
2017-02-09 14:09:47 -07:00
|
|
|
isSystem = isType "system";
|
2018-01-29 15:50:13 -07:00
|
|
|
|
|
|
|
mkSystem = components:
|
2018-04-05 13:22:45 -06:00
|
|
|
assert types.parsedPlatform.check components;
|
2018-01-29 15:50:13 -07:00
|
|
|
setType "system" components;
|
2009-11-19 10:19:39 -07:00
|
|
|
|
2017-02-09 14:09:47 -07:00
|
|
|
mkSkeletonFromList = l: {
|
2017-05-17 09:04:27 -06:00
|
|
|
"2" = # We only do 2-part hacks for things Nix already supports
|
|
|
|
if elemAt l 1 == "cygwin"
|
2017-05-22 10:42:03 -06:00
|
|
|
then { cpu = elemAt l 0; kernel = "windows"; abi = "cygnus"; }
|
|
|
|
else if elemAt l 1 == "gnu"
|
|
|
|
then { cpu = elemAt l 0; kernel = "hurd"; abi = "gnu"; }
|
2017-05-17 09:04:27 -06:00
|
|
|
else { cpu = elemAt l 0; kernel = elemAt l 1; };
|
2017-02-09 14:09:47 -07:00
|
|
|
"3" = # Awkwards hacks, beware!
|
|
|
|
if elemAt l 1 == "apple"
|
|
|
|
then { cpu = elemAt l 0; vendor = "apple"; kernel = elemAt l 2; }
|
|
|
|
else if (elemAt l 1 == "linux") || (elemAt l 2 == "gnu")
|
|
|
|
then { cpu = elemAt l 0; kernel = elemAt l 1; abi = elemAt l 2; }
|
2017-05-17 09:04:27 -06:00
|
|
|
else if (elemAt l 2 == "mingw32") # autotools breaks on -gnu for window
|
|
|
|
then { cpu = elemAt l 0; vendor = elemAt l 1; kernel = "windows"; abi = "gnu"; }
|
2017-02-09 14:09:47 -07:00
|
|
|
else throw "Target specification with 3 components is ambiguous";
|
2017-05-17 09:04:27 -06:00
|
|
|
"4" = { cpu = elemAt l 0; vendor = elemAt l 1; kernel = elemAt l 2; abi = elemAt l 3; };
|
2017-02-09 14:09:47 -07:00
|
|
|
}.${toString (length l)}
|
|
|
|
or (throw "system string has invalid number of hyphen-separated components");
|
2009-11-19 10:19:39 -07:00
|
|
|
|
|
|
|
# This should revert the job done by config.guess from the gcc compiler.
|
2017-02-09 14:09:47 -07:00
|
|
|
mkSystemFromSkeleton = { cpu
|
|
|
|
, # Optional, but fallback too complex for here.
|
|
|
|
# Inferred below instead.
|
|
|
|
vendor ? assert false; null
|
|
|
|
, kernel
|
|
|
|
, # Also inferred below
|
|
|
|
abi ? assert false; null
|
|
|
|
} @ args: let
|
2017-05-17 09:04:27 -06:00
|
|
|
getCpu = name: cpuTypes.${name} or (throw "Unknown CPU type: ${name}");
|
|
|
|
getVendor = name: vendors.${name} or (throw "Unknown vendor: ${name}");
|
|
|
|
getKernel = name: kernels.${name} or (throw "Unknown kernel: ${name}");
|
|
|
|
getAbi = name: abis.${name} or (throw "Unknown ABI: ${name}");
|
2017-02-09 14:09:47 -07:00
|
|
|
|
2017-05-21 11:39:23 -06:00
|
|
|
parsed = rec {
|
2017-02-09 14:09:47 -07:00
|
|
|
cpu = getCpu args.cpu;
|
|
|
|
vendor =
|
|
|
|
/**/ if args ? vendor then getVendor args.vendor
|
2017-05-21 11:39:23 -06:00
|
|
|
else if isDarwin parsed then vendors.apple
|
|
|
|
else if isWindows parsed then vendors.pc
|
2017-02-09 14:09:47 -07:00
|
|
|
else vendors.unknown;
|
|
|
|
kernel = getKernel args.kernel;
|
|
|
|
abi =
|
|
|
|
/**/ if args ? abi then getAbi args.abi
|
2018-05-09 16:50:51 -06:00
|
|
|
else if isLinux parsed then (if isAarch32 parsed then abis.gnueabi else abis.gnu)
|
2017-05-21 11:39:23 -06:00
|
|
|
else if isWindows parsed then abis.gnu
|
2017-02-09 14:09:47 -07:00
|
|
|
else abis.unknown;
|
|
|
|
};
|
|
|
|
|
2017-05-21 11:39:23 -06:00
|
|
|
in mkSystem parsed;
|
2017-02-09 14:09:47 -07:00
|
|
|
|
|
|
|
mkSystemFromString = s: mkSystemFromSkeleton (mkSkeletonFromList (lib.splitString "-" s));
|
|
|
|
|
2017-05-17 09:04:27 -06:00
|
|
|
doubleFromSystem = { cpu, vendor, kernel, abi, ... }:
|
2018-03-18 22:16:25 -06:00
|
|
|
/**/ if abi == abis.cygnus then "${cpu.name}-cygwin"
|
|
|
|
else if kernel.families ? darwin then "${cpu.name}-darwin"
|
2017-05-17 09:04:27 -06:00
|
|
|
else "${cpu.name}-${kernel.name}";
|
2017-02-09 14:09:47 -07:00
|
|
|
|
|
|
|
tripleFromSystem = { cpu, vendor, kernel, abi, ... } @ sys: assert isSystem sys; let
|
|
|
|
optAbi = lib.optionalString (abi != abis.unknown) "-${abi.name}";
|
|
|
|
in "${cpu.name}-${vendor.name}-${kernel.name}${optAbi}";
|
2009-11-19 10:19:39 -07:00
|
|
|
|
2018-01-29 15:50:13 -07:00
|
|
|
################################################################################
|
|
|
|
|
2009-11-19 10:19:39 -07:00
|
|
|
}
|