bazelbuild / rules_swift

Bazel rules to build Swift on Apple and Linux platforms
Apache License 2.0
311 stars 136 forks source link

Disable Swift compiler sandboxing in Xcode 15.3+ to fix nested sandboxing #1206

Closed adincebic closed 4 months ago

adincebic commented 4 months ago

This should solve https://github.com/bazelbuild/rules_swift/issues/1202 and #1204

There were issues with Swift compiler plugins (incl. macros) and nested sandboxes on macOS with Swift 5.9 that have been fixed with 5.10: swift: apple/swift#70079 swift-driver: apple/swift-driver#1493 swift-package-manager: apple/swift-package-manager#7167

I am not sure whether this flag is required on Linux too.

luispadron commented 4 months ago

Is it possible to add a test case as well for this, would catch regressions in the future

adincebic commented 4 months ago

Is it possible to add a test case as well for this, would catch regressions in the future

@luispadron No reason not to, just need to learn how to write tests in Starlark :)

adincebic commented 4 months ago

Is it possible to add a test case as well for this, would catch regressions in the future

@luispadron I added the test though it is not that comprehensive. Maybe a better integration test would be to add example project with SwiftUI preview macro and build that on CI down the road. Does this small test suffice for now?

keith commented 4 months ago

Is this fixed in 15.4?

luispadron commented 4 months ago

@keith tested in the reproducer @adincebic provided but looks like its still broken unless we disable_sandbox:

<unknown>:0: warning: compiler plugin not loaded: '/Applications/Xcode-15.4.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server; failed to initialize
app/source/ContentView.swift:15:1: error: external macro implementation type 'PreviewsMacros.SwiftUIView' could not be found for macro 'Preview(_:body:)'
#Preview {
^
SwiftUI.Preview:2:41: note: 'Preview(_:body:)' declared here
@freestanding(declaration) public macro Preview(_ name: String? = nil, body: @escaping @MainActor () -> any View) = #externalMacro(module: "PreviewsMacros", type: "SwiftUIView")
PhilCai1993 commented 3 months ago

We use -load-plugin-library instead of executable, it works well, without the sandboxing issue