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

Xcode 13.3 Beta 3 swift_binary not building #775

Closed
regularberry opened this issue Mar 8, 2022 · 19 comments · Fixed by #781, #785 or #786
Closed

Xcode 13.3 Beta 3 swift_binary not building #775

regularberry opened this issue Mar 8, 2022 · 19 comments · Fixed by #781, #785 or #786

Comments

@regularberry
Copy link

I've come across an issue with swift_binary and macos_command_line_application not building with Xcode 13.3 Beta 3 command line tools (specifically the Mac OS 12.3 SDK that ships with it).

At first I thought it was an issue with creating a custom rule and passing in a command line tool as the executable, but from creating a simple test project I've come across something else, which may or may not be related.

I've attached a very simple example project which replicates the issue.

You can build a swift_binary using Xcode 13.2.1 with no additional flags, but to build it in Xcode 13.3.0 you'll need --swiftcopt=-whole-module-optimization turned on.

The test project provides 3 configs:

  • bazelisk build SimpleCommandLine --config=success points at Xcode 13.2.1 and succeeds.
  • After a bazel clean --expunge, bazelisk build SimpleCommandLine --config=fail which points at Xcode 13.3.0 will fail
  • Finally, bazelisk build SimpleCommandLine --config=success-with-13.3 will succeed because it turns whole module optimization on.

Please correct me if I'm just not understanding something, I'm still a Bazel novice.

Thank you for your time!

SimpleCommandLine.zip

This is using Bazel 5.0.0 and rules_apple 0.33.0.

The error given is:

Compiling Swift module //SimpleCommandLine:SimpleCommandLine failed: (Exit 1): worker failed: error executing command 
  (cd /private/var/tmp/_bazel_Z006LFH/efd460bccebb4d2e1f7d3ce9a81ace5b/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=12.3 \
    XCODE_VERSION_OVERRIDE=13.3.0.13E5104i \
  bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/darwin-dbg/bin/SimpleCommandLine/SimpleCommandLine_SimpleCommandLine.swiftmodule-0.params)
# Configuration: d03c48ef8c2a47edb079909273e751b2045c82b2c50d44193c24ab65b3afcb53
# Execution platform: @local_config_platform//:host
swift_worker: Could not copy bazel-out/darwin-dbg/bin/_swift_incremental/SimpleCommandLine/SimpleCommandLine_objs/main.swift.partial_swiftmodule to bazel-out/darwin-dbg/bin/SimpleCommandLine/SimpleCommandLine_objs/main.swift.partial_swiftmodule (errno 2)
Target //SimpleCommandLine:SimpleCommandLine failed to build
@keith
Copy link
Member

keith commented Mar 12, 2022

I can reproduce this as well, also with Xcode, it seems like this file isn't produced in some cases now, we need to debug more

@sgammon
Copy link

sgammon commented Mar 15, 2022

i can reproduce, this just stopped us in our tracks when we upgraded Xcode to 13.3.0 ☹️

@keith
Copy link
Member

keith commented Mar 15, 2022

As a temporary workaround you can add -wmo to copts of swift_binary targets, assuming the targets don't rely on incremental compilation, which if they're small CLIs might be fine

@sgammon
Copy link

sgammon commented Mar 15, 2022

thanks for the quick reply and all of your hard work on this library, @keith 😄

unfortunately --swiftcopt=-whole-module-optimization doesn't fix for us. the failure is occurring within SwiftProtobuf, so i'm not sure how to apply that flag unless it's bazel-wide. our targets originate from swift_library and ios_application.

you were so quick on your comment that i've yet to complete an Xcode 13.2.1 download, but i'm going to try restoring my toolchain and see if that clears this up.

@keith
Copy link
Member

keith commented Mar 15, 2022

ah it's probably because it's for the host configuration, so you'd also have to pass --host_swiftcopt=-whole-module-optimization or set --features=swift.opt_uses_osize which applies to all configurations for opt builds (which the host configuration uses)

