Skip to content

Commit e504463

Browse files
chore: clean up and update Bazel build files
Significant changes here: - The WORKSPACE file is removed. Bazel disables WORKSPACE by default anyway in Bazel 8, and bzlmod has been available to use for several versions before that. - Update rules_python module. Remove the custom Python toolchain infrastructure which is only used to find a Python C header to include, instead use @rules_python//python/cc:current_py_cc_headers. - Make build targets private by default. Explicitly make public just the ones that are actually public interface (the jsonnet and jsonnetfmt command line tools, the C, C++ and Python libraries). - Keep internal headers private.
1 parent ca6dee1 commit e504463

File tree

15 files changed

+427
-221
lines changed

15 files changed

+427
-221
lines changed

MODULE.bazel

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@ module(
33
version = "0.21.0-rc2",
44
)
55

6-
bazel_dep(name = "googletest", version = "1.11.0", repo_name = "com_google_googletest")
7-
bazel_dep(name = "rules_python", version = "0.40.0")
8-
9-
build_defs = use_extension("//tools/build_defs:extensions.bzl", "build_defs")
10-
use_repo(
11-
build_defs,
12-
"default_python3_headers",
13-
)
14-
15-
register_toolchains("//platform_defs:default_python3_toolchain")
6+
bazel_dep(name = "googletest", version = "1.16.0")
7+
bazel_dep(name = "rules_python", version = "1.2.0")

MODULE.bazel.lock

Lines changed: 377 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE

Lines changed: 0 additions & 19 deletions
This file was deleted.

cmd/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package(default_visibility = ["//visibility:public"])
1+
package(default_visibility = ["//visibility:private"])
22

