Skip to content

Commit d717652

Browse files
authored
Update Bazel build to work with 4.0.0 (#428)
* Update Bazel build to work with 4.0.0 This includes several updates to the BUILD and WORKSPACE files, so that they now work with Bazel 4.0.0, Gazelle 0.23 and rules_go 0.27. By default, [Gazelle now uses](bazel-contrib/bazel-gazelle#863) the last component of the Bazel package, rather than `go_default_library` as the `go_library name`. This causes problems when the naming conventions do not match. bazel-contrib/bazel-gazelle#890 (comment) Adding support for the new naming convention should not break anything that depends on using the old naming convention, because the Gazelle option `import_alias` makes aliases to the libraries and this allows the old naming convention to still work.
1 parent ecf7cda commit d717652

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

BUILD.bazel

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
1-
package(default_visibility = ["//visibility:private"])
2-
3-
load("@bazel_gazelle//:def.bzl", "gazelle")
41
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
load("@bazel_gazelle//:def.bzl", "gazelle")
53

6-
gazelle(
7-
name = "gazelle",
8-
command = "fix",
9-
prefix = "github.com/go-resty/resty/v2",
10-
)
4+
# gazelle:prefix github.com/go-resty/resty/v2
5+
# gazelle:go_naming_convention import_alias
6+
gazelle(name = "gazelle")
117

128
go_library(
13-
name = "go_default_library",
14-
srcs = glob(
15-
["*.go"],
16-
exclude = ["*_test.go"],
17-
),
9+
name = "resty",
10+
srcs = [
11+
"client.go",
12+
"middleware.go",
13+
"redirect.go",
14+
"request.go",
15+
"response.go",
16+
"resty.go",
17+
"retry.go",
18+
"trace.go",
19+
"transport.go",
20+
"transport112.go",
21+
"util.go",
22+
],
1823
importpath = "github.com/go-resty/resty/v2",
1924
visibility = ["//visibility:public"],
2025
deps = ["@org_golang_x_net//publicsuffix:go_default_library"],
2126
)
2227

2328
go_test(
24-
name = "go_default_test",
25-
srcs =
26-
glob(
27-
["*_test.go"],
28-
exclude = ["example_test.go"],
29-
),
30-
data = glob([".testdata/*"]),
31-
embed = [":go_default_library"],
32-
importpath = "github.com/go-resty/resty/v2",
33-
deps = [
34-
"@org_golang_x_net//proxy:go_default_library",
29+
name = "resty_test",
30+
srcs = [
31+
"client_test.go",
32+
"context_test.go",
33+
"example_test.go",
34+
"request_test.go",
35+
"resty_test.go",
36+
"retry_test.go",
37+
"util_test.go",
3538
],
39+
data = glob([".testdata/*"]),
40+
embed = [":resty"],
41+
deps = ["@org_golang_x_net//proxy:go_default_library"],
42+
)
43+
44+
alias(
45+
name = "go_default_library",
46+
actual = ":resty",
47+
visibility = ["//visibility:public"],
3648
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,13 @@ client.SetTransport(&transport).SetScheme("http").SetHostURL(unixSocket)
829829
client.R().Get("/index.html")
830830
```
831831

832-
#### Bazel support
832+
#### Bazel Support
833833

834834
Resty can be built, tested and depended upon via [Bazel](https://bazel.build).
835835
For example, to run all tests:
836836

837837
```shell
838-
bazel test :go_default_test
838+
bazel test :resty_test
839839
```
840840

841841
#### Mocking http requests using [httpmock](https://github.com/jarcoal/httpmock) library

WORKSPACE

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
workspace(name = "resty")
22

3-
git_repository(
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
46
name = "io_bazel_rules_go",
5-
remote = "https://github.com/bazelbuild/rules_go.git",
6-
tag = "0.13.0",
7+
sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
10+
"https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
11+
],
712
)
813

9-
git_repository(
14+
http_archive(
1015
name = "bazel_gazelle",
11-
remote = "https://github.com/bazelbuild/bazel-gazelle.git",
12-
tag = "0.13.0",
16+
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
17+
urls = [
18+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
19+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
20+
],
1321
)
1422

15-
load(
16-
"@io_bazel_rules_go//go:def.bzl",
17-
"go_rules_dependencies",
18-
"go_register_toolchains",
19-
)
23+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
2024

2125
go_rules_dependencies()
2226

23-
go_register_toolchains()
27+
go_register_toolchains(version = "1.16")
2428

2529
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
2630

0 commit comments

Comments
 (0)