Commit ca2fe64
authored
command plugins: Build command plugin dependencies for the host, not the target (#7280)
Always build command line plugin dependencies for the host triple.
### Motivation:
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.
### Modifications:
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. This commit forces all plugin dependencies to be built for
the host - this is similar to what was done in #6791 and #7273.
### Testing:
An integration test checks that any targets depended on by a command plugin
are built for the host, not for the target.
* A new CommandPluginTestStub plugin has a dependency on a target executable
which will be built automatically when the plugin is run. The test checks that the
dependency is built for the host architecture, no matter which target architecture
is selected using '--triple'.
* The plugin also asks SwiftPM to build the 'placeholder' main target. The test
checks that the dependency is built for the target architecture.
The test is restricted to macOS because we can be sure of having a viable
cross-compilation environment (arm64 to x86_64 and vice versa). The standard
Linux build environments can't cross compile to other architectures.
### Result:
Command plugins can be used again when cross-compiling.1 parent 1f1e5e6 commit ca2fe64
File tree
6 files changed
+71
-1
lines changed- Fixtures/Miscellaneous/Plugins/CommandPluginTestStub
- Plugins/plugin-dependencies-stub
- Sources
- placeholder
- plugintool
- Sources/Commands/PackageTools
- Tests/BuildTests
6 files changed
+71
-1
lines changedLines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
24 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
25 | 38 | | |
26 | 39 | | |
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
25 | 64 | | |
0 commit comments