Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at building gz-utils with bzlmod
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
mjcarroll committed Sep 30, 2024
1 parent a70e742 commit 381536e
Showing 9 changed files with 227 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
common --enable_bzlmod

common --lockfile_mode=off
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.3.1
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,3 +5,9 @@ build_*
# OS generated files
.DS_Store
*.swp

# Bazel generated files
bazel-bin/
bazel-out/
bazel-testlogs/
bazel-*
164 changes: 101 additions & 63 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,70 +1,105 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@rules_gz//gz:headers.bzl", "gz_configure_header", "gz_export_header")
load("@rules_license//rules:license.bzl", "license")

package(
default_applicable_licenses = [GZ_ROOT + "utils:license"],
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
default_applicable_licenses = [":license"],
default_visibility = ["__subpackages__"],
)

license(
name = "license",
package_name = "gz-utils",
)

licenses(["notice"])

exports_files(["LICENSE"])
exports_files([
"LICENSE",
"MODULE.bazel",
])

gz_configure_header(
name = "config",
name = "genconfig",
src = "include/gz/utils/config.hh.in",
cmakelists = ["CMakeLists.txt"],
package = "utils",
)

gz_export_header(
name = "include/gz/utils/Export.hh",
name = "export",
out = "include/gz/utils/Export.hh",
export_base = "GZ_UTILS",
lib_name = "gz-utils",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/utils/*.hh",
"include/gz/utils/detail/*.hh",
"include/gz/utils/detail/*.h",
])
cc_library(
name = "config",
hdrs = ["include/gz/utils/config.hh"],
includes = ["include"],
)

gz_include_header(
name = "utilshh_genrule",
out = "include/gz/utils.hh",
hdrs = public_headers_no_gen + [
"include/gz/utils/Export.hh",
"include/gz/utils/config.hh",
cc_library(
name = "environment",
srcs = ["src/Environment.cc"],
hdrs = ["include/gz/utils/Environment.hh"],
includes = ["include"],
deps = [
":config",
":export",
],
)

public_headers = public_headers_no_gen + [
"include/gz/utils/config.hh",
"include/gz/utils/Export.hh",
"include/gz/utils.hh",
]
cc_library(
name = "ImplPtr",
hdrs = [
"include/gz/utils/ImplPtr.hh",
"include/gz/utils/detail/DefaultOps.hh",
"include/gz/utils/detail/ImplPtr.hh",
],
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
":SuppressWarning",
":export",
],
)

cc_library(
name = "utils",
srcs = ["src/Environment.cc"],
hdrs = public_headers,
copts = ["-fexceptions"],
name = "NeverDestroyed",
hdrs = ["include/gz/utils/NeverDestroyed.hh"],
includes = ["include"],
visibility = ["//visibility:public"],
)

cc_library(
name = "SuppressWarning",
hdrs = [
"include/gz/utils/SuppressWarning.hh",
"include/gz/utils/detail/SuppressWarning.hh",
],
includes = ["include"],
visibility = ["//visibility:public"],
)

cc_library(
name = "Subprocess",
hdrs = [
"include/gz/utils/Subprocess.hh",
"include/gz/utils/detail/subprocess.h",
],
includes = ["include"],
visibility = ["//visibility:public"],
)

cc_library(
name = "gz-utils",
visibility = ["//visibility:public"],
deps = [
":ImplPtr",
":NeverDestroyed",
":Subprocess",
":SuppressWarning",
":environment",
],
)

# Tests
@@ -77,7 +112,7 @@ cc_library(
"test/integration/implptr/implptr_test_classes.hh",
],
includes = ["test/integration/implptr"],
deps = [":utils"],
deps = [":ImplPtr"],
)

cc_test(
@@ -86,48 +121,51 @@ cc_test(
srcs = ["test/integration/implptr/ImplPtr_TEST.cc"],
deps = [
":implptr_test_classes",
"@gtest",
"@gtest//:gtest_main",
"@googletest//:gtest_main",
],
)

cc_test(
name = "Environment_TEST",
srcs = ["src/Environment_TEST.cc"],
deps = [
":utils",
"@gtest",
"@gtest//:gtest_main",
":environment",
"@googletest//:gtest_main",
],
)

cc_test(
name = "NeverDestroyed_TEST",
srcs = ["src/NeverDestroyed_TEST.cc"],
copts = ["-fexceptions"],
cc_binary(
name = "subprocess_main",
srcs = ["test/integration/subprocess/subprocess_main.cc"],
deps = [
":utils",
"@gtest",
"@gtest//:gtest_main",
":environment",
"//cli",
],
)

cc_binary(
name = "subprocess_main",
srcs = ["test/integration/subprocess/subprocess_main.cc"],
deps = [
GZ_ROOT + "utils/cli",
]
)

cc_test(
name = "subprocess_TEST",
srcs = ["test/integration/subprocess_TEST.cc"],
local_defines = ['SUBPROCESS_EXECUTABLE_PATH=\\"subprocess_main\\"'],
deps = [
":utils",
":gz-utils",
":subprocess_main",
"@gtest",
"@gtest//:gtest_main",
"@googletest//:gtest_main",
],
local_defines = ['SUBPROCESS_EXECUTABLE_PATH=\\"utils/subprocess_main\\"'],
)

buildifier(
name = "buildifier.fix",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
)

buildifier_test(
name = "buildifier.test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
no_sandbox = True,
workspace = "//:MODULE.bazel",
)
15 changes: 15 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## MODULE.bazel
module(
name = "gz-utils",
repo_name = "org_gazebosim_gz-utils",
)

bazel_dep(name = "buildifier_prebuilt", version = "6.1.2")
bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "rules_license", version = "0.0.8")
bazel_dep(name = "spdlog", version = "1.14.1")
bazel_dep(name = "rules_gz")
local_path_override(
module_name = "rules_gz",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/rules_gz",
)
Empty file added WORKSPACE
Empty file.
49 changes: 30 additions & 19 deletions cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_ROOT",
"GZ_VISIBILITY",
)
load("@rules_license//rules:license.bzl", "license")

package(
default_applicable_licenses = [GZ_ROOT + "utils/cli:license"],
default_applicable_licenses = ["//:license"],
)

license(
name = "license",
package_name = "gz-utils-cli",
)

public_headers = [
"include/gz/utils/cli/GzFormatter.hpp",
] + glob([
"include/external-cli/gz/utils/cli/*.hpp",
])
cc_library(
name = "cli11",
hdrs = glob([
"include/vendored-cli/gz/utils/cli/*.hpp",
]),
includes = ["include/vendored-cli"],
)

cc_library(
name = "gz_formatter",
hdrs = [
"include/gz/utils/cli/GzFormatter.hpp",
],
includes = ["include"],
deps = [
"//:export",
],
)

cc_library(
name = "cli",
hdrs = public_headers,
copts = ["-fexceptions"],
includes = [
"include",
"include/external-cli",
visibility = ["//visibility:public"],
deps = [
":cli11",
":gz_formatter",
],
visibility = GZ_VISIBILITY,
)

cc_test(
name = "cli_TEST",
srcs = ["src/cli_TEST.cc"],
deps = [
GZ_ROOT + "utils:utils",
"@cli11"
":cli",
"@googletest//:gtest_main",
],
)
14 changes: 7 additions & 7 deletions include/gz/utils/config.hh.in
Original file line number Diff line number Diff line change
@@ -21,15 +21,15 @@
#define GZ_UTILS_CONFIG_HH_

/* Version number */
#define GZ_UTILS_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
#define GZ_UTILS_MINOR_VERSION ${PROJECT_VERSION_MINOR}
#define GZ_UTILS_PATCH_VERSION ${PROJECT_VERSION_PATCH}
#define GZ_UTILS_MAJOR_VERSION @PROJECT_VERSION_MAJOR@
#define GZ_UTILS_MINOR_VERSION @PROJECT_VERSION_MINOR@
#define GZ_UTILS_PATCH_VERSION @PROJECT_VERSION_PATCH@

#define GZ_UTILS_VERSION "${PROJECT_VERSION}"
#define GZ_UTILS_VERSION_FULL "${PROJECT_VERSION_FULL}"
#define GZ_UTILS_VERSION "@PROJECT_VERSION@"
#define GZ_UTILS_VERSION_FULL "@PROJECT_VERSION_FULL@"

#define GZ_UTILS_VERSION_NAMESPACE v${PROJECT_VERSION_MAJOR}
#define GZ_UTILS_VERSION_NAMESPACE v@PROJECT_VERSION_MAJOR@

#define GZ_UTILS_VERSION_HEADER "Gazebo Utils, version ${PROJECT_VERSION_FULL}\nCopyright (C) 2020 Open Source Robotics Foundation.\nReleased under the Apache 2.0 License.\n\n"
#define GZ_UTILS_VERSION_HEADER "Gazebo Utils, version @PROJECT_VERSION_FULL@\nCopyright (C) 2020 Open Source Robotics Foundation.\nReleased under the Apache 2.0 License.\n\n"

#endif
64 changes: 64 additions & 0 deletions log/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
load("@rules_license//rules:license.bzl", "license")
load("@rules_gz//gz:headers.bzl", "gz_export_header")

package(
default_applicable_licenses = ["//:license"],
)

license(
name = "license",
package_name = "gz-utils-log",
)

gz_export_header(
name = "export",
out = "include/gz/utils/log/Export.hh",
export_base = "GZ_UTILS_LOG",
lib_name = "gz-utils-log",
)

cc_library(
name = "split_sink",
srcs = [
"src/SplitSink.cc",
],
hdrs = [
"include/gz/utils/log/SplitSink.hh",
],
includes = ["include"],
deps = [
":export",
"//:ImplPtr",
"//:config",
"@spdlog",
],
)

cc_library(
name = "logger",
srcs = [
"src/Logger.cc",
],
hdrs = [
"include/gz/utils/log/Logger.hh",
],
includes = ["include"],
deps = [":split_sink"],
)

cc_library(
name = "log",
deps = [
":logger",
":split_sink",
],
)

cc_test(
name = "SplitSink_TEST",
srcs = ["src/SplitSink_TEST.cc"],
deps = [
":log",
"@googletest//:gtest_main",
],
)

0 comments on commit 381536e

Please sign in to comment.