Skip to content

Failed to cross-compile source code using #Predicate macros. #27

@ser-0xff

Description

@ser-0xff

Hi!
We would like to create Linux binaries/executables on macOS using cross compilation possibilities.
Some projects works fine, but we have an issue compiling a project using the new predicate functionality from swift-foundation package.
There is a minimised test, which compiles fine on macOS and Linux, but does not compile on macOS for Linux using a cross-compile.
We created a cross-compile toolchain according to directions in the README:

mbpro~ macros-cross-compile % swift experimental-sdk list                                          
5.9-RELEASE_ubuntu_jammy_aarch64

and when using it have the following:

mbpro~ macros-cross-compile % swift build --experimental-swift-sdk 5.9-RELEASE_ubuntu_jammy_aarch64
Building for debugging...
warning: Could not read SDKSettings.json for SDK at: /Users/user/Library/org.swift.swiftpm/swift-sdks/5.9-RELEASE_ubuntu_jammy_aarch64.artifactbundle/5.9-RELEASE_ubuntu_jammy_aarch64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk
warning: Could not read SDKSettings.json for SDK at: /Users/user/Library/org.swift.swiftpm/swift-sdks/5.9-RELEASE_ubuntu_jammy_aarch64.artifactbundle/5.9-RELEASE_ubuntu_jammy_aarch64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk
<unknown>:0: warning: glibc not found for 'aarch64-unknown-linux-gnu'; C stdlib may be unavailable
.....
Macros: Operation not permitted
<unknown>:0: warning: glibc not found for 'aarch64-unknown-linux-gnu'; C stdlib may be unavailable
<unknown>:0: warning: glibc not found for 'aarch64-unknown-linux-gnu'; C stdlib may be unavailable
warning: Could not read SDKSettings.json for SDK at: /Users/user/Library/org.swift.swiftpm/swift-sdks/5.9-RELEASE_ubuntu_jammy_aarch64.artifactbundle/5.9-RELEASE_ubuntu_jammy_aarch64/aarch64-unknown-linux-gnu/ubuntu-jammy.sdk
error: emit-module command failed with exit code 1 (use -v to see invocation)
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
/Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros: /Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros: Operation not permitted
<unknown>:0: warning: compiler plugin not loaded: '/Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros; failed to initialize
/Users/user/external-reproducers/swift/macros-cross-compile/Sources/MacrosCrossCompile/Main.swift:8:17: error: external macro implementation type 'FoundationMacros.PredicateMacro' could not be found for macro 'Predicate'
let predicate = #Predicate<Monster> { monster in
                ^
/Users/user/external-reproducers/swift/macros-cross-compile/.build/checkouts/swift-foundation/Sources/FoundationEssentials/Predicate/Predicate.swift:33:14: note: 'Predicate' declared here
public macro Predicate<each Input>(_ body: (repeat each Input) -> Bool) -> Predicate<repeat each Input> = #externalMacro(module: "FoundationMacros", type: "PredicateMacro")
             ^
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
/Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros: /Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros: Operation not permitted
<unknown>:0: warning: compiler plugin not loaded: '/Users/user/external-reproducers/swift/macros-cross-compile/.build/aarch64-unknown-linux-gnu/debug/FoundationMacros; failed to initialize
/Users/user/external-reproducers/swift/macros-cross-compile/Sources/MacrosCrossCompile/Main.swift:8:17: error: external macro implementation type 'FoundationMacros.PredicateMacro' could not be found for macro 'Predicate'
let predicate = #Predicate<Monster> { monster in
                ^
/Users/user/external-reproducers/swift/macros-cross-compile/.build/checkouts/swift-foundation/Sources/FoundationEssentials/Predicate/Predicate.swift:33:14: note: 'Predicate' declared here
public macro Predicate<each Input>(_ body: (repeat each Input) -> Bool) -> Predicate<repeat each Input> = #externalMacro(module: "FoundationMacros", type: "PredicateMacro")
             ^
error: fatalError

The source code of the minimised test available in the repo

Steps to reproduce

mbpro~ git clone https://github.com/ordo-one/external-reproducers.git
Cloning into 'external-reproducers'...
remote: Enumerating objects: 231, done.
remote: Counting objects: 100% (231/231), done.
remote: Compressing objects: 100% (155/155), done.
remote: Total 231 (delta 92), reused 154 (delta 38), pack-reused 0
Receiving objects: 100% (231/231), 42.60 KiB | 1.22 MiB/s, done.
Resolving deltas: 100% (92/92), done.
mbpro~ cd external-reproducers/swift/macros-cross-compile 
mbpro~ swift build --experimental-swift-sdk 5.9-RELEASE_ubuntu_jammy_aarch64

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