Skip to content

Commit

Permalink
go: support remote cross-compilation (#307)
Browse files Browse the repository at this point in the history
If no go_download_sdk is declared, go_register_toolchains
automatically declares one for the host platform. But it fails
toolchains resolution if the execution platform is different
than the host platform.
  • Loading branch information
jayconrod authored Mar 27, 2024
1 parent e427a11 commit abfc7d4
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ load("@rules_proto_grpc//java:repositories.bzl", rules_proto_grpc_java_repos = "

rules_proto_grpc_java_repos()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")

rules_proto_dependencies()
Expand Down Expand Up @@ -209,7 +212,7 @@ scalatest_repositories()

scalatest_toolchain()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load(":deps.bzl", "go_dependencies")

Expand All @@ -218,7 +221,27 @@ go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.21.6")
GO_PLATFORMS = [
("darwin", "amd64"),
("darwin", "arm64"),
("linux", "amd64"),
("linux", "arm64"),
("windows", "amd64"),
]

GO_VERSION = "1.21.6"

[
go_download_sdk(
name = "go_{}_{}".format(goos, goarch),
goarch = goarch,
goos = goos,
version = GO_VERSION,
)
for goos, goarch in GO_PLATFORMS
]

go_register_toolchains()

gazelle_dependencies()

Expand Down

0 comments on commit abfc7d4

Please sign in to comment.