Enabling .enableExperimentalFeature("BodyMacros") doesn't work

Hey there, I am trying to enable BodyMacros experimental feature but BodyMacros still cannot be found.
I am on the swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-20-a and the corresponding branch for SwiftSyntax library
Here is my package:

let package = Package(
    name: "Swift 6.0 Macros",
    platforms: [.macOS(.v14), .iOS(.v17)],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "Swift 6.0 Macros",
            targets: ["Swift 6.0 Macros"]
        ),
        .executable(
            name: "Swift 6.0 MacrosClient",
            targets: [
                "Swift 6.0 MacrosClient"
            ]
        ),
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-syntax", revision: "d3a39e42038b59e65186cadcd22467943e0bab8e"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        // Macro implementation that performs the source transformation of a macro.
        .macro(
            name: "Swift 6.0 MacrosMacros",
            dependencies: [
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax")
            ],
            swiftSettings: [
                .enableExperimentalFeature("BodyMacros")
            ]
        ),
        
        // Library that exposes a macro as part of its API, which is used in client programs.
        .target(
            name: "Swift 6.0 Macros",
            dependencies: [
                "Swift 6.0 MacrosMacros",
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
            ],
            swiftSettings: [
                .enableExperimentalFeature("BodyMacros")
            ]
        ),
        
        // A client of the library, which is able to use the macro in its own code.
        .executableTarget(
            name: "Swift 6.0 MacrosClient",
            dependencies: ["Swift 6.0 Macros"],
            swiftSettings: [
                .enableExperimentalFeature("BodyMacros"),
            ]
        ),
        
        // A test target used to develop the macro implementation.
        .testTarget(
            name: "Swift 6.0 MacrosTests",
            dependencies: [
                "Swift 6.0 MacrosMacros",
                .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
            ]
        ),
    ]
)

But the BodyMacro still cannot be found in scope but I can see it in swift-syntax in Xcode.
Any suggestions greatly appreciated

@rvsrvs thanks for helping with the previous issue. Any chance you may know what's wrong here? Thanks

seems to compile fine for me with that flag. not quite sure what the issue might be.

what when you conform your own struct to it? Does it compile just fine?

Also, when you go to the implementation, does it look the same? What about your pre compiler macro? Does it also go to #else?

The bizarre finding is that even after the successful pre compiler check on the feature flag being enabled, the BodyMacro still cannot be found.

The compiler feature isn't needed when building the implementation of the macro, only when building the library that declares it and those that use it.

In this case, the BodyMacro protocol is hidden because it's SPI; you need to write @_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros to import it.

2 Likes

Yes I added it to make sure adding this flag worked.

Thank you very much! That did the trick.

2 Likes