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

[internal] Add plugin hook for Go codegen support #14707

Merged
merged 7 commits into from
Mar 4, 2022

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Mar 4, 2022

Closes #14258. As described there, codegen for compiled languages is more complex because the generated code must be compiled, unlike Python where the code only needs to be present.

We still use the GenerateSourcesRequest plugin hook to generate the raw .go files and so that integrations like export-codegen goal still work. But that alone is not powerful enough to know how to compile the Go code.

So, we add a new Go-specific plugin hook. Plugin implementations return back the standardized type BuildGoPackageRequest, which is all the information needed to compile a particular package, including by compiling its transitive dependencies. That allows for complex codegen modeling such as Protobuf needing the Protobuf third-party Go package compiled first, or Protobufs depending on other Protobufs.

Rule authors can then directly tell Pants to compile that codegen (#14705), or it can be loaded via a dependency on a normal go_package.

It's not sufficient for compiled languages. We'll need a new plugin hook instead.

Still keep a dedicated rule for generating the source files though. That is nice for readability and testing.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano

This comment was marked as outdated.

)

# Running directly on a codegen target should work.
assert_pkg_target_built(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this triggers actual Go compilation - it works 🙌

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
)

# Running directly on a codegen target should work.
assert_pkg_target_built(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

src/python/pants/engine/internals/graph.py Outdated Show resolved Hide resolved
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…e codegen

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano
Copy link
Contributor Author

PTAL at the newest commit to make sure it's okay. I made the test more complex to ensure we can handle codegen depending on go_third_party_package targets, which is cyclical. We can 🎉 yay the engine!

@Eric-Arellano Eric-Arellano requested a review from tdyas March 4, 2022 20:30
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano enabled auto-merge (squash) March 4, 2022 21:03
@Eric-Arellano Eric-Arellano merged commit 8db4f81 into pantsbuild:main Mar 4, 2022
@Eric-Arellano Eric-Arellano deleted the go-codegen branch March 4, 2022 21:56
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.

teach codegen rules to accomodate compiled languages
2 participants