I noticed when generating a new package, type macro, it adds the platforms:
argument to the Package
initializer in the Package.Swift
file.
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
import CompilerPluginSupport
let package = Package(
name: "MacroPackage",
>> platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
products: [
...
Is it possible to write macro packages just for the iOS platform? Or even better, for no specific platform?
Because, when removing the .macOS(.v10_15)
from the platforms argument, I get an error saying that swift-syntax
requires the macOS platform.
...
Creating working copy for https://github.com/apple/swift-syntax.git
Working copy of https://github.com/apple/swift-syntax.git resolved at 509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a
**error:** the macro 'MacroPackageMacros' requires macos 10.13, but depends on the product 'SwiftSyntaxMacros' which requires macos 10.15; consider changing the macro 'MacroPackageMacros' to require macos 10.15 or later, or the product 'SwiftSyntaxMacros' to require macos 10.13 or earlier.
**error:** the macro 'MacroPackageMacros' requires macos 10.13, but depends on the product 'SwiftCompilerPlugin' which requires macos 10.15; consider changing the macro 'MacroPackageMacros' to require macos 10.15 or later, or the product 'SwiftCompilerPlugin' to require macos 10.13 or earlier.
I would assume that macros can be part of a library package. In fact, the swift package init --type macro
command generates a library product, which can be imported into another package or an executable.
I also saw the discussion about Swift Macros support in Linux, so is it at this point even possible to make a platform agnostic macro?