-
-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a MODULE.bazel that makes rules_go usable as a bzlmod module for basic use cases. The new module definition is verified by a test module that will be used in the presubmit tests of the Bazel Central Registry (BCR). The following features require more thought and/or work and are not yet supported: * SDK rules other than go_host_sdk and go_download_sdk. * non-no-op nogo * go_proto_library
- Loading branch information
Showing
14 changed files
with
157 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bcr_tests |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/bazel-* | ||
/tests/core/cgo/libimported.* | ||
/tests/core/cgo/libversioned.* | ||
/bcr_tests/bazel-* |
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,21 @@ | ||
module( | ||
name = "io_bazel_rules_go", | ||
version = "0.29.0", | ||
compatibility_level = 1, | ||
toolchains_to_register = [ | ||
"@go_host_sdk//:all", | ||
], | ||
) | ||
|
||
bazel_dep(name = "bazel_skylib", version = "1.1.1") | ||
bazel_dep(name = "platforms", version = "0.0.4") | ||
|
||
non_module_dependencies = use_extension("@io_bazel_rules_go//go/private:extensions.bzl", "non_module_dependencies") | ||
use_repo( | ||
non_module_dependencies, | ||
"io_bazel_rules_nogo", | ||
) | ||
|
||
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") | ||
go_sdk.host(name = "go_host_sdk") | ||
use_repo(go_sdk, "go_host_sdk") |
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 @@ | ||
build --experimental_enable_bzlmod |
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 @@ | ||
20d880770fb5657d4cb35c971d074b6965a820a8 |
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,19 @@ | ||
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "lib", | ||
srcs = ["lib.go"], | ||
importpath = "example.com/lib", | ||
) | ||
|
||
go_binary( | ||
name = "main", | ||
srcs = ["main.go"], | ||
deps = [":lib"], | ||
) | ||
|
||
go_test( | ||
name = "test", | ||
srcs = ["test.go"], | ||
embed = [":lib"], | ||
) |
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,16 @@ | ||
module( | ||
name = "rules_go_bcr_tests", | ||
toolchains_to_register = [ | ||
"@go_sdk//:all", | ||
], | ||
) | ||
|
||
bazel_dep(name = "io_bazel_rules_go", version = "", repo_name = "rules_go") | ||
local_path_override( | ||
module_name = "io_bazel_rules_go", | ||
path = "..", | ||
) | ||
|
||
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") | ||
go_sdk.download(name = "go_sdk", version = "1.17.5") | ||
use_repo(go_sdk, "go_sdk") |
Empty file.
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,5 @@ | ||
package lib | ||
|
||
func Name() string { | ||
return "bzlmod" | ||
} |
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,11 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"example.com/lib" | ||
) | ||
|
||
func main() { | ||
fmt.Printf("Hello %s!", lib.Name()) | ||
} |
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,11 @@ | ||
package lib | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestName(t *testing.T) { | ||
if Name() != "bzlmod" { | ||
t.Fail() | ||
} | ||
} |
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,3 @@ | ||
load("//go/private:extensions.bzl", _go_sdk = "go_sdk") | ||
|
||
go_sdk = _go_sdk |
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,53 @@ | ||
load("//go/private:sdk.bzl", "go_download_sdk", "go_host_sdk") | ||
load("//go/private:repositories.bzl", "go_rules_dependencies") | ||
|
||
_download_tag = tag_class( | ||
attrs = { | ||
"name": attr.string(mandatory = True), | ||
"goos": attr.string(), | ||
"goarch": attr.string(), | ||
"sdks": attr.string_list_dict(), | ||
"urls": attr.string_list(default = ["https://dl.google.com/go/{}"]), | ||
"version": attr.string(), | ||
"strip_prefix": attr.string(default = "go"), | ||
}, | ||
) | ||
|
||
_host_tag = tag_class( | ||
attrs = { | ||
"name": attr.string(mandatory = True), | ||
}, | ||
) | ||
|
||
def _go_sdk_impl(ctx): | ||
for mod in ctx.modules: | ||
for download_tag in mod.tags.download: | ||
go_download_sdk( | ||
name = download_tag.name, | ||
goos = download_tag.goos, | ||
goarch = download_tag.goarch, | ||
sdks = download_tag.sdks, | ||
urls = download_tag.urls, | ||
version = download_tag.version, | ||
register_toolchains = False, | ||
) | ||
for host_tag in mod.tags.host: | ||
go_host_sdk( | ||
name = host_tag.name, | ||
register_toolchains = False, | ||
) | ||
|
||
go_sdk = module_extension( | ||
implementation = _go_sdk_impl, | ||
tag_classes = { | ||
"download": _download_tag, | ||
"host": _host_tag, | ||
}, | ||
) | ||
|
||
def _non_module_dependencies_impl(ctx): | ||
go_rules_dependencies(force = True) | ||
|
||
non_module_dependencies = module_extension( | ||
implementation = _non_module_dependencies_impl, | ||
) |