at 18.09-beta 2.4 kB view raw
1{ lib }: 2 let inherit (lib.attrsets) mapAttrs; in 3 4rec { 5 doubles = import ./doubles.nix { inherit lib; }; 6 forMeta = import ./for-meta.nix { inherit lib; }; 7 parse = import ./parse.nix { inherit lib; }; 8 inspect = import ./inspect.nix { inherit lib; }; 9 platforms = import ./platforms.nix { inherit lib; }; 10 examples = import ./examples.nix { inherit lib; }; 11 12 # Elaborate a `localSystem` or `crossSystem` so that it contains everything 13 # necessary. 14 # 15 # `parsed` is inferred from args, both because there are two options with one 16 # clearly prefered, and to prevent cycles. A simpler fixed point where the RHS 17 # always just used `final.*` would fail on both counts. 18 elaborate = args: let 19 final = { 20 # Prefer to parse `config` as it is strictly more informative. 21 parsed = parse.mkSystemFromString (if args ? config then args.config else args.system); 22 # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds. 23 system = parse.doubleFromSystem final.parsed; 24 config = parse.tripleFromSystem final.parsed; 25 # Just a guess, based on `system` 26 platform = platforms.selectBySystem final.system; 27 # Derived meta-data 28 libc = 29 /**/ if final.isDarwin then "libSystem" 30 else if final.isMinGW then "msvcrt" 31 else if final.isMusl then "musl" 32 else if final.isUClibc then "uclibc" 33 else if final.isAndroid then "bionic" 34 else if final.isLinux /* default */ then "glibc" 35 # TODO(@Ericson2314) think more about other operating systems 36 else "native/impure"; 37 extensions = { 38 sharedLibrary = 39 /**/ if final.isDarwin then ".dylib" 40 else if final.isWindows then ".dll" 41 else ".so"; 42 executable = 43 /**/ if final.isWindows then ".exe" 44 else ""; 45 }; 46 # Misc boolean options 47 useAndroidPrebuilt = false; 48 useiOSPrebuilt = false; 49 } // mapAttrs (n: v: v final.parsed) inspect.predicates 50 // args; 51 in assert final.useAndroidPrebuilt -> final.isAndroid; 52 assert lib.foldl 53 (pass: { assertion, message }: 54 if assertion final 55 then pass 56 else throw message) 57 true 58 (final.parsed.abi.assertions or []); 59 final; 60}