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

makes buf version configurable #10

Merged
merged 4 commits into from
Feb 8, 2022
Merged

makes buf version configurable #10

merged 4 commits into from
Feb 8, 2022

Conversation

srikrsna-buf
Copy link
Member

Closes #4

This depends on our GitHub release assets of buf. It defaults to latest version if one is not provided. We download the sha256.txt of a release and download the releases using those hashes.

buf/internal/toolchain.bzl Outdated Show resolved Hide resolved
Comment on lines 106 to 111
ctx.download(
url = "https://github.com/bufbuild/buf/releases/download/{}/{}".format(version, bin),
sha256 = sum,
executable = True,
output = "{}/{}".format(target, bin),
)

Choose a reason for hiding this comment

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

This will download every binary no matter if it ends up being used or not. Can we instead generate http_file rules for each of these?

Copy link
Member Author

Choose a reason for hiding this comment

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

How will that work?

Since http_file rules are repository_rules adding them to the generated WORKSPACE won't work as they won't be available within the root workspace.

To generate http_file rules themselves the macro should be able to download the sha256.txt file which may not be possible until bzlmod lands.

Choose a reason for hiding this comment

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

Right, I think this repository rule would do a download for the list of releases and generate generate a bzl file with http_rules that gets loaded in the main repository.

Not sure if that's what rules_go does, but I'm pretty sure there you don't have to download every distribution type of the sdk.

Copy link
Member Author

@srikrsna-buf srikrsna-buf Feb 7, 2022

Choose a reason for hiding this comment

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

They try and guess the GOOS and GOARCH in the rule itself and download the appropriate version. The problem with that is for every platform the repo needs to be re triggered, not sure how that affects remote caching

https://github.com/bazelbuild/rules_go/blob/master/go/private/sdk.bzl#L240

Choose a reason for hiding this comment

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

On a single platform, when would the rules be re-triggered? Making users download the cross product of os+cpu architecture does not seem like the right direction, I doubt that other toolchains like a clang/gcc would force this. Can we explore alternatives a bit more?

Comment on lines +96 to +101
sha_list = ctx.read("sha256.txt").splitlines()
for sha_line in sha_list:
if sha_line.strip(" ").endswith(".tar.gz"):
continue
(sum, _, bin) = sha_line.partition(" ")
bin = bin.strip(" ")

Choose a reason for hiding this comment

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

Have we committed to our sha256.txt file format? Given that something is a plain text file, this seems pretty easy to change without knowing that it needs to have an exact format or the bazel rule updating will break.

Copy link
Member Author

Choose a reason for hiding this comment

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

I share the concern. We have been consistent so far. Is there any alternative that you have in mind?

I was hoping GitHub's API would have it but no luck there.

Choose a reason for hiding this comment

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

At minimum updating the release instructions and scripts to contain notes/comments that indicate this isn't an arbitrary format txt file, but maybe we should update the releases to contain a shas.json file or similar?

Copy link
Member Author

Choose a reason for hiding this comment

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

sha.json will be better if we can get it before we release v1.0.0. That way we can limit the minimum version to be v1.0.0 and only depend on the json file.

I'll take this up on buf. Merging this for now.

"""

def _register_toolchains(repo, cmd):
native.register_toolchains(
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we are registering only one toolchain per tool. It will be backed by the right binary. That is handled by _buf_download_releases

},
)

def declare_buf_toolchains(os, cpu, rules_buf_repo_name):
Copy link
Member Author

Choose a reason for hiding this comment

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

Declare the toolchains in the proxy repo and reference the toolchain type in rules_buf

@srikrsna-buf srikrsna-buf merged commit 5620213 into main Feb 8, 2022
@srikrsna-buf srikrsna-buf deleted the buf-versions branch February 8, 2022 17:11
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.

Make buf version configurable
3 participants