Skip to content

Commit ebe8d14

Browse files
committed
Fix buf path in buf_dependencies function
Signed-off-by: Sergei Shirshanov <[email protected]>
1 parent bdc843b commit ebe8d14

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

buf/internal/repo.bzl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ _DOC = """
2323
For more info please refer to the [`buf_dependencies` section](https://docs.buf.build/build-systems/bazel#buf-dependencies) of the docs.
2424
"""
2525

26+
# Copied from rules_go: https://github.com/bazelbuild/rules_go/blob/19ad920c6869a179d186a365d117ab82f38d0f3a/go/private/sdk.bzl#L517
27+
def _detect_host_platform(ctx):
28+
goos = ctx.os.name
29+
if goos == "mac os x":
30+
goos = "osx"
31+
elif goos.startswith("windows"):
32+
goos = "windows"
33+
34+
goarch = ctx.os.arch
35+
if goarch == "aarch64":
36+
goarch = "arm64"
37+
elif goarch == "x86_64":
38+
goarch = "amd64"
39+
40+
return goos, goarch
41+
2642
def _executable_extension(ctx):
2743
extension = ""
2844
if ctx.os.name.startswith("windows"):
@@ -41,7 +57,18 @@ def _valid_pin(pin):
4157
return True
4258

4359
def _buf_dependencies_impl(ctx):
44-
buf = ctx.path(Label("@{}//:buf{}".format(ctx.attr.toolchain_repo, _executable_extension(ctx))))
60+
host_os, host_arch = _detect_host_platform(ctx)
61+
binary_real_repo = "@@{workspace}_{host_os}_{host_arch}".format(
62+
workspace = Label("@{toolchain_repo}".format(toolchain_repo = ctx.attr.toolchain_repo)).workspace_name,
63+
host_os = host_os,
64+
host_arch = host_arch,
65+
)
66+
buf = ctx.path(
67+
Label("{binary_real_repo}//:buf{executable_extension}".format(
68+
binary_real_repo = binary_real_repo,
69+
executable_extension = _executable_extension(ctx),
70+
)),
71+
)
4572

4673
for pin in ctx.attr.modules:
4774
if not _valid_pin(pin):

0 commit comments

Comments
 (0)