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

Avoid involving a toolchain for the other build platform #72

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def go_binary_impl(ctx):
lib_out = ctx.outputs.lib

emit_go_link_action(
ctx,
ctx,
transitive_libs=lib_result.transitive_go_library_object,
importmap=lib_result.transitive_go_importmap,
cgo_deps=lib_result.transitive_cgo_deps,
Expand Down Expand Up @@ -960,37 +960,54 @@ def cgo_library(name, srcs,
**kwargs
)


################

_toolchain_map = {
'linux': struct(
url = "https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz",
sha256 = "702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95",
),
'mac os x': struct(
Copy link
Contributor

Choose a reason for hiding this comment

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

The bazel-standard name is "darwin", so maybe just use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It must be consistent to ctx.os.name and it is actually "mac os x".

url = "https://storage.googleapis.com/golang/go1.7.darwin-amd64.tar.gz",
sha256 = "51d905e0b43b3d0ed41aaf23e19001ab4bc3f96c3ca134b48f7892485fc52961",
),
}

GO_TOOLCHAIN_BUILD_FILE = """
package(
default_visibility = [ "//visibility:public" ])

filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
srcs = glob(["bin/*", "pkg/**", ]),
)

filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
srcs = [ "bin/go" ],
)

filegroup(
name = "go_include",
srcs = [ "go/pkg/include" ],
srcs = [ "pkg/include" ],
)
"""

def go_repositories():
native.new_http_archive(
name= "golang_linux_amd64",
url = "https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz",
build_file_content = GO_TOOLCHAIN_BUILD_FILE,
sha256 = "702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95"
)
def _go_repositories_impl(ctx):
toolchain = _toolchain_map.get(ctx.os.name)
if not toolchain:
fail("unsupported operating system: " + ctx.os.name)

native.new_http_archive(
name= "golang_darwin_amd64",
url = "https://storage.googleapis.com/golang/go1.7.darwin-amd64.tar.gz",
build_file_content = GO_TOOLCHAIN_BUILD_FILE,
sha256 = "51d905e0b43b3d0ed41aaf23e19001ab4bc3f96c3ca134b48f7892485fc52961"
result = ctx.execute(["mkdir", "-p", ctx.path('')])
if result.return_code:
fail("cannot create directory %s: %s" % (ctx.path(''), result.stderr))
ctx.download_and_extract(toolchain.url, '.', toolchain.sha256, 'tar.gz', 'go')
ctx.file("BUILD", GO_TOOLCHAIN_BUILD_FILE, False)

_go_repositories = repository_rule(_go_repositories_impl)

def go_repositories():
_go_repositories(
name = "io_bazel_rules_go_toolchain",
)
36 changes: 7 additions & 29 deletions go/toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
package(
default_visibility = ["//src:__subpackages__"],
default_visibility = ["//visibility:public"],
)

config_setting(
name = "darwin",
values = {"host_cpu": "darwin"},
)

config_setting(
name = "k8",
values = {"host_cpu": "k8"},
)

filegroup(
alias(
name = "toolchain",
srcs = select({
":darwin": ["@golang_darwin_amd64//:toolchain"],
":k8": ["@golang_linux_amd64//:toolchain"],
}),
visibility = ["//visibility:public"],
actual = "@io_bazel_rules_go_toolchain//:toolchain",
)

filegroup(
alias(
name = "go_tool",
srcs = select({
":darwin": ["@golang_darwin_amd64//:go_tool"],
":k8": ["@golang_linux_amd64//:go_tool"],
}),
visibility = ["//visibility:public"],
actual = "@io_bazel_rules_go_toolchain//:go_tool",
)

filegroup(
alias(
name = "go_include",
srcs = select({
":darwin": ["@golang_darwin_amd64//:go_include"],
":k8": ["@golang_linux_amd64//:go_include"],
}),
visibility = ["//visibility:public"],
actual = "@io_bazel_rules_go_toolchain//:go_include",
)