Skip to content
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

SwiftPM plugin: generate files into the source directory #1343

Open
gliush opened this issue Nov 15, 2022 · 8 comments
Open

SwiftPM plugin: generate files into the source directory #1343

gliush opened this issue Nov 15, 2022 · 8 comments

Comments

@gliush
Copy link

gliush commented Nov 15, 2022

Hello,

I would like to keep the generated files in the repository as well as the .proto files.
This seems to be useful at least for the following reasons:

  • The protoc is not part of the project, and its version is something that is defined by the environment. I want to be sure that some strange CI environment (with old or buggy version of the protoc) will not ruin my production.
  • Check and monitor any change to the generated files (who did when and why), especially in case of protoc version change.

The current version doesn't work for me as it puts the generated files into the .build folder.

I would like to either:

  • be able to specify the path for the generated file, and make it possible to put it to the source path.
  • have a command to generate swift files from protobuf files.

It seems that https://github.com/apple/swift-evolution/blob/main/proposals/0332-swiftpm-command-plugins.md allows both:

  • PluginPermission allows to write to the package directory
  • CommandPlugin allows to have a plugin command to perform any action.

The second approach is preferable for me as it allows to run the generation on-request from the developer.

@FranzBusch
Copy link
Member

Hey @gliush,

Right now our SPM plugin is a BuildPlugin that is generating the code during build time. These kind of plugins will only generate the code into build directories.

I think we need to take a step back here and talk about your reasons for why you want to commit the files:

The protoc is not part of the project, and its version is something that is defined by the environment. I want to be sure that some strange CI environment (with old or buggy version of the protoc) will not ruin my production.

I understand that concern and we don't like that protoc is coming from the environment right now. One of the ideas we have been playing around with is having one blessed swift package that exports protoc for the whole ecosystem. SPM just landed support for exporting binaryTargets so that is something we want to look into in the future and will resolve this issue for you.

Check and monitor any change to the generated files (who did when and why), especially in case of protoc version change.

IMO you should monitor the changes to the proto files and not to the generated code. The generated code should be invisible to you at best.

On a side note, I think having a separate CommandPlugin is something useful and I would love to see somebody trying to contribute this.

@gliush
Copy link
Author

gliush commented Nov 15, 2022

Yes, if we have protoc in the project itself, it will cover all my concerns.
Though, what if I run my code compilation on two OSes? (Linux and macOS)? Will we have binaries for each OS we would like to work with?

@FranzBusch
Copy link
Member

Yes, if we have protoc in the project itself, it will cover all my concerns.
Though, what if I run my code compilation on two OSes? (Linux and macOS)? Will we have binaries for each OS we would like to work with?

This would be a requirement for the whole endeavour. I can't promise anything here but we are exploring this.

@gliush
Copy link
Author

gliush commented Nov 15, 2022

Sounds great!

@thomasvl
Copy link
Collaborator

What's the actually status/request here? Seems like the discussion covered a few things, so I'm not completely clear what this issue is now meant to track. Can someone update it or close it out and open a new issue that's a little more clear with what ever the pending request is?

@FranzBusch
Copy link
Member

I think the latest here is that we need protoc available in the SPM ecosystem and then @gliush request would be solved.

@thomasvl
Copy link
Collaborator

Is that the same as #1409?

@FranzBusch
Copy link
Member

Yes, I think both point to the same underlying problem

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

No branches or pull requests

3 participants