@sgammon
Copy link

sgammon commented Mar 15, 2022

in case this helps with diagnosis, @keith

build --host_swiftcopt=-whole-module-optimization
build --features=swift.opt_uses_osize
build --host_swiftcopt=-whole-module-optimization
build --features=swift.opt_uses_osize

and

build --swiftcopt=-whole-module-optimization

all fail in my case with the same message:

swift_worker: Could not copy bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-fastbuild-ST-3d618853b8a4/bin/_swift_incremental/external/com_github_apple_swift_protobuf/SwiftProtobuf_objs/Sources/SwiftProtobuf/AnyMessageStorage.swift.partial_swiftmodule to bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-fastbuild-ST-3d618853b8a4/bin/external/com_github_apple_swift_protobuf/SwiftProtobuf_objs/Sources/SwiftProtobuf/AnyMessageStorage.swift.partial_swiftmodule (errno 2)

previously these builds had succeeded, so it leads me to believe it's the same issue. i haven't upgraded SwiftProtobuf -- it's a transitive dependency, in this case, from rules_swift. i'm on rules_swift latest. i'm going to give the 13.2.1 toolchain a try, but i know how integrated xcode et. all is into macOS, so 🤞🏻

@sgammon
Copy link

sgammon commented Mar 15, 2022

okay, downloading 13.2.1 from here, decompressing, and running...

bazel clean --expunge
bazel shutdown
sudo mv /Applications/Xcode.app /Applications/Xcode_v13_3.app
sudo mv ~/Downloads/Xcode.app /Applications
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
bazel build //...

everything's building again.

@thii
Copy link
Member

thii commented Mar 15, 2022

Looks like none of your build options combinations contains both --swiftcopt=-wmo and --host_swiftcopt=-wmo?

@keith
Copy link
Member

keith commented Mar 17, 2022

As a potentially better short term workaround you can pass --swiftcopt=-no-emit-module-separately. I'm not sure what downsides this has yet

keith added a commit that referenced this issue Mar 17, 2022
Previously we required this file to be produced by adding it to the
outputs of compile actions. Starting with Swift 5.6 in incremental mode
the driver no longer produces these files, and instead separates
compilation from a single module creation step, instead of producing
partial modules and merging them. This leads to this file never being
created, and a build failure. This file is never consumed elsewhere, so
we don't need to ensure it's created. We still leave it in the output
file map so that in the case it is created it's still a validate
filepath.

swiftlang/swift-driver@e0c3e5c

Fixes #775
@keith
Copy link
Member

keith commented Mar 17, 2022

I think we can just drop this requirement #781

keith added a commit that referenced this issue Mar 18, 2022
Previously we required this file to be produced by adding it to the
outputs of compile actions. Starting with Swift 5.6 in incremental mode
the driver no longer produces these files, and instead separates
compilation from a single module creation step, instead of producing
partial modules and merging them. This leads to this file never being
created, and a build failure. This file is never consumed elsewhere, so
we don't need to ensure it's created.

swiftlang/swift-driver@e0c3e5c

Fixes #775
@keith
Copy link
Member

keith commented Mar 18, 2022

I've merged this, please test with HEAD, once I hear back I can work on a new release. I tested with Xcode 13.2.1 and 13.3 and also I tested incremental builds and they passed correctly AFAICT

keith added a commit that referenced this issue Mar 18, 2022
With Swift 5.6 the swift driver now emits modules in a separate step,
which skips the partial module merging step that happened before. This
means partial swiftmodule files are not emitted. This reflects that in
our logic for determining this. It's also enabled by default for WMO
builds, but that shouldn't matter for now either since we already
assumed that.

Technically this isn't a perfect solution, this ignores the fact that
users could pass -no-emit-modules-separately, or the WMO version of
these flags but this doesn't seem to be an issue.

swiftlang/swift-driver@e0c3e5c

Fixes #775
@keith keith reopened this Mar 21, 2022
@keith
Copy link
Member

keith commented Mar 21, 2022

I'm reverting this and going with another fix, details on #784

keith added a commit that referenced this issue Mar 21, 2022
This fixes #775 by
disabling the optimization intended by swiftlang/swift-driver@e0c3e5c

Ideally we wouldn't disable it, but that caused other issues
#784 and this is no worse
than what Swift 5.5 was doing until we find a better fix.
keith added a commit that referenced this issue Mar 21, 2022
This fixes #775 by
disabling the optimization intended by swiftlang/swift-driver@e0c3e5c

Ideally we wouldn't disable it, but that caused other issues
#784 and this is no worse
than what Swift 5.5 was doing until we find a better fix.
@keith
Copy link
Member

keith commented Mar 21, 2022

So the core issue turned out to be swiftlang/swift-driver#1036, with that, and #781 things work as expected

keith added a commit that referenced this issue Mar 22, 2022
This fixes #775 by
disabling the optimization intended by swiftlang/swift-driver@e0c3e5c

Ideally we wouldn't disable it, but that caused other issues
#784 and this is no worse
than what Swift 5.5 was doing until we find a better fix.
@keith keith reopened this Mar 22, 2022
@keith
Copy link
Member

keith commented Mar 22, 2022

Ok after even more investigation, that issue is a red-herring (although also a real issue), it seems that #786 is the actual fix we need

@keith
Copy link
Member

keith commented Mar 22, 2022

Please test with the new change and I will actually create a release as long as we don't find any new issues in the next day or so

@regularberry
Copy link
Author

regularberry commented Mar 22, 2022

I've tested this on commit 7b8558c and it's working for me, thank you!

@VegetarianZombie
Copy link

I'm still getting the same error. I have my workspace set up to use the commit:

git_repository(
    name = "build_bazel_rules_swift",
    remote = "https://github.com/bazelbuild/rules_swift.git",
    commit = "7b8558cab8e402eb21e2fc655989bae378171486",
    #tag = "0.26.0",
)

Doing a Bazel clean, then a Bazel build is producing the same compile error.

swift_worker: Could not copy bazel-out/ios-x86_64-min14.0-applebin_ios-ios_x86_64-fastbuild-ST-67e90b6cfecd/bin/_swift_incremental/bullseye/sources_objs/Bullseye/Sources/BackgroundView.swift.partial_swiftmodule to bazel-out/ios-x86_64-min14.0-applebin_ios-ios_x86_64-fastbuild-ST-67e90b6cfecd/bin/bullseye/sources_objs/Bullseye/Sources/BackgroundView.swift.partial_swiftmodule (errno 2)

@keith
Copy link
Member

keith commented Mar 23, 2022

Are you loading rules_apple above this? if so it's likely not respecting this version since rules apple loads a pinned version first

@VegetarianZombie
Copy link

Hi Keith, that looks to have been the problem. I was able to compile the build. Thanks so much for your help!

tymurmustafaiev pushed a commit to tymurmustafaiev/rules_swift that referenced this issue Jul 19, 2023
Previously we required this file to be produced by adding it to the
outputs of compile actions. Starting with Swift 5.6 in incremental mode
the driver no longer produces these files, and instead separates
compilation from a single module creation step, instead of producing
partial modules and merging them. This leads to this file never being
created, and a build failure. This file is never consumed elsewhere, so
we don't need to ensure it's created.

swiftlang/swift-driver@e0c3e5c

Fixes bazelbuild#775
tymurmustafaiev pushed a commit to tymurmustafaiev/rules_swift that referenced this issue Jul 19, 2023
This fixes bazelbuild#775 by
disabling the optimization intended by swiftlang/swift-driver@e0c3e5c

Ideally we wouldn't disable it, but that caused other issues
bazelbuild#784 and this is no worse
than what Swift 5.5 was doing until we find a better fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment