Skip to content

Implement proposed adjustments to SE-0303 to use @main for plugins #3712

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

Merged
merged 6 commits into from
Sep 17, 2021

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Sep 3, 2021

This is an implementation of almost all of the approved adjustments to SE-0303 proposed in swiftlang/swift-evolution#1434.

Motivation:

This changes the entry point to use @main rather than top-level code, and introduces protocols for the entry points corresponding to the various plugin capabilities. Using @main allows customized entry points for each kind of plugin, makes it clearer what the inputs and expected outputs of each plugin are by replacing the global variables with method parameters and return values, and will make it easier to add new kinds of plugins in the future.

Modifications:

  • introduce a property in the JSON that SwiftPM sends to the plugin that tells the implementation what plugin function to call
  • in the implementation of the PackagePlugins library:
    • remove the global variables
    • replace CommandConstructor with the Command enum and static factory functions
    • implement a static func main() that decodes input from SwiftPM and calls the plugin
    • replace the atexit() code for dumping output with similar code at the end of the static main()
  • compile the plugin with -parse-as-library so that @main can be used
  • update unit tests accordingly

Result:

Plugins will use the new entry point as described in the amended SE-0303.

The one change left to make is to mark the entry point as async. That cannot be done right now because it would make plugins unavailable on macOS 11 and earlier. Further work is needed to find a way to support async when running on macOS 12 and later, while still supporting macOS 11 for plugins that don't need async APIs.

@abertelrud abertelrud marked this pull request as draft September 3, 2021 18:02
@abertelrud abertelrud force-pushed the eng/plugin-improvements branch from 0fb7392 to 27104d7 Compare September 3, 2021 19:50
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud self-assigned this Sep 3, 2021
@abertelrud abertelrud force-pushed the eng/plugin-improvements branch from 27104d7 to 2d75055 Compare September 6, 2021 18:37
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud changed the title WIP: Implement proposed adjustments to SE-0303 to use @main for plugins Implement proposed adjustments to SE-0303 to use @main for plugins Sep 7, 2021
@abertelrud abertelrud marked this pull request as ready for review September 7, 2021 16:33

struct Diagnostic: Encodable {
enum Severity: String, Encodable {
case error, warning, remark
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remark -> info ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. Or note. In the amendment proposal this is remark, so we should also take it up there whether it should be something else.

@abertelrud abertelrud force-pushed the eng/plugin-improvements branch 2 times, most recently from 2d12188 to 61abc08 Compare September 13, 2021 19:19
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud force-pushed the eng/plugin-improvements branch from 2dc5ea7 to ec71d58 Compare September 15, 2021 23:05
This is an implementation of the proposed adjustments to SE-0303 in swiftlang/swift-evolution#1434.

This changes the entry point to use `@main` rather than top-level code, and introduces protocols for the entry points corresponding to the various plugin capabilities.  It gets rid of the globals in favour of plugin parameters and return values (except for diagnostics, which are still collected using a process-wide list).
…ifications.

Mark the Severity as public and add a method that takes it as a parameter.
@abertelrud abertelrud force-pushed the eng/plugin-improvements branch from ec71d58 to aa295b0 Compare September 16, 2021 05:04
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud force-pushed the eng/plugin-improvements branch from aa295b0 to 1ce1543 Compare September 16, 2021 19:01
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test linux

@abertelrud
Copy link
Contributor Author

abertelrud commented Sep 16, 2021

These Linux failures seem to be outside of the actual changes for this PR... they're also different each time; trying again.

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test linux

@tomerd
Copy link
Contributor

tomerd commented Sep 17, 2021

lgtm 👍

@abertelrud abertelrud merged commit fb98989 into swiftlang:main Sep 17, 2021
@abertelrud abertelrud deleted the eng/plugin-improvements branch September 17, 2021 16:36
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.

2 participants