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

Unable to compile Swift files with system-provided Swift Macro like #Preview when sandboxing is enabled #1202

Closed
adincebic opened this issue May 8, 2024 · 0 comments

Comments

@adincebic
Copy link
Contributor

When performing bazel build while --spawn_strategy=sandboxed the build fails.

➜  bazel-ios-swiftui-template git:(failing-build-with-macros-and-sandboxing) bazel build //app
INFO: Analyzed target //app:app (0 packages loaded, 0 targets configured).
ERROR: /Users/adincebic/developer/bazel-ios-swiftui-template/app/BUILD.bazel:16:14: Compiling Swift module //app:app.library failed: (Exit 1): worker failed: error executing SwiftCompile command (from target //app:app.library) bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/rules_swift~/tools/worker/worker swiftc ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
sandbox-exec: sandbox_apply: Operation not permitted
<unknown>:0: warning: compiler plugin not loaded: '/Applications/Xcode.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")
                                        ^
error: emit-module command failed with exit code 1 (use -v to see invocation)
sandbox-exec: sandbox_apply: Operation not permitted
<unknown>:0: warning: compiler plugin not loaded: '/Applications/Xcode.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")
                                        ^
error: fatalError
Target //app:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.784s, Critical Path: 3.65s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
➜  bazel-ios-swiftui-template git:(failing-build-with-macros-and-sandboxing) 

Switching spawn_strategy to use worker makes it compile.

Here is a small project that demonstrates the problem: https://github.com/adincebic/bazel-ios-swiftui-template/tree/failing-build-with-macros-and-sandboxing

NOTE: I am using Xcode 15.3

keith pushed a commit that referenced this issue May 22, 2024
…xing (#1206)

This should solve #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](apple/swift#70079)
> swift-driver:
[apple/swift-driver#1493](apple/swift-driver#1493)
> swift-package-manager:
[apple/swift-package-manager#7167](apple/swift-package-manager#7167)


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

---------

Signed-off-by: Adin Cebic <cebic.ad@gmail.com>
Co-authored-by: Brentley Jones <github@brentleyjones.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant