Skip to content

Commit 3e3a47f

Browse files
authored
Migrate bazel build setup to use bzlmod - Part 1 (#679)
Migrated bazel build from workspace approach to bzlmod. Migrated components: gz-common, io, testing, events, profiler --------- Signed-off-by: Ian Chen <[email protected]>
1 parent 13bded1 commit 3e3a47f

File tree

15 files changed

+318
-398
lines changed

15 files changed

+318
-398
lines changed

.bazelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
common --enable_bzlmod
2+
common --lockfile_mode=off
3+
4+
# Add C++17 compiler flags.
5+
build --cxxopt=-std=c++17
6+
build --host_cxxopt=-std=c++17
7+
8+
build --force_pic
9+
build --strip=never
10+
build --strict_system_includes
11+
build --fission=dbg
12+
build --features=per_object_debug_info
13+
14+
# Enable header processing, required for layering checks with parse_header.
15+
build --process_headers_in_dependencies

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.3.1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ build
22
build_*
33
.DS_Store
44
*.swp
5+
6+
# Bazel generated files
7+
bazel-*

BUILD.bazel

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
load(
2-
"@gz//bazel/skylark:build_defs.bzl",
3-
"GZ_FEATURES",
4-
"GZ_ROOT",
5-
"GZ_VISIBILITY",
6-
"gz_configure_header",
7-
"gz_export_header",
8-
"gz_include_header",
9-
)
10-
load(
11-
"@gz//bazel/lint:lint.bzl",
12-
"add_lint_tests",
13-
)
1+
load("@rules_gazebo//gazebo:headers.bzl", "gz_configure_header", "gz_export_header")
142
load("@rules_license//rules:license.bzl", "license")
153

164
package(
17-
default_applicable_licenses = [GZ_ROOT + "common:license"],
18-
default_visibility = GZ_VISIBILITY,
19-
features = GZ_FEATURES,
5+
default_applicable_licenses = [":license"],
6+
features = [
7+
"layering_check",
8+
"parse_headers",
9+
],
2010
)
2111

2212
license(
@@ -26,20 +16,23 @@ license(
2616

2717
licenses(["notice"])
2818

29-
exports_files(["LICENSE"])
19+
exports_files([
20+
"package.xml",
21+
"LICENSE",
22+
"MODULE.bazel",
23+
])
3024

3125
gz_configure_header(
32-
name = "config",
26+
name = "Config",
3327
src = "include/gz/common/config.hh.in",
34-
cmakelists = ["CMakeLists.txt"],
35-
package = "common",
28+
package_xml = "package.xml",
3629
)
3730

3831
gz_export_header(
39-
name = "include/gz/common/Export.hh",
32+
name = "Export",
33+
out = "include/gz/common/Export.hh",
4034
export_base = "GZ_COMMON",
4135
lib_name = "gz-common",
42-
visibility = ["//visibility:private"],
4336
)
4437

4538
public_headers_no_gen = glob([
@@ -48,45 +41,43 @@ public_headers_no_gen = glob([
4841
"include/gz/common/graph/*.hh",
4942
])
5043

51-
private_headers = glob(["src/*.hh"])
44+
private_headers = glob(
45+
include = [
46+
"src/*.hh",
47+
],
48+
)
5249

5350
sources = glob(
54-
["src/*.cc"],
51+
include = [
52+
"src/*.cc",
53+
],
5554
exclude = [
5655
"src/Plugin.cc",
5756
"src/PluginLoader.cc",
5857
"src/*_TEST.cc",
5958
],
6059
)
6160

62-
gz_include_header(
63-
name = "commonhh_genrule",
64-
out = "include/gz/common.hh",
65-
hdrs = public_headers_no_gen + [
66-
"include/gz/common/config.hh",
67-
"include/gz/common/Export.hh",
68-
],
69-
)
70-
7161
public_headers = public_headers_no_gen + [
7262
"include/gz/common/config.hh",
7363
"include/gz/common/Export.hh",
74-
"include/gz/common.hh",
7564
]
7665

7766
cc_library(
78-
name = "common",
67+
name = "gz-common",
7968
srcs = sources + private_headers,
8069
hdrs = public_headers,
8170
copts = [
8271
"-fexceptions",
8372
"-Wno-unused-value",
8473
],
8574
includes = ["include"],
75+
visibility = ["//visibility:public"],
8676
deps = [
87-
GZ_ROOT + "utils",
88-
GZ_ROOT + "math",
89-
"@uuid",
77+
"@gz-utils//:ImplPtr",
78+
"@gz-utils//log:Logger",
79+
"@gz-math//:gz-math",
80+
"@libuuid",
9081
],
9182
)
9283

@@ -103,11 +94,10 @@ test_sources = glob(
10394
srcs = [src],
10495
copts = ["-fexceptions"],
10596
deps = [
106-
":common",
107-
GZ_ROOT + "common/testing",
108-
"@gtest",
109-
"@gtest//:gtest_main",
97+
":gz-common",
98+
"//testing:testing",
99+
"@googletest//:gtest",
100+
"@googletest//:gtest_main",
101+
"@gz-utils//:ExtraTestMacros",
110102
],
111103
) for src in test_sources]
112-
113-
add_lint_tests()

MODULE.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## MODULE.bazel
2+
module(
3+
name = "gz-common",
4+
repo_name = "org_gazebosim_gz-common",
5+
)
6+
7+
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
8+
bazel_dep(name = "googletest", version = "1.14.0")
9+
bazel_dep(name = "rules_license", version = "1.0.0")
10+
bazel_dep(name = "tinyxml2", version = "10.0.0")
11+
bazel_dep(name = "libuuid", version = "2.39.3.bcr.1")
12+
13+
# Gazebo Dependencies
14+
bazel_dep(name = "rules_gazebo", version = "0.0.2")
15+
bazel_dep(name = "gz-utils")
16+
bazel_dep(name = "gz-math")
17+
18+
archive_override(
19+
module_name = "gz-utils",
20+
strip_prefix = "gz-utils-main",
21+
urls = ["https://github.com/gazebosim/gz-utils/archive/refs/heads/main.tar.gz"],
22+
)
23+
24+
archive_override(
25+
module_name = "gz-math",
26+
strip_prefix = "gz-math-main",
27+
urls = ["https://github.com/gazebosim/gz-math/archive/refs/heads/main.tar.gz"],
28+
)

av/BUILD.bazel

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
load(
2-
"@gz//bazel/skylark:build_defs.bzl",
3-
"GZ_FEATURES",
4-
"GZ_ROOT",
5-
"GZ_VISIBILITY",
6-
"gz_export_header",
7-
"gz_include_header",
8-
)
9-
load(
10-
"@gz//bazel/lint:lint.bzl",
11-
"add_lint_tests",
12-
)
1+
load("@rules_gazebo//gazebo:headers.bzl", "gz_export_header")
2+
load("@rules_license//rules:license.bzl", "license")
133

144
package(
15-
default_applicable_licenses = [GZ_ROOT + "common:license"],
16-
features = GZ_FEATURES,
5+
default_applicable_licenses = ["//:license"],
6+
features = [
7+
"layering_check",
8+
"parse_headers",
9+
],
1710
)
1811

1912
public_headers_no_gen = glob([
@@ -29,54 +22,45 @@ sources = glob(
2922
test_sources = glob(["src/*_TEST.cc"])
3023

3124
gz_export_header(
32-
name = "include/gz/common/av/Export.hh",
25+
name = "Export",
26+
out = "include/gz/common/av/Export.hh",
3327
export_base = "GZ_COMMON_AV",
3428
lib_name = "gz-common-av",
35-
visibility = ["//visibility:private"],
36-
)
37-
38-
gz_include_header(
39-
name = "av_hh_genrule",
40-
out = "include/gz/common/av.hh",
41-
hdrs = public_headers_no_gen + [
42-
"include/gz/common/av/Export.hh",
43-
],
4429
)
4530

4631
public_headers = public_headers_no_gen + [
4732
"include/gz/common/av/Export.hh",
48-
"include/gz/common/av.hh",
4933
]
5034

51-
cc_library(
52-
name = "av",
53-
srcs = sources,
54-
hdrs = public_headers,
55-
includes = ["include"],
56-
visibility = GZ_VISIBILITY,
57-
deps = [
58-
GZ_ROOT + "common",
59-
GZ_ROOT + "utils",
60-
"@ffmpeg//:libavcodec",
61-
"@ffmpeg//:libavformat",
62-
"@ffmpeg//:libavutil",
63-
"@ffmpeg//:libswscale",
64-
],
65-
)
66-
67-
[cc_test(
68-
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
69-
srcs = [src],
70-
data = [GZ_ROOT + "common/test:data"],
71-
env = {
72-
"GZ_BAZEL": "1",
73-
"GZ_BAZEL_PATH": "common",
74-
},
75-
deps = [
76-
":av",
77-
GZ_ROOT + "common/testing",
78-
"@gtest//:gtest_main",
79-
],
80-
) for src in test_sources]
81-
82-
add_lint_tests()
35+
# cc_library(
36+
# name = "av",
37+
# srcs = sources,
38+
# hdrs = public_headers,
39+
# includes = ["include"],
40+
# visibility = ["//visibility:public"],
41+
# deps = [
42+
# "//:gz-common",
43+
# "@gz-utils//:ImplPtr",
44+
# "@gz-utils//:ExtraTestMacros",
45+
# "@ffmpeg//:libavcodec",
46+
# "@ffmpeg//:libavformat",
47+
# "@ffmpeg//:libavutil",
48+
# "@ffmpeg//:libswscale",
49+
# ],
50+
# )
51+
#
52+
# [cc_test(
53+
# name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
54+
# srcs = [src],
55+
# data = ["//test:data"],
56+
# env = {
57+
# "GZ_BAZEL": "1",
58+
# },
59+
# deps = [
60+
# ":av",
61+
# "//testing:testing",
62+
# "@googletest//:gtest",
63+
# "@googletest//:gtest_main",
64+
#
65+
# ],
66+
# ) for src in test_sources]

events/BUILD.bazel

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
load(
2-
"@gz//bazel/skylark:build_defs.bzl",
3-
"GZ_FEATURES",
4-
"GZ_ROOT",
5-
"GZ_VISIBILITY",
6-
"gz_export_header",
7-
"gz_include_header",
8-
)
9-
load(
10-
"@gz//bazel/lint:lint.bzl",
11-
"add_lint_tests",
12-
)
1+
load("@rules_gazebo//gazebo:headers.bzl", "gz_export_header")
2+
load("@rules_license//rules:license.bzl", "license")
133

144
package(
15-
default_applicable_licenses = [GZ_ROOT + "common:license"],
16-
features = GZ_FEATURES,
5+
default_applicable_licenses = ["//:license"],
6+
features = [
7+
"layering_check",
8+
"parse_headers",
9+
],
1710
)
1811

1912
public_headers_no_gen = glob([
@@ -22,41 +15,34 @@ public_headers_no_gen = glob([
2215
])
2316

2417
sources = glob(
25-
["src/*.cc"],
18+
include = ["src/*.cc"],
2619
exclude = ["src/*_TEST.cc"],
2720
)
2821

29-
test_sources = glob(["src/*_TEST.cc"])
22+
test_sources = glob(
23+
include = ["src/*_TEST.cc"],
24+
)
3025

3126
gz_export_header(
32-
name = "include/gz/common/events/Export.hh",
27+
name = "Export",
28+
out = "include/gz/common/events/Export.hh",
3329
export_base = "GZ_COMMON_EVENTS",
3430
lib_name = "gz-common-events",
35-
visibility = ["//visibility:private"],
36-
)
37-
38-
gz_include_header(
39-
name = "events_hh_genrule",
40-
out = "include/gz/common/events.hh",
41-
hdrs = public_headers_no_gen + [
42-
"include/gz/common/events/Export.hh",
43-
],
4431
)
4532

4633
public_headers = public_headers_no_gen + [
4734
"include/gz/common/events/Export.hh",
48-
"include/gz/common/events.hh",
4935
]
5036

5137
cc_library(
5238
name = "events",
5339
srcs = sources,
5440
hdrs = public_headers,
5541
includes = ["include"],
56-
visibility = GZ_VISIBILITY,
42+
visibility = ["//visibility:public"],
5743
deps = [
58-
GZ_ROOT + "common",
59-
GZ_ROOT + "utils",
44+
"//:gz-common",
45+
"@gz-utils//:ImplPtr",
6046
],
6147
)
6248

@@ -65,9 +51,8 @@ cc_library(
6551
srcs = [src],
6652
deps = [
6753
":events",
68-
GZ_ROOT + "common/testing",
69-
"@gtest//:gtest_main",
54+
"//testing:testing",
55+
"@googletest//:gtest_main",
56+
"@googletest//:gtest",
7057
],
7158
) for src in test_sources]
72-
73-
add_lint_tests()

0 commit comments

Comments
 (0)