-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
treewide: expunge functions from platforms #238331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,100 @@ | ||||||
| { lib }: | ||||||
| let inherit (lib.attrsets) mapAttrs; in | ||||||
| { lib | ||||||
| }: | ||||||
| let | ||||||
| inherit (lib.attrsets) mapAttrs; | ||||||
|
|
||||||
| selectEmulator = platform: pkgs: | ||||||
| let | ||||||
| qemu-user = pkgs.qemu.override { | ||||||
| smartcardSupport = false; | ||||||
| spiceSupport = false; | ||||||
| openGLSupport = false; | ||||||
| virglSupport = false; | ||||||
| vncSupport = false; | ||||||
| gtkSupport = false; | ||||||
| sdlSupport = false; | ||||||
| pulseSupport = false; | ||||||
| pipewireSupport = false; | ||||||
| smbdSupport = false; | ||||||
| seccompSupport = false; | ||||||
| enableDocs = false; | ||||||
| hostCpuTargets = [ "${platform.qemuArch}-linux-user" ]; | ||||||
| }; | ||||||
| wine = (pkgs.winePackagesFor "wine${toString platform.parsed.cpu.bits}").minimal; | ||||||
| in | ||||||
| if lib.systems.canExecute pkgs.stdenv.hostPlatform platform | ||||||
| then "${pkgs.runtimeShell} -c '\"$@\"' --" | ||||||
| else if platform.isWindows | ||||||
| then "${wine}/bin/wine${lib.optionalString (platform.parsed.cpu.bits == 64) "64"}" | ||||||
| else if platform.isLinux && pkgs.stdenv.hostPlatform.isLinux && platform.qemuArch != null | ||||||
| then "${qemu-user}/bin/qemu-${platform.qemuArch}" | ||||||
| else if platform.isWasi | ||||||
| then "${pkgs.wasmtime}/bin/wasmtime" | ||||||
| else if platform.isMmix | ||||||
| then "${pkgs.mmixware}/bin/mmix" | ||||||
| else null; | ||||||
|
|
||||||
| rec { | ||||||
| doubles = import ./doubles.nix { inherit lib; }; | ||||||
|
|
||||||
| parse = import ./parse.nix { inherit lib; }; | ||||||
|
|
||||||
| isCompatiblePlaceholder = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details"; | ||||||
|
|
||||||
| # These definitions have to be floated out into a `let … in` binding to ensure | ||||||
| # that they are the same exact value struct in the evaluating Nix | ||||||
| # implementation. Due to a quirk in how equality is implemented, values including | ||||||
| # functions are considered equal if they have the same memory location as long as | ||||||
| # they are inside a container value and not compared directly. Thus any attribute | ||||||
| # set will compare equal to itself even if it contains functions. | ||||||
| # By floating the functions out of the attribute set construction we'll ensure | ||||||
| # that the functions have the same memory location regardless of what call to | ||||||
| # lib.systems.elaborate produced them. This ensures that platform sets will be | ||||||
| # equal even if they have been constructed by different calls to lib.systems.elaborate | ||||||
| # —as long as their other contents are the same. | ||||||
| # | ||||||
| # For details see: | ||||||
| # - https://github.com/NixOS/nix/issues/3371 | ||||||
| # - https://code.tvl.fyi/about/tvix/docs/value-pointer-equality.md | ||||||
|
|
||||||
| # uncomment after 24.05 branch-off | ||||||
| /* | ||||||
| canExecutePlaceholder = _: throw "2023-06-17: `platform.canExecute` has been removed in favor of `lib.systems.canExecute platform`"; | ||||||
| emulatorAvailablePlaceholder = _: throw "2023-06-17: `platform.emulatorAvailable` has been removed in favor of `lib.systems.emulatorAvailable platform`"; | ||||||
| emulatorPlaceholder = _: throw "2023-06-17: `platform.emulator` has been removed in favor of `lib.systems.emulator platform`"; | ||||||
| */ | ||||||
|
|
||||||
| # uncomment after 23.11 branch-off | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # delete after 24.05 branch-off | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /* | ||||||
| canExecutePlaceholder = _: lib.warn "2023-06-17: `platform.canExecute` has been removed in favor of `lib.systems.canExecute platform`" | ||||||
| self: plat: canExecute self plat; | ||||||
| emulatorAvailablePlaceholder = _: lib.warn "2023-06-17: `platform.emulatorAvailable` has been removed in favor of `lib.systems.emulatorAvailabl | ||||||
| self: pkgs: emulatorAvailable self pkgs; | ||||||
| emulatorPlaceholder = _: lib.warn "2023-06-17: `platform.emulator` has been removed in favor of `lib.systems.emulator platform`" | ||||||
| self: pkgs: emulator self pkgs; | ||||||
| */ | ||||||
|
|
||||||
| # delete out after 23.11 branch-off | ||||||
| canExecutePlaceholder = self: plat: canExecute self plat; | ||||||
| emulatorAvailablePlaceholder = self: pkgs: emulatorAvailable self pkgs; | ||||||
| emulatorPlaceholder = self: pkgs: emulator self pkgs; | ||||||
|
|
||||||
| canExecute = machinePlatform: binaryPlatform: | ||||||
| machinePlatform.isAndroid == binaryPlatform.isAndroid && | ||||||
| parse.isCompatible machinePlatform.parsed.cpu binaryPlatform.parsed.cpu | ||||||
| && machinePlatform.parsed.kernel == binaryPlatform.parsed.kernel; | ||||||
|
|
||||||
| emulatorAvailable = platform: pkgs: (selectEmulator platform pkgs) != null; | ||||||
|
|
||||||
| emulator = platform: pkgs: | ||||||
| if (emulatorAvailable platform pkgs) | ||||||
| then selectEmulator platform pkgs | ||||||
| else throw "Don't know how to run ${platform.config} executables."; | ||||||
|
|
||||||
|
|
||||||
| in rec { | ||||||
| doubles = import ./doubles.nix { inherit lib; }; | ||||||
| inherit parse; | ||||||
| inspect = import ./inspect.nix { inherit lib; }; | ||||||
| platforms = import ./platforms.nix { inherit lib; }; | ||||||
| examples = import ./examples.nix { inherit lib; }; | ||||||
|
|
@@ -34,6 +125,8 @@ rec { | |||||
| */ | ||||||
| flakeExposed = import ./flake-systems.nix { }; | ||||||
|
|
||||||
| inherit canExecute emulatorAvailable emulator; | ||||||
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # Elaborate a `localSystem` or `crossSystem` so that it contains everything | ||||||
| # necessary. | ||||||
| # | ||||||
|
|
@@ -53,12 +146,19 @@ rec { | |||||
| # Either of these can be losslessly-extracted from `parsed` iff parsing succeeds. | ||||||
| system = parse.doubleFromSystem final.parsed; | ||||||
| config = parse.tripleFromSystem final.parsed; | ||||||
| # Determine whether we can execute binaries built for the provided platform. | ||||||
| canExecute = platform: | ||||||
| final.isAndroid == platform.isAndroid && | ||||||
| parse.isCompatible final.parsed.cpu platform.parsed.cpu | ||||||
| && final.parsed.kernel == platform.parsed.kernel; | ||||||
| isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details"; | ||||||
|
|
||||||
| # Placeholders for removed functions that inform the user about their replacements | ||||||
| #isCompatible = isCompatiblePlaceholder final; | ||||||
|
|
||||||
| # 2023-06-17: `platform.canExecute` is deprecated in favor of `lib.systems.canExecute platform` | ||||||
| canExecute = canExecutePlaceholder final; | ||||||
|
|
||||||
| # 2023-06-17: `platform.emulatorAvailable` has been removed in favor of `lib.systems.emulatorAvailable platform` | ||||||
| emulatorAvailable = emulatorAvailablePlaceholder final; | ||||||
|
||||||
|
|
||||||
| # 2023-06-17: `platform.emulator` has been removed in favor of `lib.systems.emulator platform` | ||||||
| emulator = emulatorPlaceholder final; | ||||||
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # Derived meta-data | ||||||
| libc = | ||||||
| /**/ if final.isDarwin then "libSystem" | ||||||
|
|
@@ -314,47 +414,8 @@ rec { | |||||
| if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET" | ||||||
| else if final.isiOS then "IPHONEOS_DEPLOYMENT_TARGET" | ||||||
| else null; | ||||||
| } // ( | ||||||
| let | ||||||
| selectEmulator = pkgs: | ||||||
| let | ||||||
| qemu-user = pkgs.qemu.override { | ||||||
| smartcardSupport = false; | ||||||
| spiceSupport = false; | ||||||
| openGLSupport = false; | ||||||
| virglSupport = false; | ||||||
| vncSupport = false; | ||||||
| gtkSupport = false; | ||||||
| sdlSupport = false; | ||||||
| pulseSupport = false; | ||||||
| pipewireSupport = false; | ||||||
| smbdSupport = false; | ||||||
| seccompSupport = false; | ||||||
| enableDocs = false; | ||||||
| hostCpuTargets = [ "${final.qemuArch}-linux-user" ]; | ||||||
| }; | ||||||
| wine = (pkgs.winePackagesFor "wine${toString final.parsed.cpu.bits}").minimal; | ||||||
| in | ||||||
| if pkgs.stdenv.hostPlatform.canExecute final | ||||||
| then "${pkgs.runtimeShell} -c '\"$@\"' --" | ||||||
| else if final.isWindows | ||||||
| then "${wine}/bin/wine${lib.optionalString (final.parsed.cpu.bits == 64) "64"}" | ||||||
| else if final.isLinux && pkgs.stdenv.hostPlatform.isLinux && final.qemuArch != null | ||||||
| then "${qemu-user}/bin/qemu-${final.qemuArch}" | ||||||
| else if final.isWasi | ||||||
| then "${pkgs.wasmtime}/bin/wasmtime" | ||||||
| else if final.isMmix | ||||||
| then "${pkgs.mmixware}/bin/mmix" | ||||||
| else null; | ||||||
| in { | ||||||
| emulatorAvailable = pkgs: (selectEmulator pkgs) != null; | ||||||
|
|
||||||
| emulator = pkgs: | ||||||
| if (final.emulatorAvailable pkgs) | ||||||
| then selectEmulator pkgs | ||||||
| else throw "Don't know how to run ${final.config} executables."; | ||||||
|
|
||||||
| }) // mapAttrs (n: v: v final.parsed) inspect.predicates | ||||||
|
|
||||||
| } // mapAttrs (n: v: v final.parsed) inspect.predicates | ||||||
| // mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates | ||||||
| // args; | ||||||
| in assert final.useAndroidPrebuilt -> final.isAndroid; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,33 @@ lib.runTests ( | |||||
| testunix = mseteq unix (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ cygwin ++ redox); | ||||||
| }) | ||||||
|
|
||||||
|
|
||||||
| # Uncomment after 23.11 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be in sync with the other uncomment comment.
Suggested change
|
||||||
| /* | ||||||
| # Verify that pointer equality doesn't influence the result of comparing two | ||||||
| # platform sets that are the same, but have been constructed by independent calls | ||||||
| # to `lib.systems.elaborate`. | ||||||
| // builtins.listToAttrs (builtins.map (input: { | ||||||
| name = "test_equality_same_argument_${input}"; | ||||||
| value = { | ||||||
| expr = lib.systems.elaborate input == lib.systems.elaborate input; | ||||||
| expected = true; | ||||||
| }; | ||||||
| }) [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" "x86_64-unknown-linux-musl" "powerpc64le-unknown-linux-gnu" "riscv64-linux" ]) | ||||||
|
|
||||||
| # Verify that pointer equality doesn't influence the result of comparing two | ||||||
| # platform sets that are the same, but have been constructed by two different, | ||||||
| # but effectively equivalent arguments to `lib.systems.elaborate` (in one case | ||||||
| # we pass the `system` as a string, the other time it is placed in a skeleton | ||||||
| # platform attribute set). | ||||||
| // builtins.listToAttrs (builtins.map (system: { | ||||||
| name = "test_equality_equivalent_argument_${system}"; | ||||||
| value = { | ||||||
| expr = lib.systems.elaborate system == lib.systems.elaborate { inherit system; }; | ||||||
| expected = true; | ||||||
| }; | ||||||
| }) [ "x86_64-linux" "riscv64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-netbsd" ]) | ||||||
|
|
||||||
| // { | ||||||
| test_equals_example_x86_64-linux = { | ||||||
| expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") (lib.systems.elaborate "x86_64-linux"); | ||||||
|
|
@@ -79,6 +106,7 @@ lib.runTests ( | |||||
| expected = null; | ||||||
| }; | ||||||
| } | ||||||
| */ | ||||||
|
|
||||||
| # Generate test cases to assert that a change in any non-function attribute makes a platform unequal | ||||||
| // lib.concatMapAttrs (platformAttrName: origValue: { | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.