33
cc_library(
44
name = "utils",
@@ -10,6 +10,7 @@ cc_library(
1010
cc_binary(
1111
name = "jsonnet",
1212
srcs = ["jsonnet.cpp"],
13+
visibility = ["//visibility:public"],
1314
deps = [
1415
":utils",
1516
"//core:libjsonnet",
@@ -19,6 +20,7 @@ cc_binary(
1920
cc_binary(
2021
name = "jsonnetfmt",
2122
srcs = ["jsonnetfmt.cpp"],
23+
visibility = ["//visibility:public"],
2224
deps = [
2325
":utils",
2426
"//core:libjsonnet",

core/BUILD

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
1-
package(default_visibility = ["//visibility:public"])
1+
package(default_visibility = ["//visibility:private"])
22

33
cc_library(
44
name = "libjsonnet",
55
srcs = [
6-
"desugarer.cpp",
7-
"formatter.cpp",
8-
"lexer.cpp",
9-
"libjsonnet.cpp",
10-
"parser.cpp",
11-
"pass.cpp",
12-
"path_utils.cpp",
13-
"static_analysis.cpp",
14-
"string_utils.cpp",
15-
"vm.cpp",
16-
],
17-
hdrs = [
186
"ast.h",
7+
"desugarer.cpp",
198
"desugarer.h",
9+
"formatter.cpp",
2010
"formatter.h",
2111
"json.h",
12+
"lexer.cpp",
2213
"lexer.h",
14+
"libjsonnet.cpp",
15+
"parser.cpp",
2316
"parser.h",
17+
"pass.cpp",
2418
"pass.h",
19+
"path_utils.cpp",
2520
"path_utils.h",
2621
"state.h",
22+
"static_analysis.cpp",
2723
"static_analysis.h",
2824
"static_error.h",
25+
"string_utils.cpp",
2926
"string_utils.h",
3027
"unicode.h",
28+
"vm.cpp",
3129
"vm.h",
3230
],
33-
includes = ["."],
34-
linkopts = ["-lm"],
35-
deps = [
36-
"//include:libjsonnet",
37-
"//include:libjsonnet_fmt",
31+
copts = ["-I."],
32+
implementation_deps = [
3833
"//stdlib:std",
3934
"//third_party/json",
4035
"//third_party/md5:libmd5",
4136
"//third_party/rapidyaml:ryml",
4237
],
38+
linkopts = ["-lm"],
39+
visibility = ["//visibility:public"],
40+
deps = [
41+
"//include:libjsonnet",
42+
"//include:libjsonnet_fmt",
43+
],
4344
)
4445

4546
cc_test(
@@ -48,7 +49,7 @@ cc_test(
4849
deps = [
4950
":libjsonnet",
5051
# Note: On Ubuntu, apt-get install libgtest-dev google-mock
51-
"@com_google_googletest//:gtest_main",
52+
"@googletest//:gtest_main",
5253
],
5354
)
5455

@@ -57,7 +58,7 @@ cc_test(
5758
srcs = ["parser_test.cpp"],
5859
deps = [
5960
":libjsonnet",
60-
"@com_google_googletest//:gtest_main",
61+
"@googletest//:gtest_main",
6162
],
6263
)
6364

@@ -66,7 +67,7 @@ cc_test(
6667
srcs = ["libjsonnet_test.cpp"],
6768
deps = [
6869
":libjsonnet",
69-
"@com_google_googletest//:gtest_main",
70+
"@googletest//:gtest_main",
7071
],
7172
)
7273

@@ -75,6 +76,6 @@ cc_test(
7576
srcs = ["unicode_test.cpp"],
7677
deps = [
7778
":libjsonnet",
78-
"@com_google_googletest//:gtest_main",
79+
"@googletest//:gtest_main",
7980
],
8081
)

cpp/BUILD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package(default_visibility = ["//visibility:public"])
1+
package(default_visibility = ["//visibility:private"])
22

33
cc_library(
44
name = "libjsonnet++",
55
srcs = ["libjsonnet++.cpp"],
6+
visibility = ["//visibility:public"],
67
deps = [
78
"//core:libjsonnet",
89
"//include:libjsonnet++",
@@ -15,6 +16,6 @@ cc_test(
1516
data = ["//cpp/testdata"],
1617
deps = [
1718
":libjsonnet++",
18-
"@com_google_googletest//:gtest_main",
19+
"@googletest//:gtest_main",
1920
],
2021
)

include/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
package(default_visibility = ["//visibility:public"])
1+
package(default_visibility = ["//visibility:private"])
22

33
cc_library(
44
name = "libjsonnet",
55
hdrs = ["libjsonnet.h"],
66
includes = ["."],
7+
visibility = ["//core:__pkg__"],
78
)
89

910
cc_library(
1011
name = "libjsonnet_fmt",
1112
hdrs = ["libjsonnet_fmt.h"],
1213
includes = ["."],
14+
visibility = ["//core:__pkg__"],
1315
)
1416

1517
cc_library(
1618
name = "libjsonnet++",
1719
hdrs = ["libjsonnet++.h"],
1820
includes = ["."],
21+
visibility = ["//cpp:__pkg__"],
22+
deps = ["//include:libjsonnet"],
1923
)

platform_defs/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
22

3+
package(default_visibility = ["//visibility:private"])
4+
35
py_runtime(
46
name = "python3",
57
interpreter_path = "/usr/bin/python3",

python/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
load("@rules_python//python:defs.bzl", "py_library", "py_test")
22

3+
package(default_visibility = ["//visibility:private"])
4+
35
cc_binary(
46
name = "_jsonnet.so",
57
srcs = ["_jsonnet.c"],
68
linkshared = 1,
79
deps = [
810
"//core:libjsonnet",
9-
"@default_python3_headers//:headers",
11+
"@rules_python//python/cc:current_py_cc_headers",
1012
],
1113
)
1214

@@ -20,6 +22,7 @@ py_library(
2022

2123
py_test(
2224
name = "_jsonnet_test",
25+
size = "small",
2326
srcs = ["_jsonnet_test.py"],
2427
data = [
2528
"testdata/basic_check.jsonnet",

stdlib/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package(default_visibility = ["//visibility:public"])
1+
package(default_visibility = ["//visibility:private"])
22

33
filegroup(
44
name = "stdlib",
@@ -7,10 +7,10 @@ filegroup(
77

88
cc_library(
99
name = "std",
10-
srcs = [":gen-std-jsonnet-h"],
11-
hdrs = ["std.jsonnet.h"],
1210
includes = ["."],
1311
linkstatic = 1,
12+
textual_hdrs = [":gen-std-jsonnet-h"],
13+
visibility = ["//core:__pkg__"],
1414
)
1515

1616
genrule(

0 commit comments

Comments
 (0)