forked from google/skia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[bazel] Fix golang cross-compilation on RBE"
This is a reland of commit b2109e6 See cr/488438081 Original change's description: > [bazel] Fix golang cross-compilation on RBE > > Without this change, one could not have a Mac Bazel host > and use our Linux executor to build for a Mac target. > What I observed was the host uploading the Mac go toolchain > to the Linux RBE instance and that not working. > > To fix this, we explicitly download a Linux golang toolchain > as well as one for the host machine. This is straightforward > after the fact (See WORKSPACE.bazel) but took a bit of > experimentation and doc reading to get right. > > To *use* the right toolchain, one must tell the Linux > RBE instance the target platform should be the same as > the host platform. This is a smidge tricky to do correctly > in a script (e.g. a Makefile), so I also added a short > Bazel (read: Python) script to call `go version` and parse > the output into a Bazel-ready os_arch string. > > Change-Id: If009316209c46efa912f39f0f55bd7d6734d27c5 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/604061 > Reviewed-by: Leandro Lovisolo <[email protected]> Change-Id: I8bbeee8bbf6109810915125d581548ebc36acff0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/605077 Reviewed-by: Leandro Lovisolo <[email protected]>
- Loading branch information
Showing
4 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# A helper function to get the go platform string of the Bazel host. | ||
# This can be used to do cross-platform go compilations. | ||
# Example: | ||
# $ bazelisk run //bazel:go_platform | ||
# darwin_arm64 | ||
py_binary( | ||
name = "go_platform", | ||
srcs = ["go_platform.py"], | ||
data = ["@go_sdk//:bin/go"], | ||
tags = ["no-remote"], # Need the platform of the host | ||
) | ||
|
||
_GO_PLATFORM = """ | ||
import os | ||
import subprocess | ||
# https://bazel.build/reference/be/make-variables#predefined_label_variables | ||
go_exe = os.path.abspath("$(execpath @go_sdk//:bin/go)") | ||
result = subprocess.run([ | ||
go_exe, | ||
"version", | ||
], capture_output=True, encoding="utf-8") | ||
# e.g. go version go1.18 darwin/arm64 | ||
os_arch = result.stdout.strip().split(" ")[3] | ||
# e.g. darwin/arm64 | ||
print(os_arch.replace("/", "_")) | ||
""" | ||
|
||
genrule( | ||
name = "create_go_platform_script", | ||
outs = ["go_platform.py"], | ||
cmd = "echo '%s' > $@" % _GO_PLATFORM, | ||
exec_tools = [ | ||
"@go_sdk//:bin/go", | ||
], | ||
) |