Skip to content

Conversation

@drodriguez
Copy link
Contributor

Similar in spirit to #5966, but where that one was about plugins, this one is about Swift macros.

We reuse the existing -Xbuild-tools-swiftc because that was what was designed to be used for (any usage of swiftc used for the build tools, which in the case of macros, need to build for the building machine, to not the target machine).

Motivation:

For most cases, compiling against the host toolchain does not need extra arguments, but mixing the arguments for the target with those for the host toolchain can create problems if the target is different enough to the host. In the case of Swift macros, any argument passed to -Xswiftc and others was being forwarded to the Swift macro compilation, which is not correct, since the macros need to compile and execute in the host machine, not the target machine.

The original intention of #5966 was that all host compilation used the "host" flags, and the original spelling proposed in #5966 (-Xhost) was chosen because of this, but the PR review settled in -Xbuild-tools-swiftc, and I think macro compilation did not end up using those flags because it did not convey the actual intention of those flags.

Modifications:

This creates a parallel variable to the existing pluginSwiftCFlags named hostSwiftCFlags which picks up the buildToolsSwiftCFlags that come from the command line -Xbuild-tools-swiftc flags.

With those, it builds a hostBuildFlags with mostly empty flags, except for the swiftCompilerFlags taking its value from hostSwiftCFlags. The rest of the flags are empty because there is not equivalent -Xbuild-tools-cc, -Xbuild-tools-cxx, to take their values from, and they have never been needed.

When building the SwiftCommandState, depending on the destination, one set of flags or the other will be chosen, allowing macros to avoid the -Xswiftc flags intended for the target.

Result:

With these modifications the -Xswiftc flags of the target in complicated setups are not propagated to the macro compilation, while the ones from -Xbuild-tools-swiftc are, allowing issuing swift build that just works when host and target are very different.

Similar in spirit to swiftlang#5966, but where that one was about plugins, this
one is about Swift macros.

We reuse the existing `-Xbuild-tools-swiftc` because that was what was
designed to be used for (any usage of `swiftc` used for the build tools,
which in the case of macros, need to build for the building machine, to
not the target machine).

Motivation:
----------

For most cases, compiling against the host toolchain does not need extra
arguments, but mixing the arguments for the target with those for the
host toolchain can create problems if the target is different enough to
the host. In the case of Swift macros, any argument passed to `-Xswiftc`
and others was being forwarded to the Swift macro compilation, which is
not correct, since the macros need to compile and execute in the host
machine, not the target machine.

The original intention of swiftlang#5966 was that all host compilation used the
"host" flags, and the original spelling proposed in swiftlang#5966 (`-Xhost`) was
chosen because of this, but the PR review settled in
`-Xbuild-tools-swiftc`, and I think macro compilation did not end up
using those flags because it did not convey the actual intention of
those flags.

Modifications:
--------------

This creates a parallel variable to the existing `pluginSwiftCFlags`
named `hostSwiftCFlags` which picks up the `buildToolsSwiftCFlags` that
come from the command line `-Xbuild-tools-swiftc` flags.

With those, it builds a `hostBuildFlags` with mostly empty flags, except
for the `swiftCompilerFlags` taking its value from `hostSwiftCFlags`.
The rest of the flags are empty because there is not equivalent
`-Xbuild-tools-cc`, `-Xbuild-tools-cxx`, to take their values from, and
they have never been needed.

When building the `SwiftCommandState`, depending on the `destination`,
one set of flags or the other will be chosen, allowing macros to avoid
the `-Xswiftc` flags intended for the target.

Result:
-------

With these modifications the `-Xswiftc` flags of the target in
complicated setups are not propagated to the macro compilation, while
the ones from `-Xbuild-tools-swiftc` are, allowing issuing `swift build`
that just works when host and target are very different.
@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant