Skip to content

Commit 8d7a047

Browse files
committed
command plugins: Build command plugin dependencies for the host, not the target
Since #7164, dependencies of command plugins are once again being built for the _target_ rather than the host. This causes problem when cross compiling because the host needs to be able to run the plugin dependencies, but finds target binaries instead. This problem was fixed before in #6791 by forcing command plugin dependencies to be built for the host by overriding the default build parameters in swiftTool.createBuildSystem(). The same solution still works in this commit, but a better long-term option would be to rework BuildOperation.plan() to handle command plugin dependencies specially, as it already does for build plugin dependencies. At present, BuildOperation.plan calls graph.invokeBuildToolPlugins to process sources. invokeBuildToolPlugins finds all build tool dependecies and builds them separately, using a specially-created BuildOperation instance: https://github.com/apple/swift-package-manager/blob/34efc0bfe9d40d9a019644ac8fcd0b852c491dfe/Sources/SPMBuildCore/Plugins/PluginInvocation.swift#L409 There is no equivalent step for command plugin dependencies, so they are built for the host architecture. Ideally we should rework BuildOperation.plan to build command and build plugin dependencies in the same way.
1 parent f313486 commit 8d7a047

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/Commands/PackageTools/PluginCommand.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ struct PluginCommand: SwiftCommand {
319319
// Build or bring up-to-date any executable host-side tools on which this plugin depends. Add them and any binary dependencies to the tool-names-to-path map.
320320
let buildSystem = try swiftTool.createBuildSystem(
321321
explicitBuildSystem: .native,
322-
cacheBuildManifest: false
322+
cacheBuildManifest: false,
323+
// Force all dependencies to be built for the host, to work around the fact that BuildOperation.plan
324+
// knows to compile build tool plugin dependencies for the host but does not do the same for command
325+
// plugins.
326+
productsBuildParameters: buildParameters
323327
)
324328
let accessibleTools = try plugin.processAccessibleTools(
325329
packageGraph: packageGraph,

0 commit comments

Comments
 (0)