Skip to content

Commit

Permalink
Playing with bzlmod
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
  • Loading branch information
mjcarroll committed Apr 23, 2024
1 parent 2f1e049 commit 727382c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://github.com/bazelbuild/bazelisk
USE_BAZEL_VERSION=latest
12 changes: 12 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
common --enable_bzlmod
common --lockfile_mode=off

# Add C++17 compiler flags.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

build --force_pic
build --strip=never
build --strict_system_includes
build --fission=dbg
build --features=per_object_debug_info
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build_*

# Python generaated files
*.pyc

# Bazel generated files
bazel-*

62 changes: 37 additions & 25 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@rules_gz//gz:headers.bzl", "gz_configure_header", "gz_export_header", "gz_include_header")
load("@rules_license//rules:license.bzl", "license")

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
default_applicable_licenses = [":license"],
)

licenses(["notice"]) # Apache-2.0
license(
name = "license",
package_name = "gz-math",
)

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

gz_configure_header(
name = "config",
Expand Down Expand Up @@ -49,11 +44,11 @@ sources = glob(
)

gz_include_header(
name = "mathhh_genrule",
name = "math_hh_genrule",
out = "include/gz/math.hh",
hdrs = public_headers_no_gen + [
"include/gz/math/config.hh",
"include/gz/math/Export.hh",
"include/gz/math/config.hh",
],
)

Expand All @@ -64,15 +59,18 @@ public_headers = public_headers_no_gen + [
]

cc_library(
name = "math",
name = "gz-math",
srcs = sources + private_headers,
hdrs = public_headers,
copts = ["-fexceptions"],
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
GZ_ROOT + "utils",
"@gz-utils",
],
)

# Tests
test_sources = glob(
[
"src/*_TEST.cc",
Expand All @@ -84,10 +82,24 @@ test_sources = glob(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
deps = [
":math",
"@gtest",
"@gtest//:gtest_main",
":gz-math",
"@googletest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
# Bazel linting
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-math",
repo_name = "org_gazebosim_gz-math",
)

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 = "eigen", version = "3.4.0")

# Gazebo dependencies
bazel_dep(name = "rules_gz")
bazel_dep(name = "gz-utils")
Empty file added WORKSPACE.bazel
Empty file.
36 changes: 22 additions & 14 deletions eigen3/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
load("@rules_gz//gz:headers.bzl", "gz_include_header")
load("@rules_license//rules:license.bzl", "license")

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

license(
name = "license",
package_name = "gz-math-eigen3",
)

public_headers = glob([
"include/gz/math/eigen3/*.hh",
])

gz_include_header(
name = "eigen3_hh_genrule",
out = "include/gz/math/eigen3.hh",
hdrs = public_headers,
)

cc_library(
name = "eigen3",
srcs = public_headers,
hdrs = public_headers,
hdrs = public_headers + [
"include/gz/math/eigen3.hh",
],
includes = ["include"],
visibility = GZ_VISIBILITY,
deps = [
GZ_ROOT + "math",
"@eigen3",
"//:gz-math",
"@eigen",
],
)

Expand All @@ -35,7 +44,6 @@ test_sources = glob(
srcs = [src],
deps = [
":eigen3",
"@gtest",
"@gtest//:gtest_main",
"@googletest//:gtest_main",
],
) for src in test_sources]
23 changes: 0 additions & 23 deletions examples/BUILD.bazel

This file was deleted.

13 changes: 0 additions & 13 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_VISIBILITY",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

# Currently test directory only applies to CMake builds

add_lint_tests()

0 comments on commit 727382c

Please sign in to comment.