Skip to content

swift: fix build with the new SDK pattern#346947

Merged
emilazy merged 12 commits intoNixOS:stagingfrom
reckenrode:push-pttrpnmvytwl
Oct 11, 2024
Merged

swift: fix build with the new SDK pattern#346947
emilazy merged 12 commits intoNixOS:stagingfrom
reckenrode:push-pttrpnmvytwl

Conversation

@reckenrode
Copy link
Contributor

Swift depends on how the old SDK pattern was implemented (e.g., that only the requested framework dependencies would be available). This PR updates Swift to build in a way that’s compatible with the new pattern, uses the same SDK that Swift 5.8 expects to use, and propagates it to make sure packages using Swift have at least the right SDK version.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added the 8.has: clean-up This PR removes packages or removes other cruft label Oct 6, 2024
@ofborg ofborg bot requested review from Trundle, dduan, stephank and trepetti October 6, 2024 22:53
@ofborg ofborg bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Oct 6, 2024
@reckenrode reckenrode mentioned this pull request Oct 7, 2024
13 tasks
@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: haskell General-purpose, statically typed, purely functional programming language 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: emacs Text editor 6.topic: ruby A dynamic, open source programming language with a focus on simplicity and productivity. 6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment 6.topic: pantheon The Pantheon desktop environment 6.topic: module system About "NixOS" module system internals 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. 6.topic: nim Nim programing language 6.topic: vscode A free and versatile code editor that supports almost every major programming language. 6.topic: lib The Nixpkgs function library 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` labels Oct 7, 2024
@reckenrode reckenrode force-pushed the reckenrode/darwin-sdk-refactor branch from ee7fb7e to 183877a Compare October 7, 2024 03:49
@reckenrode reckenrode force-pushed the reckenrode/darwin-sdk-refactor branch from a240201 to 4112f1a Compare October 9, 2024 02:16
Swift’s build makes a few assumptions about how the SDK is set up that
are not true anymore with the new SDK. Fix it to find the SDK at
`$SDKROOT` and copy additional stubs it needs to bootstrap.
libarclite is needed to support ARC on very old deployment targets
(10.10 and older). None of these deployment targets are supported
deployment targets in nixpkgs, especially for Swift. This removes the
need to package the command-line tools executables.
Swift releases are associated with particular Darwin SDK versions. They
don’t _have_ to use that version, but it makes sense to use that version
by default. The deployment target is set to the supported Swift minimum
versions. Unlike C and C++, Swift requires you to availability
annotations, so propagating a newer SDK should be safe.
@reckenrode reckenrode force-pushed the reckenrode/darwin-sdk-refactor branch from 4112f1a to a1adff0 Compare October 10, 2024 05:18
Copy link
Member

@emilazy emilazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really qualified to review this, but generally LGTM. Love to see those comments about our weird build environment disappear.

Comment on lines +44 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is equivalent to deploymentVersion = "10.15";, but it’s fine (and will go away in 25.05 anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also defaults to 10.15 when building on Linux (or should).

Comment on lines +152 to +154
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t really understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrapper uses darwinMinVersion to detect whether it is targeting Linux or Darwin. On Darwin, it will add the SDK to NIX_CFLAGS_COMPILE. Setting it to empty triggers the Linux behavior (no setting), which is what we want because the full SDK breaks the Swift bootstrap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I guess because they expect people to be using the system Swift for bootstrap on macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream uses a Python script to manage the bootstrap. I don’t know the specifics, but the nixpkgs derivation is trying to recreate what it does.

@reckenrode reckenrode force-pushed the reckenrode/darwin-sdk-refactor branch from a1adff0 to e3f2829 Compare October 10, 2024 20:25
@emilazy emilazy marked this pull request as ready for review October 10, 2024 22:54
@emilazy emilazy deleted the branch NixOS:staging October 11, 2024 00:00
@emilazy emilazy closed this Oct 11, 2024
@reckenrode reckenrode reopened this Oct 11, 2024
@reckenrode reckenrode changed the base branch from reckenrode/darwin-sdk-refactor to staging October 11, 2024 00:04
Copy link
Member

@emilazy emilazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand this about as well as I ever will.

@emilazy emilazy merged commit 3f6c2f2 into NixOS:staging Oct 11, 2024
@reckenrode reckenrode deleted the push-pttrpnmvytwl branch October 11, 2024 13:27
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/title-the-darwin-sdks-have-been-updated/55295/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: clean-up This PR removes packages or removes other cruft 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants