spotify / XCRemoteCache

Other
825 stars 50 forks source link

Support Xcode 14.0+ Swift driver #153

Open polac24 opened 2 years ago

polac24 commented 2 years ago

Expected/desired behavior Xcode 14 introduced the new swift driver that changes the way swift-frontent commands are invoked.

Swift driver, the component that orchestrates Swift front-end invocations, is now integrated into Xcode’s build system, allowing for fine granular dependencies to other build system tasks and explicit scheduling. (72440175)

This change is not yet compatible with the simplest SWIFT_EXEC override, so for now disabling the new driver has been applied in #152. However, for a full advantage of swift driver, XCRemoteCache could actively integrate into the Xcode <-> swift-driver communication messages - for now, the approach is still unknown.

Relevant integration setup

ainopara commented 2 years ago

Is it possible to change the behavior of swift driver through custom toolchain? https://github.com/apple/swift-driver#testing-in-xcode-with-custom-toolchain

polac24 commented 2 years ago

@ainopara, I don't think so. Even if you change a toolchain, (at least for the non SPM-project) Xcode triggers a step builtin-SwiftDriver, which then schedules individual swift-frontend steps according to the output of the embedded driver. That said, it is impossible to define a wrapper which would modify the "planning session" done in the driver.

grigorye commented 9 months ago

Just in case, I'm experiencing a problem with Xcode 14.2 (using the cocoapods plugin): SWIFT_USE_INTEGRATED_DRIVER is set to NO, SWIFT_EXEC is overridden to ".../xcswiftc" (all of that is set automatically by the plugin, as result of the cache hit), however, when building in Xcode, it still uses xxx/swift-frontend -frontend -c ... for compilation of .swift files in the target. Will try to make a reproducible sample project, but I wonder if there's a clue/hint already?

polac24 commented 9 months ago

If Xcode invokes xcswiftc and then swift-frontend, that seems like a cache miss. Does the Xcode's output in the report navigator (CMD+9) show that there was a cache hit (Cached build for ... vs Disabled remote cache for)?

To trace the cache miss reason, I would look for logs (docs).

grigorye commented 9 months ago

The output says "Disabled remote cache for" indeed, thanks! Will take a look on it.

grigorye commented 9 months ago

And I figured it out that it indeed invokes xcswiftc first, I apologise for the confusion.