Skip to content
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

swift: Workaround Hydra darwin build problem #354192

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

azuwis
Copy link
Contributor

@azuwis azuwis commented Nov 7, 2024

When the host platform is darwin, building swift on Hydra and Github Actions with ninja 1.12 will both give the same error:

ld: warning: directory not found for option '-L/nix/store/g9rbp9m6vs1xj4jl6b6vjb6bm8kgr107-SDKs/MacOSX10.15.sdk/usr/lib/swift'
...
ld: warning: Could not find or use auto-linked library 'swiftCompatibility56'
Undefined symbols for architecture arm64:
  "__swift_FORCE_LOAD_$_swiftCompatibility56", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_Optimizer in libswiftCompilerModules-bootstrapping1.a(Optimizer.o)
  ...

Beware the failure does not happen on developers' local machines.

Edit: You can reproduce the problem using nix --option cores 2 -L build -f . swiftPackages.swift-unwrapped.

Until we find out the exact cause, pin ninja to version 1.11 to workaround the problem.

I have verified nix build github:azuwis/nixpkgs/push-yzpukurnozzk#swiftPackages.swift-unwrapped works on Github Actions macos-latest (aarch64-darwin) with sandbox = relaxed in /etc/nix/nix.conf.

This will hopefully also fix build problem in Hydra #327836, https://hydra.nixos.org/build/276929157

ZHF: #352882


A bit more about the build failure, compare the last successful build log and first broken build log with grep swiftCompatibility56.

Last successful build log:

[16/1354] Building CXX object stdlib/toolchain/Compatibility56/CMakeFiles/swiftCompatibility56-macosx-arm64.dir/Concurrency/MutexPThread.cpp.o
[17/1354] Building CXX object stdlib/toolchain/Compatibility56/CMakeFiles/swiftCompatibility56-macosx-arm64.dir/Concurrency/TaskAlloc.cpp.o
[18/1354] Building CXX object stdlib/toolchain/Compatibility56/CMakeFiles/swiftCompatibility56-macosx-arm64.dir/Runtime/Exclusivity.cpp.o
[28/1354] Linking CXX static library lib/swift/macosx/arm64/libswiftCompatibility56.a
[29/1354] Generating ../../../lib/swift/macosx/libswiftCompatibility56.a
-- Installing: /nix/store/3qk45k9hgr68psf072x4zfwsyva17hpy-swift-5.8/lib/lldb//swift/macosx/libswiftCompatibility56.a
-- Installing: /nix/store/3qk45k9hgr68psf072x4zfwsyva17hpy-swift-5.8/lib/lldb//swift/macosx/arm64/libswiftCompatibility56.a
-- Installing: /nix/store/3qk45k9hgr68psf072x4zfwsyva17hpy-swift-5.8/lib/swift/macosx/libswiftCompatibility56.a

First broken build log:

[886/1354] Building CXX object stdlib/toolchain/Compatibility56/CMakeFiles/swiftCompatibility56-macosx-arm64.dir/Concurrency/MutexPThread.cpp.o
[887/1354] Building CXX object stdlib/toolchain/Compatibility56/CMakeFiles/swiftCompatibility56-macosx-arm64.dir/Runtime/Exclusivity.cpp.o
[925/1354] Linking CXX static library lib/swift/macosx/arm64/libswiftCompatibility56.a
ld: warning: Could not find or use auto-linked library 'swiftCompatibility56'
  "__swift_FORCE_LOAD_$_swiftCompatibility56", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_Optimizer in libswiftCompilerModules-bootstrapping1.a(Optimizer.o)
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_SIL in libswiftCompilerModules-bootstrapping1.a(SIL.o)
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_Basic in libswiftCompilerModules-bootstrapping1.a(Basic.o)
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_Parse in libswiftCompilerModules-bootstrapping1.a(Parse.o)
      __swift_FORCE_LOAD_$_swiftCompatibility56_$__CompilerRegexParser in libswiftCompilerModules-bootstrapping1.a(_CompilerRegexParser.o)
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_AST in libswiftCompilerModules-bootstrapping1.a(AST.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility56_$__CompilerRegexParser, __swift_FORCE_LOAD_$_swiftCompatibility56_$_SIL , __swift_FORCE_LOAD_$_swiftCompatibility56_$_Parse , __swift_FORCE_LOAD_$_swiftCompatibility56_$_Basic , __swift_FORCE_LOAD_$_swiftCompatibility56_$_Optimizer , __swift_FORCE_LOAD_$_swiftCompatibility56_$_AST )

The broken build log lacks this line Generating ../../../lib/swift/macosx/libswiftCompatibility56.a, it seems libswiftCompatibility56.a is not generated in the first place, hence the final ld error.

And with grep ninja.

Last successful build log:

-- CMake Make Program (/nix/store/cisdzsmkr9rk82npn4w2ln295abdy83w-ninja-1.11.1/bin/ninja) Version: 1.11.1
-- CMake Make Program (/nix/store/cisdzsmkr9rk82npn4w2ln295abdy83w-ninja-1.11.1/bin/ninja) Version: 1.11.1

First broken build log:

-- CMake Make Program (/nix/store/zzcj2g6a7znzbr5h26nh5hss9crh5n28-ninja-1.12.1/bin/ninja) Version: 1.12.1
ninja: build stopped: subcommand failed.

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 6.topic: darwin Running or building packages on Darwin label Nov 7, 2024
@ofborg ofborg bot requested review from Trundle, dduan, trepetti and stephank November 7, 2024 11:43
@ofborg ofborg bot added 10.rebuild-darwin: 11-100 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Nov 7, 2024
@github-actions github-actions bot removed the 6.topic: darwin Running or building packages on Darwin label Nov 7, 2024
@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

Wait, what? It’s a Ninja bump? What?

Thank you so much for tracking this down! But I’m going to look at the Ninja commit log for a bit to try and figure out what’s going on here before giving in 😅

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’m seeing mainly changes to dependency ordering and a move to C++11 in Ninja. The former makes me wonder if this is an incomplete dependency specification that only shows up under heavy load like Hydra builders are constantly under. I wonder if enableParallelBuilding = false; works, or at least exposes the problem locally too?

It would be great if we could bisect this to the Ninja commit that broke it, but that would probably take a while…

@@ -190,6 +190,24 @@ let
'';
};

ninja' =
if stdenv.hostPlatform.isDarwin then
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be buildPlatform, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since darwin can't be cross compiled, it should function the same I believe. Though buildPlatform is better suited here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Darwin to Darwin cross-compilation was fixed in #346043.

Copy link
Member

Choose a reason for hiding this comment

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

The real question is whether it breaks compiling a Linux Swift on Darwin. (Probably that doesn’t quite work right now for unrelated reasons, is my guess.)

Anyway if we pin we should just pin unconditionally to match upstream.

@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

I think it would be worth trying the commit immediately before and after the merge of ninja-build/ninja#2177, since the changelog disclaims it as potentially breaking builds.

@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

Looks like Swift pinned Ninja 1.11 for unrelated reasons: swiftlang/swift#72989.

Perhaps we need a proper ninja_1_11 package for now? :(

@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

cc @JohnRTitor who bumped Ninja

@JohnRTitor
Copy link
Contributor

Yeah looks like Swift build on Darwin got overlooked.

Perhaps we need a proper ninja_1_11 package for now? :(

If quite a few packages don't build with ninja 1.12, I think it's fine to have a 1.11 version. But let's consult ninja maintainers anyway.

@JohnRTitor
Copy link
Contributor

Can we get upstream to fix build with ninja 1.12? And also fix the regressions? Having a outdated pin potentially creates a maintainer hassle downstream.

@khaneliman
Copy link
Contributor

Can we get upstream to fix build with ninja 1.12? And also fix the regressions? Having a outdated pin potentially creates a maintainer hassle downstream.

I think that's best long term. But, it would still make sense to pin this derivation to 1.11, like they have done upstream, until they fix it.

@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

If someone found the undeclared dependency in Swift upstream that would be ideal; we could submit a fix upstream and patch it downstream. However since nobody has yet fixed all the other issues we’ve had with the Swift derivation I doubt we can hope for that to happen soon. Maybe for 25.05 when I plan to finally corral an effort to get it in good shape, but ideally we’d not ship 24.11 with a broken Swift.

Possible solutions I see:

  1. Really fix the issue.
  2. Use Ninja 1.11, either with this .overrideAttrs or a proper package.
  3. Try disabling parallel builds.
  4. Try using Make instead of Ninja, if supported. (But it seems like upstream uses Ninja.)

If we do (2), it should probably be unconditional for all platforms, to match upstream’s decision.

@emilazy
Copy link
Member

emilazy commented Nov 7, 2024

Note that we’re on a fairly old version of Swift and it’s possible this particular issue was already fixed upstream. But making Swift 5.10/6.0 happen is definitely a 25.05 task. It might be best just to bite the bullet on the old Ninja version for now.

@azuwis azuwis force-pushed the push-yzpukurnozzk branch from 3fe4fab to b1e157d Compare November 8, 2024 00:32
@azuwis
Copy link
Contributor Author

azuwis commented Nov 8, 2024

Update the PR, override ninja unconditionally.

@azuwis
Copy link
Contributor Author

azuwis commented Nov 8, 2024

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 354192


aarch64-darwin

⏩ 30 packages marked as broken and skipped:
  • anilibria-winmaclinux
  • anki
  • anki.dist
  • anki.doc
  • anki.man
  • deepin.dde-gsettings-schemas
  • flet-client-flutter
  • flet-client-flutter.debug
  • flet-client-flutter.pubcache
  • haruna
  • jellyfin-mpv-shim
  • jellyfin-mpv-shim.dist
  • ki
  • ki.dist
  • libsForQt5.tokodon
  • mnemosyne
  • mnemosyne.dist
  • mpc-qt
  • plasma5Packages.tokodon
  • python311Packages.flet
  • python311Packages.flet-runtime
  • python311Packages.flet-runtime.dist
  • python311Packages.flet.dist
  • python312Packages.flet
  • python312Packages.flet-runtime
  • python312Packages.flet-runtime.dist
  • python312Packages.flet.dist
  • sublime-music
  • sublime-music.dist
  • ytui-music
❌ 11 packages failed to build:
  • dotnetCorePackages.dotnet_9.aspnetcore
  • dotnetCorePackages.dotnet_9.runtime
  • dotnetCorePackages.dotnet_9.sdk
  • dotnetCorePackages.dotnet_9.sdk.artifacts
  • dotnetCorePackages.dotnet_9.vmr
  • gonic
  • hydrus
  • hydrus.doc
  • mov-cli
  • mov-cli.dist
  • termusic
✅ 60 packages built:
  • ani-cli
  • cplay-ng
  • cplay-ng.dist
  • curseradio
  • curseradio.dist
  • dark-mode-notify
  • darwin.openwith
  • dmlive
  • dockutil
  • dotnetCorePackages.dotnet_8.aspnetcore
  • dotnetCorePackages.dotnet_8.runtime
  • dotnetCorePackages.dotnet_8.sdk
  • dotnetCorePackages.dotnet_8.sdk.artifacts
  • dotnetCorePackages.dotnet_8.vmr
  • dra-cla
  • ff2mpv
  • ff2mpv-go
  • ghidra-extensions.ghidraninja-ghidra-scripts
  • gtk-pipe-viewer
  • gtk-pipe-viewer.devdoc
  • invidtui
  • jellyfin-media-player
  • klipperscreen
  • mpv
  • mpv-unwrapped
  • mpv-unwrapped.dev
  • mpv-unwrapped.doc
  • mpv-unwrapped.man
  • needle
  • pipe-viewer
  • pipe-viewer.devdoc
  • plex-media-player
  • python311Packages.mpv
  • python311Packages.mpv.dist
  • python312Packages.mpv
  • python312Packages.mpv.dist
  • somafm-cli
  • sourcekit-lsp (swiftPackages.sourcekit-lsp)
  • subtitleedit
  • supersonic
  • swift (swiftPackages.swift)
  • swift-format (swiftPackages.swift-format)
  • swift.man (swiftPackages.swift.man)
  • swiftPackages.XCTest
  • swiftPackages.swift-docc
  • swiftPackages.swift-driver
  • swiftPackages.swift-unwrapped
  • swiftPackages.swift-unwrapped.dev
  • swiftPackages.swift-unwrapped.doc
  • swiftPackages.swift-unwrapped.lib
  • swiftPackages.swift-unwrapped.man
  • swiftPackages.swiftNoSwiftDriver
  • swiftPackages.swiftNoSwiftDriver.man
  • swiftpm (swiftPackages.swiftpm)
  • tomato-c
  • wtwitch
  • xcodes
  • yafc-ce
  • youtube-tui
  • ytfzf

x86_64-darwin

⏩ 30 packages marked as broken and skipped:
  • anilibria-winmaclinux
  • anki
  • anki.dist
  • anki.doc
  • anki.man
  • deepin.dde-gsettings-schemas
  • flet-client-flutter
  • flet-client-flutter.debug
  • flet-client-flutter.pubcache
  • haruna
  • jellyfin-mpv-shim
  • jellyfin-mpv-shim.dist
  • ki
  • ki.dist
  • libsForQt5.tokodon
  • mnemosyne
  • mnemosyne.dist
  • mpc-qt
  • plasma5Packages.tokodon
  • python311Packages.flet
  • python311Packages.flet-runtime
  • python311Packages.flet-runtime.dist
  • python311Packages.flet.dist
  • python312Packages.flet
  • python312Packages.flet-runtime
  • python312Packages.flet-runtime.dist
  • python312Packages.flet.dist
  • sublime-music
  • sublime-music.dist
  • ytui-music
❌ 18 packages failed to build:
  • dotnetCorePackages.dotnet_8.aspnetcore
  • dotnetCorePackages.dotnet_8.runtime
  • dotnetCorePackages.dotnet_8.sdk
  • dotnetCorePackages.dotnet_8.sdk.artifacts
  • dotnetCorePackages.dotnet_8.vmr
  • dotnetCorePackages.dotnet_9.aspnetcore
  • dotnetCorePackages.dotnet_9.runtime
  • dotnetCorePackages.dotnet_9.sdk
  • dotnetCorePackages.dotnet_9.sdk.artifacts
  • dotnetCorePackages.dotnet_9.vmr
  • gonic
  • hydrus
  • hydrus.doc
  • mov-cli
  • mov-cli.dist
  • needle
  • termusic
  • yafc-ce
✅ 51 packages built:
  • ani-cli
  • cplay-ng
  • cplay-ng.dist
  • curseradio
  • curseradio.dist
  • darwin.openwith
  • dmlive
  • dra-cla
  • ff2mpv
  • ff2mpv-go
  • ghidra-extensions.ghidraninja-ghidra-scripts
  • gtk-pipe-viewer
  • gtk-pipe-viewer.devdoc
  • invidtui
  • jellyfin-media-player
  • klipperscreen
  • mpv
  • mpv-unwrapped
  • mpv-unwrapped.dev
  • mpv-unwrapped.doc
  • mpv-unwrapped.man
  • pipe-viewer
  • pipe-viewer.devdoc
  • plex-media-player
  • python311Packages.mpv
  • python311Packages.mpv.dist
  • python312Packages.mpv
  • python312Packages.mpv.dist
  • somafm-cli
  • sourcekit-lsp (swiftPackages.sourcekit-lsp)
  • subtitleedit
  • supersonic
  • swift (swiftPackages.swift)
  • swift-format (swiftPackages.swift-format)
  • swift.man (swiftPackages.swift.man)
  • swiftPackages.XCTest
  • swiftPackages.swift-docc
  • swiftPackages.swift-driver
  • swiftPackages.swift-unwrapped
  • swiftPackages.swift-unwrapped.dev
  • swiftPackages.swift-unwrapped.doc
  • swiftPackages.swift-unwrapped.lib
  • swiftPackages.swift-unwrapped.man
  • swiftPackages.swiftNoSwiftDriver
  • swiftPackages.swiftNoSwiftDriver.man
  • swiftpm (swiftPackages.swiftpm)
  • tomato-c
  • wtwitch
  • xcodes
  • youtube-tui
  • ytfzf

@azuwis
Copy link
Contributor Author

azuwis commented Nov 8, 2024

Just confirmed the problem can be reproduced in your local machines using nix --option cores 2 -L build -f . swiftPackages.swift-unwrapped.

@azuwis azuwis marked this pull request as draft November 8, 2024 02:50
@azuwis azuwis force-pushed the push-yzpukurnozzk branch from b1e157d to 52211fe Compare November 8, 2024 02:50
@azuwis azuwis marked this pull request as ready for review November 8, 2024 02:51
@azuwis
Copy link
Contributor Author

azuwis commented Nov 8, 2024

Rebase to #354367

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Nov 8, 2024
@emilazy
Copy link
Member

emilazy commented Nov 8, 2024

Needs rebasing for changes in the Ninja PR. Otherwise LGTM!

Fail to build with ninja 1.12 when NIX_BUILD_CORES is low (Hydra or Github Actions):

```
ld: warning: directory not found for option '-L/nix/store/g9rbp9m6vs1xj4jl6b6vjb6bm8kgr107-SDKs/MacOSX10.15.sdk/usr/lib/swift'
...
ld: warning: Could not find or use auto-linked library 'swiftCompatibility56'
Undefined symbols for architecture arm64:
  "__swift_FORCE_LOAD_$_swiftCompatibility56", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibility56_$_Optimizer in libswiftCompilerModules-bootstrapping1.a(Optimizer.o)
  ...
```

Can reproduce using `nix --option cores 2 build -f . swiftPackages.swift-unwrapped`.

Until we find out the exact cause, follow [swift upstream][1], pin ninja to version
1.11.1.

[1]: swiftlang/swift#72989
@azuwis azuwis force-pushed the push-yzpukurnozzk branch from 52211fe to 8dfed1b Compare November 8, 2024 04:32
@github-actions github-actions bot removed the 6.topic: darwin Running or building packages on Darwin label Nov 8, 2024
@azuwis
Copy link
Contributor Author

azuwis commented Nov 8, 2024

Needs rebasing for changes in the Ninja PR. Otherwise LGTM!

Done.

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Nov 8, 2024
Copy link
Contributor

@JohnRTitor JohnRTitor left a comment

Choose a reason for hiding this comment

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

LGTM

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.

The community builder is happy. Let’s see if Hydra is.

Thank you again for putting in the work to track this down 💜

@emilazy emilazy merged commit f8ce2d4 into NixOS:master Nov 8, 2024
11 of 12 checks passed
@azuwis azuwis deleted the push-yzpukurnozzk branch November 8, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 11-100 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants