File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed
Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,22 @@ _DOC = """
2323For 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+
2642def _executable_extension (ctx ):
2743 extension = ""
2844 if ctx .os .name .startswith ("windows" ):
@@ -41,7 +57,18 @@ def _valid_pin(pin):
4157 return True
4258
4359def _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 ):
You can’t perform that action at this time.
0 commit comments