Skip to content

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

Closed
@adincebic

Description

@adincebic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions