1- // swift-tools-version: 6.0
1+ // swift-tools-version: 6.1
22// The swift-tools-version declares the minimum version of Swift required to build this package.
33
44import CompilerPluginSupport
55import PackageDescription
66
77import Foundation
88
9+ // Package Trait Names
10+ let SwiftJavaMacrosSupport : String = " SwiftJavaMacrosSupport "
11+
912// Note: the JAVA_HOME environment variable must be set to point to where
1013// Java is installed, e.g.,
1114// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home.
@@ -196,6 +199,17 @@ let package = Package(
196199 ) ,
197200
198201 ] ,
202+
203+ traits: [
204+ . init(
205+ name: SwiftJavaMacrosSupport,
206+ description: " Enable @JavaMethod, @JavaClass and other Swift macros which are used in wrapping Java types "
207+ ) ,
208+ . default( enabledTraits: [
209+ SwiftJavaMacrosSupport
210+ ] ) // enabled by default, but downstream libraries may disable macros if they don't use them
211+ ] ,
212+
199213 dependencies: [
200214 . package ( url: " https://github.com/swiftlang/swift-syntax " , from: " 601.0.1 " ) ,
201215 . package ( url: " https://github.com/apple/swift-argument-parser " , from: " 1.5.0 " ) ,
@@ -208,6 +222,7 @@ let package = Package(
208222 // Benchmarking
209223 . package ( url: " https://github.com/ordo-one/package-benchmark " , . upToNextMajor( from: " 1.4.0 " ) ) ,
210224 ] ,
225+
211226 targets: [
212227 . target(
213228 name: " SwiftJavaDocumentation " ,
@@ -220,8 +235,8 @@ let package = Package(
220235 . macro(
221236 name: " SwiftJavaMacros " ,
222237 dependencies: [
223- . product( name: " SwiftSyntaxMacros " , package : " swift-syntax " ) ,
224- . product( name: " SwiftCompilerPlugin " , package : " swift-syntax " ) ,
238+ . product( name: " SwiftSyntaxMacros " , package : " swift-syntax " , condition : . when ( traits : [ SwiftJavaMacrosSupport ] ) ) ,
239+ . product( name: " SwiftCompilerPlugin " , package : " swift-syntax " , condition : . when ( traits : [ SwiftJavaMacrosSupport ] ) ) ,
225240 ] ,
226241 swiftSettings: [
227242 . swiftLanguageMode( . v5)
@@ -237,10 +252,10 @@ let package = Package(
237252 . target(
238253 name: " SwiftJava " ,
239254 dependencies: [
240- " CSwiftJavaJNI " ,
241- " SwiftJavaMacros " ,
242- " JavaTypes " ,
243- " SwiftJavaConfigurationShared " , // for Configuration reading at runtime
255+ . byName ( name : " CSwiftJavaJNI " ) ,
256+ . byName ( name : " JavaTypes " ) ,
257+ . byName ( name : " SwiftJavaMacros " , condition : . when ( traits : [ SwiftJavaMacrosSupport ] ) ) ,
258+ . byName ( name : " SwiftJavaConfigurationShared " ) , // for Configuration reading at runtime
244259 ] ,
245260 exclude: [ " swift-java.config " ] ,
246261 swiftSettings: [
0 commit comments