-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing extra arguments to plugin compilation #5966
Conversation
@swift-ci please smoke test |
Thanks for the contribution! So |
eceecda
to
4b43fcf
Compare
Added a note in the changelog about the new I checked the failing checks, and they did not seem to be related to these changes. |
@swift-ci please smoke test |
4b43fcf
to
e013a62
Compare
|
@swift-ci please smoke test |
Sources/CoreCommands/Options.swift
Outdated
parsing: .unconditionalSingleValue, | ||
help: ArgumentHelp("Pass flag to the manifest build invocation", | ||
help: ArgumentHelp("Pass flag to build invocation targetting the host (manifest and plugins)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like the idea of -Xmanifest
being an alias here, that feels unexpected, especially if we are doing it in perpetuity. I think these should be separate with -Xhost
affecting everything and -Xmanifest
to continue to only affect manifests specifically and emitting a warning about it being deprecated. Then we can eventually remove -Xmanifest
and the support for separate manifest flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good idea. And if you specify both, then -Xmanifest
wins, I'd assume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on @neonichu idea.
also, how about -Xhost-swiftc
? -Xhost
seems a bit too generic, and this only apply to swiftc
and this way we can also add -Xhost-clang
etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, but I think -Xswiftc-host
might be a better spelling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @neonichu. Being able to, in essence, apply -host
as a suffix to any of the tools makes a lot of sense — each of them could really be used for the host in addition to the destination, so it's really another axis. And I think a suffix probably makes things more readable than a prefix (it's a nitpick of course), but it flows better).
This PR doesn't have to be as generic as that, but picking a spelling that will scale naturally to that later makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like the idea of
-Xmanifest
being an alias here, that feels unexpected, especially if we are doing it in perpetuity. I think these should be separate with-Xhost
affecting everything and-Xmanifest
to continue to only affect manifests specifically and emitting a warning about it being deprecated. Then we can eventually remove-Xmanifest
and the support for separate manifest flags.
I considered this approach but left it aside because I think as currently implemented will automatically work for people that used to use -Xmanifest
and found out about plugins not getting the same flags applied to (in my mind -Xmanifest
was always "flags that my host needs to compile, not my target". I was also hoping to have an easier upgrade path for our scripts (which are used with stable versions of SwiftPM and the main
version of SwiftPM) until all of the versions supported -Xhost
and then switch. I will see what it takes to do as you ask, but I wanted to see a different PoV.
That seems like a good idea. And if you specify both, then
-Xmanifest
wins, I'd assume.
I imagine that you mean if any -Xmanifest
is provided, only the manifest compilation will not use any of the -Xhost
arguments? Not that -Xmanifest
will be used even for plugins, right? I don't know if someone will need that behaviour explicitly, and I am a little bit afraid of implementing it, since someone will end up relying on it. I will give it a shot if this allow this to be merged (as I understand it as explained at the start of this paragraph).
+1 on @neonichu idea.
also, how about
-Xhost-swiftc
?-Xhost
seems a bit too generic, and this only apply toswiftc
and this way we can also add-Xhost-clang
etc
This is a good point, but I think
-Xswiftc-host
might be a better spelling?
I think there's no -Xmanifest-swiftc
and -Xmanifest-clang
because -Xmanifest
can be composed with other -Xfoo
accepted by swiftc
. We use this to correctly pass the right arguments to each piece of the toolchain (example: -Xmanifest -Xcc -Xmanifest -nostdlibinc -Xmanifest -Xclang-linker -Xmanifest --sysroot=/var/empty
). This might be because the manifest only invoked swiftc
, and plugins only seem to do so as well. Is there any case you all think that products that need to be compiled for the host will need to invoke something else but swiftc
? I will keep this suggestion out of the rework. If you really think this change is important, I will abide, but I really think it makes things more complicated than needed.
That say, if I have some vote in the spelling, I think -Xhost-swiftc
is slightly better (having host first indicates earlier that this is not a normal -Xswiftc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great points @drodriguez, to add a few thoughts:
- manifests are by definition swift only, but we should consider if plugins could include other languages in the future. if they do we should design the flags to support different compilers.
- I agree with your argument that
-Xhost-swiftc
is better.
@neonichu @abertelrud, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case you all think that products that need to be compiled for the host will need to invoke something else but swiftc?
Yes, this was the motivation for suggesting to broaden the discussion here. There are flags for other tools (-Xcc
, -Xlinker
, etc) and for each of those it's quite possible that the flags will need to be different for the host vs the destination during a regular build (as opposed to compilation of a manifest or plugin, which today is handled outside the build system).
I didn't realize that the compiler driver allows these flags to be composed, however. It's important to support Clang as well, but if it also supports composition, then doing -Xmanifest -Xlinker -Xmanifest -lfoo
(for example) seems like a way around that.
I still think that the name -Xhost
is too generic in this case, if it only applies to compilation of manifests and plugins, since I'd expect that with that name it would also apply to products built for the host.
I agree with your argument that -Xhost-swiftc is better.
This order seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that the name -Xhost is too generic in this case, if it only applies to compilation of manifests and plugins, since I'd expect that with that name it would also apply to products built for the host.
I used the name because it is the name of the "destination" used for the manifest. I am fine changing it if someone can find a good common name that applies to both manifest and plugins.
If we follow compnerd recommendation (#5966 (comment)) and want to follow the GCC naming (https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html), one possibility would be -Xbuild
, but that might be confusing with internal terminology (and the fact that the concepts of "target" and "host" are a little bit dilutted by LLVM architecture).
Finally, if we want to add this as -X<whatever>-swiftc
in this PR I am fine doing that change. -Xmanifest
will be left as a deprecated detail that did not support several tools.
/cc @compnerd I forgot to look for the original author of |
I think that |
I used "host" because that's the internal name of the toolchain used to compile the manifest and the plugins: https://github.com/apple/swift-package-manager/blob/14d05ccaa13b768449cd405fff81d630a520e04a/Sources/PackageModel/Destination.swift#L159 I know it is not the right terminology, but it is the one that fits with the current model, which I think is more important. It is also a hidden option, so it is not like we are exposing bad terminology to most users, only those who need it. I did not want to add If somebody changes their minds to these new terms, the spelling is relatively easy to change, but I think a common |
e013a62
to
4781bd0
Compare
|
Sources/CoreCommands/SwiftTool.swift
Outdated
@@ -335,6 +335,10 @@ public final class SwiftTool { | |||
if let _ = options.security.netrcFilePath, options.security.netrc == false { | |||
observabilityScope.emit(.mutuallyExclusiveArgumentsError(arguments: ["--disable-netrc", "--netrc-file"])) | |||
} | |||
|
|||
if !options.build._deprecated_manifestFlags.isEmpty { | |||
observabilityScope.emit(warning: "'-Xmanifest' option is deprecated; use '-Xhost' instead") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@natecook1000 does argument parser support deprecated arguments? I can see this being super useful in SwiftPM use case, where one can mark a flag as deprecate and provide a deprecation message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have built-in support for that — could you open an issue? I could see it added to the help for an argument.
shouldDisplay: false)) | ||
public var _deprecated_manifestFlags: [String] = [] | ||
|
||
var manifestFlags: [String] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
4781bd0
to
7df5a4e
Compare
If someone can have a look at the new version and fire up the testing, I will appreciate it. Edit: also changed from |
7df5a4e
to
21e1595
Compare
@swift-ci please smoke test |
21e1595
to
2b1a27d
Compare
|
Is there something else I need to do for this to be considered for merging? Did I miss some of the feedback? |
7d67288
to
b75d814
Compare
|
b75d814
to
714b2b7
Compare
|
@swift-ci smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! 👍
714b2b7
to
4d911fa
Compare
Rebased on top of Can this be tested and merged in its current state? Do the maintainers require any more changes? I don't know if we are happy with the current spelling or not, but I have not seen any other proposals, or any proposal that everybody is happy with. Since this is a hidden option for a very special use case, can we not merge the current spelling and if anyone came up with a better name use the new name then? |
personally I am happy with this and would very much like to see this over the finish line. IIUC @neonichu @abertelrud @MaxDesiatov may still have some concerns about naming. also adding @compnerd since he may have opinion / suggestions for a name. @neonichu to your point about "Extensible Build Tools" proposal, I agree and think we should retitle it to "Extensible Tools" or "SwiftPM Plugins", happy to make that PR if @abertelrud et all agree. In any case, let's try to get this merged. If by the end of this week we cannot agree on a name, I can help decide on one. |
With the announcement of Swift 5.9 release process, I would like to give another gentle ping to this PR to see if it can move forward and be merged before the cut. I am also happy to try to implement changes for any feedback that can still appear. |
4d911fa
to
f53f876
Compare
I'm not super happy with the name, but let's move forward with this anyway. |
@swift-ci please smoke test |
For most case, compiling against the host toolchain does not need extra arguments, but in some complicated setups, the host toolchain might need extra arguments for search paths and such. In the case of the manifest, the option of using `-Xmanifest` arguments to customize the manifest compilation has existed for a while, but in the case of plugins, the same option was not available and made consuming packages with plugins very complicated. The changes in this commit add `-Xbuild-tools-swiftc` to affect both manifest and plugin compilation, allowing complicated setups to provide their values and compile and use plugins. `-Xmanifest` is kept for backwards compatibility, but it will only affect manifest compilation, as before, and it will print a warning if used. Includes modifications in one of the plugin tests to show that the `-Xbuild-tools-swiftc` parameters are passed to the plugin compilation (I could not find a similar test for `-Xmanifest`).
f53f876
to
ba2310c
Compare
Rebased on I think the failed check on macOS for previous commit was not caused by these changes:
|
@swift-ci smoke test |
the |
self._deprecated_manifestFlags | ||
} | ||
|
||
var pluginSwiftCFlags: [String] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not blocking, but wasnt the idea to also expose this is a user facing flag? or is that for next PR so we can debbate the name? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean supporting both -Xbuild-tools-swiftc
which applies to every build time tool and a -Xplugin-swiftc
which only applies to plugins? I never got that impression from the feedback, but I might have missed that facet. I am not sure that I can see an scenario in which someone has different sets of flags for the same native machine depending if they are compiling a plugin or some other build time tool. The solution as implemented can grow in that direction, if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could have been my misunderstanding of he goal of this PR. in any case as you say this sets the ground work if needed, and this feedback is by no means to hold the PR back 👍
@neonichu good to merge? |
I wanted to give another gentle ping towards the end of last week, but I forgot. Is there something I need or can do to get this merged before the release 5.9 is branch off? Thank you very much for all the feedback and the reviews. |
@swift-ci test windows |
thanks for your patience @drodriguez |
Allow customizing the compilation of plugins by passing
-Xbuild-tools-swiftc
parameters to theswift build
invocation, the same that customizing the compilation of the manifest was possible with-Xmanifest
parameters.Motivation:
For most cases, compiling against the host toolchain does not need extra arguments, but in some complicated setups, the host toolchain might need extra arguments for search paths and such. In the case of the manifest, the option of using
-Xmanifest
arguments to customize the manifest compilation has existed for a while, but in the case of plugins, the same option was not available and made consuming packages with plugins very complicated.Modifications:
The changes in this commit modify the former
-Xmanifest
to understand an alias-Xbuild-tools-swiftc
and apply the provided arguments to both the manifest and the plugin compilation, allowing complicated setups to provide their values and compile and use plugins.Includes modifications in one of the plugin tests to show that the
-Xbuild-tools-swiftc
parameters are passed to the plugin compilation (I could not find a similar test for-Xmanifest
).Result:
Setups that need to use a complicated environment can compile plugins by passing
-Xbuild-tools-swiftc
arguments to theswift build
invocation and the plugin compilation will use such arguments.