File tree Expand file tree Collapse file tree 4 files changed +15
-6
lines changed Expand file tree Collapse file tree 4 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -234,8 +234,8 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
234
234
// Support for linking tests against executables is conditional on the tools
235
235
// version of the package that defines the executable product.
236
236
let executableTarget = try product. executableTarget
237
- if executableTarget. underlyingTarget is SwiftTarget , self . toolsVersion >= . v5_5,
238
- self . buildParameters. canRenameEntrypointFunctionName, executableTarget . underlyingTarget . type != . macro
237
+ if let target = executableTarget. underlyingTarget as? SwiftTarget , self . toolsVersion >= . v5_5,
238
+ self . buildParameters. canRenameEntrypointFunctionName, target . supportsTestableExecutablesFeature
239
239
{
240
240
if let flags = buildParameters. linkerFlagsForRenamingMainFunction ( of: executableTarget) {
241
241
args += flags
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ public final class SwiftTargetBuildDescription {
93
93
var moduleOutputPath : AbsolutePath {
94
94
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
95
95
let allowLinkingAgainstExecutables = ( buildParameters. triple. isDarwin ( ) || self . buildParameters. triple
96
- . isLinux ( ) || self . buildParameters. triple. isWindows ( ) ) && self . toolsVersion >= . v5_5 && target . type != . macro
96
+ . isLinux ( ) || self . buildParameters. triple. isWindows ( ) ) && self . toolsVersion >= . v5_5
97
97
let dirPath = ( target. type == . executable && !allowLinkingAgainstExecutables) ? self . tempsPath : self
98
98
. buildParameters. buildPath
99
99
return dirPath. appending ( component: self . target. c99name + " .swiftmodule " )
@@ -450,7 +450,7 @@ public final class SwiftTargetBuildDescription {
450
450
// when we link the executable, we will ask the linker to rename the entry point
451
451
// symbol to just `_main` again (or if the linker doesn't support it, we'll
452
452
// generate a source containing a redirect).
453
- if ( self . target. type == . executable || self . target . type == . snippet )
453
+ if ( self . target. underlyingTarget as? SwiftTarget ) ? . supportsTestableExecutablesFeature == true
454
454
&& !self . isTestTarget && self . toolsVersion >= . v5_5
455
455
{
456
456
// We only do this if the linker supports it, as indicated by whether we
Original file line number Diff line number Diff line change @@ -731,10 +731,10 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
731
731
// In tool version .v5_5 or greater, we also include executable modules implemented in Swift in
732
732
// any test products... this is to allow testing of executables. Note that they are also still
733
733
// built as separate products that the test can invoke as subprocesses.
734
- case . executable, . snippet:
734
+ case . executable, . snippet, . macro :
735
735
if product. targets. contains ( target) {
736
736
staticTargets. append ( target)
737
- } else if product. type == . test && target. underlyingTarget is SwiftTarget {
737
+ } else if product. type == . test && ( target. underlyingTarget as? SwiftTarget ) ? . supportsTestableExecutablesFeature == true {
738
738
if let toolsVersion = graph. package ( for: product) ? . manifest. toolsVersion, toolsVersion >= . v5_5 {
739
739
staticTargets. append ( target)
740
740
}
Original file line number Diff line number Diff line change @@ -426,6 +426,15 @@ public final class SwiftTarget: Target {
426
426
self . swiftVersion = try container. decode ( SwiftLanguageVersion . self, forKey: . swiftVersion)
427
427
try super. init ( from: decoder)
428
428
}
429
+
430
+ public var supportsTestableExecutablesFeature : Bool {
431
+ // Exclude macros from testable executables if they are built as dylibs.
432
+ #if BUILD_MACROS_AS_DYLIBS
433
+ return type == . executable || type == . snippet
434
+ #else
435
+ return type == . executable || type == . macro || type == . snippet
436
+ #endif
437
+ }
429
438
}
430
439
431
440
public final class SystemLibraryTarget : Target {
You can’t perform that action at this time.
0 commit comments