@@ -389,8 +389,19 @@ final class PluginDelegate: PluginInvocationDelegate {
389
389
throw StringError ( " could not find a target named “ \( targetName) ” " )
390
390
}
391
391
392
+ // FIXME: This is currently necessary because `target(for:destination:)` can
393
+ // produce a module that is targeting host when `targetName`` corresponds to
394
+ // a macro, plugin, or a test. Ideally we'd ask a build system for a`BuildSubset`
395
+ // and get the destination from there but there are other places that need
396
+ // refactoring in that way as well.
397
+ let buildParameters = if target. buildTriple == . tools {
398
+ try swiftCommandState. toolsBuildParameters
399
+ } else {
400
+ try swiftCommandState. productsBuildParameters
401
+ }
402
+
392
403
// Build the target, if needed.
393
- try buildSystem. build ( subset: . target( target. name) )
404
+ try buildSystem. build ( subset: . target( target. name, for : buildParameters . destination ) )
394
405
395
406
// Configure the symbol graph extractor.
396
407
var symbolGraphExtractor = try SymbolGraphExtract (
@@ -419,7 +430,7 @@ final class PluginDelegate: PluginInvocationDelegate {
419
430
guard let package = packageGraph. package ( for: target) else {
420
431
throw StringError ( " could not determine the package for target “ \( target. name) ” " )
421
432
}
422
- let outputDir = try buildSystem . buildPlan . toolsBuildParameters . dataPath. appending (
433
+ let outputDir = try buildParameters . dataPath. appending (
423
434
components: " extracted-symbols " ,
424
435
package . identity. description,
425
436
target. name
@@ -430,7 +441,7 @@ final class PluginDelegate: PluginInvocationDelegate {
430
441
let result = try symbolGraphExtractor. extractSymbolGraph (
431
442
module: target,
432
443
buildPlan: try buildSystem. buildPlan,
433
- buildParameters: buildSystem . buildPlan . destinationBuildParameters ,
444
+ buildParameters: buildParameters ,
434
445
outputRedirection: . collect,
435
446
outputDirectory: outputDir,
436
447
verboseOutput: self . swiftCommandState. logLevel <= . info
0 commit comments