Atomics in Swift 6

I've been experimenting heavily with SE-0427 and non-copyable generics lately so I'm using Swift 6 nightly toolchains. Yesterday I went to add a macro to the project where I'm doing this and (after downloading the appropriate nightly version of swift-syntax) suddenly I'm getting:

<unknown>:0: error: missing required module '_AtomicBool'

which I presume means that I need to somehow enable stdlib support for Atomics., But I can't figure out the appropriate flags to get past this.

Any suggestions, @Alejandro ?

I'm not actually sure what module this is or where it comes from :thinking:

Edit: Oh this is a C module in swift-syntax :thinking:

cc: @ahoppen

2 Likes

@rvsrvs Do you have a package that reproduces the issue? That would make it a lot easier for me to figure out what’s going wrong.

let me see what I can do. Picked back up a little while ago and I'm suspecting that this is Xcode related

1 Like

hey there, any progress on this?

I created a little Macros package to experiment with new macros (body, preamble).
I came across the same issue:

../MockAuto+MemberMacro.swift Missing required module '_AtomicBool'

In my package, I am using this branch of swift syntax:
.package(url: "https://github.com/apple/swift-syntax.git", branch: "swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-20-a"),

And the swift 6.0 version:
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-20-a.xctoolchain

On Xcode 15.3

Thank for any help

1 Like

I use the following:

.package(url: "https://github.com/apple/swift-syntax", revision: "d3a39e42038b59e65186cadcd22467943e0bab8e"),

and use the matching toolchain: 6.0-DEVELOPMENT-SNAPSHOT-2024-04-20-a

and now Xcode seems to work..

Thanks mate, but this didn't work for me.
Anything else you changed/updated?

@ahoppen is the information I provided enough for you to have a look when you have time please?

I'm sure there is, I just have to find it. :) give me a bit to look.

1 Like

Could it be that you’re missing a dependency between from your target to the SwiftSyntax target? We saw a similar issue here: Missing required module '_AtomicBool' · Issue #2610 · apple/swift-syntax · GitHub

If that’s not the problem, could you share the project that you’re seeing the issue in. If that’s not possible and it’s a SwiftPM project, could you share Package.swift and the name of the target that you are seeing this issue in?

2 Likes

I ended up having to add the swift-syntax packages as depends in the module where I use the macro. Something like this...

let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v17),
        .watchOS(.v10),
        .macOS(.v14)
    ],
    products: [
        .library(
            name: "MyPackage",
            targets: [
                "MainTarget",
                "MyMacro"
            ]
        ),
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-syntax", revision: "d3a39e42038b59e65186cadcd22467943e0bab8e"),
    ],
    targets: [
        .macro(
            name: "MyMacroMacros",
            dependencies: [
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax")
            ]
        ),
        .target(
            name: "MyMacro",
            dependencies: [
                "MyMacroMacros"
            ],
        ),
        .target(
            name: "MainTarget",
            dependencies: [
                "MyMacro",
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
            ],
        ),
        .testTarget(
            name: "MainTargetTests",
            dependencies: [
                "MainTarget",
                "MyMacro",
                "MyMacroMacros",
                .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
            ],
        ),
        .testTarget(
            name: "MyMacroTests",
            dependencies: [
                "MyMacroMacros",
                .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
            ]
        ),
    ]
)

the change that fixed things was adding the swift syntax dependencies to the MainTarget target

1 Like

thank you that did the trick!

1 Like