diff --git a/.bazeliskrc b/.bazeliskrc new file mode 100644 index 000000000..69d616437 --- /dev/null +++ b/.bazeliskrc @@ -0,0 +1,2 @@ +# See https://github.com/bazelbuild/bazelisk +USE_BAZEL_VERSION=latest diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..f2d06137d --- /dev/null +++ b/.bazelrc @@ -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 diff --git a/.gitignore b/.gitignore index 5eca50293..400bd5c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ build_* # Python generaated files *.pyc + +# Bazel generated files +bazel-* + diff --git a/BUILD.bazel b/BUILD.bazel index b89cd10a1..fe8dd4066 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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", @@ -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", ], ) @@ -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", @@ -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", +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..220b7418c --- /dev/null +++ b/MODULE.bazel @@ -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") diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/eigen3/BUILD.bazel b/eigen3/BUILD.bazel index 2b3ba9537..d258fdfce 100644 --- a/eigen3/BUILD.bazel +++ b/eigen3/BUILD.bazel @@ -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", ], ) @@ -35,7 +44,6 @@ test_sources = glob( srcs = [src], deps = [ ":eigen3", - "@gtest", - "@gtest//:gtest_main", + "@googletest//:gtest_main", ], ) for src in test_sources] diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel deleted file mode 100644 index c3902e6a3..000000000 --- a/examples/BUILD.bazel +++ /dev/null @@ -1,23 +0,0 @@ -load( - "@gz//bazel/skylark:build_defs.bzl", - "GZ_ROOT", - "GZ_VISIBILITY", -) -load( - "@gz//bazel/lint:lint.bzl", - "add_lint_tests", -) - -sources = glob( - ["*.cc"], -) - -[cc_binary( - name = src.replace(".cc", ""), - srcs = [src], - deps = [ - GZ_ROOT + "math", - ], -) for src in sources] - -add_lint_tests() diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 9000f4abc..e69de29bb 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -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()