Skip to content

feat(internal/librarian): add protoc installation support#6583

Open
JoeWang1127 wants to merge 23 commits into
mainfrom
feat/install-protoc
Open

feat(internal/librarian): add protoc installation support#6583
JoeWang1127 wants to merge 23 commits into
mainfrom
feat/install-protoc

Conversation

@JoeWang1127

@JoeWang1127 JoeWang1127 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Add the ability to install the protoc compiler from GitHub releases.

The install function downloads the protoc zip archive for the host platform, verifies its checksum, and extracts it to the librarian bin directory.

For #6558

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for downloading and installing the protoc compiler. It adds a new Protoc configuration struct, a ZIP extraction utility with Zip Slip protection, and the core installation logic along with corresponding tests. The review feedback focuses on improving cross-platform compatibility, suggesting that the download URL dynamically determine the platform suffix based on the host OS and architecture, that the path filtering handle the .exe extension on Windows using forward slashes, and that the tests mock the platform suffix to remain deterministic.

Comment thread internal/librarian/protoc.go
Comment thread internal/librarian/protoc.go Outdated
Comment thread internal/librarian/protoc.go Outdated
Comment thread internal/librarian/protoc_test.go
@JoeWang1127 JoeWang1127 changed the title feat(internal/librarian): install protoc to librarian bin directory feat(internal/librarian): add protoc installation support Jul 1, 2026
@JoeWang1127 JoeWang1127 marked this pull request as ready for review July 1, 2026 01:47
@JoeWang1127 JoeWang1127 requested a review from a team as a code owner July 1, 2026 01:47
@JoeWang1127 JoeWang1127 requested a review from zhumin8 July 1, 2026 01:47
Comment thread internal/librarian/protoc.go Outdated

var (
// downloadURL returns the download URL for the protoc binary for the given version and platform.
downloadURL = func(version string) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe let's make the base (https://github.com) a global var that we can replace with the test server, and make this an actual function that we can test coverage for.

That would be cleaner code all around.

var (
// downloadURL returns the download URL for the protoc binary for the given version and platform.
downloadURL = func(version string) string {
return fmt.Sprintf("https://github.com/protocolbuffers/protobuf/releases/download/v%s/protoc-%s-%s.zip", version, version, platformSuffix())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

embedding execution of platformSuffix may make this a little harder to test on various platforms. Maybe we should have a platform string parameter that tests can just provide, rather than have the potential point of variance introduced by running this on different dev / CI machines.

return filepath.Join(binDir, "protoc", fmt.Sprintf("v%s", version)), nil
}

func platformSuffix() string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: please add a comment, all the other funcs have them :)

@noahdietz

Copy link
Copy Markdown
Contributor

Stoked about this! I'm guessing a follow up will introduce the code changes to language packages to use the librarian installed protoc ?

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