Skip to content

Commit

Permalink
Initial bzlmod skeleton
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Sep 13, 2024
1 parent c2c4f91 commit 9700a6e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 260 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
build --cxxopt='-std=c++20'
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build_*
*.*.sw?
.vscode
__pycache__
bazel-*
211 changes: 23 additions & 188 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,200 +1,35 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"add_lint_tests",
"gz_configure_file",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
"gz_py_binary",
)
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@rules_license//rules:license.bzl", "license")

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"])

exports_files(["LICENSE"])

gz_configure_header(
name = "config",
src = "include/sdf/config.hh.in",
cmakelists = ["CMakeLists.txt"],
defines = {
"CMAKE_INSTALL_FULL_DATAROOTDIR": "unused",
},
package = "sdformat",
default_applicable_licenses = [":license"],
)

gz_py_binary(
name = "embed_sdf",
srcs = ["sdf/embedSdf.py"],
main = "sdf/embedSdf.py",
license(
name = "license",
package_name = "sdformat",
)

genrule(
name = "embed_sdf_genrule",
srcs = glob([
"sdf/**/*.sdf",
"sdf/**/*.convert",
]),
outs = ["EmbeddedSdf.cc"],
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdformat/sdf/ --input-files $(SRCS)", # noqa
tools = [":embed_sdf"],
)
licenses(["notice"])

public_headers_no_gen = glob([
"include/sdf/*.h",
"include/sdf/*.hh",
exports_files([
"LICENSE",
"MODULE.bazel",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
"src/gz.cc",
],
)

gz_export_header(
name = "include/sdf/Export.hh",
export_base = "GZ_SDFORMAT",
lib_name = "sdf",
visibility = ["//visibility:private"],
# Bazel linting
buildifier(
name = "buildifier.fix",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
)

gz_include_header(
name = "sdformat_hh_genrule",
out = "include/sdformat.hh",
hdrs = public_headers_no_gen + [
"include/sdf/config.hh",
"include/sdf/Export.hh",
],
buildifier_test(
name = "buildifier.test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
no_sandbox = True,
workspace = "//:MODULE.bazel",
)

public_headers = public_headers_no_gen + [
"include/sdf/Export.hh",
"include/sdf/config.hh",
"include/sdformat.hh",
]

cc_library(
name = "urdf",
srcs = [
"src/urdf/urdf_parser/joint.cpp",
"src/urdf/urdf_parser/link.cpp",
"src/urdf/urdf_parser/model.cpp",
"src/urdf/urdf_parser/pose.cpp",
"src/urdf/urdf_parser/twist.cpp",
"src/urdf/urdf_parser/urdf_model_state.cpp",
"src/urdf/urdf_parser/urdf_sensor.cpp",
"src/urdf/urdf_parser/world.cpp",
],
hdrs = glob(
["src/urdf/**/*.h"],
),
copts = ["-Wno-unknown-pragmas"],
includes = ["src/urdf"],
deps = [
"@tinyxml2",
],
)

cc_library(
name = "sdformat",
srcs = sources + private_headers + ["EmbeddedSdf.cc"],
hdrs = public_headers,
defines = [
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
includes = [
"include",
"src",
],
deps = [
":urdf",
GZ_ROOT + "math",
GZ_ROOT + "utils",
"@tinyxml2",
],
)

cc_library(
name = "sdformat_internal",
srcs = [
"src/gz.cc",
"src/gz.hh",
],
visibility = ["//visibility:private"],
deps = [":sdformat"],
)

test_sources = glob(
["src/*_TEST.cc"],
exclude = ["src/gz_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
data = [
"sdf",
GZ_ROOT + "sdformat/test:integration",
GZ_ROOT + "sdformat/test:sdf",
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "sdformat",
},
deps = [
":sdformat",
GZ_ROOT + "sdformat/test:test_utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

gz_configure_file(
name = "sdformat.rb",
src = "src/cmd/cmdsdformat.rb.in",
out = "cmdsdformat.rb",
cmakelists = ["CMakeLists.txt"],
defines = [
"library_location=libgz-sdformat.so",
],
package = "sdformat",
visibility = [GZ_ROOT + "tools:__pkg__"],
)

gz_configure_file(
name = "sdformat_yaml",
src = "conf/sdformat.yaml.in",
out = "sdformat.yaml",
cmakelists = ["CMakeLists.txt"],
defines = [
"gz_library_path=gz/sdformat/cmdsdformat.rb",
],
package = "sdformat",
visibility = [GZ_ROOT + "tools:__pkg__"],
)

cc_binary(
name = "libgz-sdformat.so",
srcs = [":sdformat_internal"],
linkshared = True,
visibility = [GZ_ROOT + "tools:__pkg__"],
deps = [
":sdformat",
],
)

exports_files(["sdf"])

add_lint_tests()
29 changes: 29 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## MODULE.bazel
module(
name = "sdformat",
repo_name = "org_gazebosim_sdformat",
)

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")

# Gazebo Dependencies
bazel_dep(name = "rules_gz")
bazel_dep(name = "gz-utils")
bazel_dep(name = "gz-math")

local_path_override(
module_name = "rules_gz",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/rules_gz",
)

local_path_override(
module_name = "gz-utils",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/gz-utils",
)

local_path_override(
module_name = "gz-math",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/gz-math",
)
72 changes: 0 additions & 72 deletions test/BUILD.bazel

This file was deleted.

0 comments on commit 9700a6e

Please sign in to comment.