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 Nov 4, 2024
1 parent bf36eb7 commit e66b689
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 189 deletions.
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
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.3.1
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-*
218 changes: 102 additions & 116 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
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_gazebo//gazebo:headers.bzl", "gz_configure_header", "gz_export_header")
load("@rules_license//rules:license.bzl", "license")

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

license(
name = "license",
package_name = "sdformat",
)

licenses(["notice"])

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

gz_export_header(
name = "Export",
out = "include/sdf/Export.hh",
export_base = "GZ_SDFORMAT",
lib_name = "sdformat",
)

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

gz_py_binary(
py_binary(
name = "embed_sdf",
srcs = ["sdf/embedSdf.py"],
main = "sdf/embedSdf.py",
Expand All @@ -43,49 +49,12 @@ genrule(
"sdf/**/*.convert",
]),
outs = ["EmbeddedSdf.cc"],
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdformat/sdf/ --input-files $(SRCS)", # noqa
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdf/ --input-files $(SRCS)", # noqa
tools = [":embed_sdf"],
)

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

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

gz_include_header(
name = "sdformat_hh_genrule",
out = "include/sdformat.hh",
hdrs = public_headers_no_gen + [
"include/sdf/config.hh",
"include/sdf/Export.hh",
],
)

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

cc_library(
name = "urdf",
name = "urdf_parser",
srcs = [
"src/urdf/urdf_parser/joint.cpp",
"src/urdf/urdf_parser/link.cpp",
Expand All @@ -108,93 +77,110 @@ cc_library(

cc_library(
name = "sdformat",
srcs = sources + private_headers + ["EmbeddedSdf.cc"],
hdrs = public_headers,
srcs = glob(
include = [
"src/*.cc",
"src/*.hh",
"src/bazel/*.cc",
],
exclude = [
"src/*_TEST.cc",
],
) + ["EmbeddedSdf.cc"],
hdrs = glob(
include = [
"include/sdf/*.hh",
],
exclude = [
],
),
defines = [
"CMAKE_INSTALL_RELATIVE_DATAROOTDIR=\\\"\\\"",
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
includes = [
"include",
"src",
],
data = [
"sdf"
],
deps = [
":urdf",
GZ_ROOT + "math",
GZ_ROOT + "utils",
"@tinyxml2",
":Config",
":Export",
":urdf_parser",
"@gz-math//:Angle",
"@gz-math//:Box",
"@gz-math//:Capsule",
"@gz-math//:Color",
"@gz-math//:Cone",
"@gz-math//:Cylinder",
"@gz-math//:Ellipsoid",
"@gz-math//:Graph",
"@gz-math//:Inertial",
"@gz-math//:Pose3",
"@gz-math//:SemanticVersion",
"@gz-math//:Sphere",
"@gz-math//:SphericalCoordinates",
"@gz-math//:Temperature",
"@gz-math//:Vector2",
"@gz-utils//:Environment",
"@gz-utils//:ImplPtr",
],
)

cc_library(
name = "sdformat_internal",
cc_test(
name = "Actor_TEST",
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",
"src/Actor_TEST.cc",
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "sdformat",
},
deps = [
":sdformat",
GZ_ROOT + "sdformat/test:test_utils",
"@gtest",
"@gtest//:gtest_main",
"@googletest//: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",
cc_test(
name = "Console_TEST",
srcs = [
"src/Console_TEST.cc",
],
deps = [
":sdformat",
"@googletest//:gtest_main",
],
package = "sdformat",
visibility = [GZ_ROOT + "tools:__pkg__"],
)

cc_binary(
name = "libgz-sdformat.so",
srcs = [":sdformat_internal"],
linkshared = True,
visibility = [GZ_ROOT + "tools:__pkg__"],
cc_test(
name = "Element_TEST",
srcs = [
"src/Element_TEST.cc",
],
deps = [
":sdformat",
"//test:test_utils",
"@googletest//:gtest_main",
],
)

exports_files(["sdf"])
# Bazel linting
buildifier(
name = "buildifier.fix",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
)

add_lint_tests()
buildifier_test(
name = "buildifier.test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
no_sandbox = True,
workspace = "//:MODULE.bazel",
)
27 changes: 27 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## 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")
bazel_dep(name = "tinyxml2", version = "10.0.0")

# Gazebo Dependencies
bazel_dep(name = "rules_gazebo", version = "0.0.2")
bazel_dep(name = "gz-utils")
bazel_dep(name = "gz-math")

archive_override(
module_name = "gz-utils",
strip_prefix = "gz-utils-gz-utils3",
urls = ["https://github.com/gazebosim/gz-utils/archive/refs/heads/gz-utils3.tar.gz"],
)

archive_override(
module_name = "gz-math",
strip_prefix = "gz-math-gz-math8",
urls = ["https://github.com/gazebosim/gz-math/archive/refs/heads/gz-math8.tar.gz"],
)
5 changes: 5 additions & 0 deletions src/Actor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "sdf/Actor.hh"
#include "sdf/Plugin.hh"

#include <filesystem>

/////////////////////////////////////////////////
sdf::Animation CreateDummyAnimation()
{
Expand Down Expand Up @@ -509,6 +511,9 @@ TEST(DOMActor, ToElement)
{
sdf::Actor actor;

// Output the current working directory
std::cout << std::filesystem::current_path() << std::endl;

actor.SetName("my-actor");
actor.SetRawPose(gz::math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3));
actor.SetSkinFilename("my-skinfilename");
Expand Down
4 changes: 4 additions & 0 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,13 @@ const std::string &SDF::EmbeddedSpec(
const std::string &SDF::EmbeddedSpec(
sdf::Errors &_errors, const std::string &_filename)
{

try
{
const std::string pathname = SDF::Version() + "/" + _filename;

std::cout << "Reading: " << pathname << std::endl;

return GetEmbeddedSdf().at(pathname);
}
catch(const std::out_of_range &)
Expand Down
2 changes: 1 addition & 1 deletion src/parser_urdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <urdf_parser/urdf_parser.h>

#include "sdf/Error.hh"
#include "sdf/sdf.hh"
#include "sdf/Types.hh"
#include "sdf/Frame.hh"

#include "XmlUtils.hh"
#include "SDFExtension.hh"
Expand Down
Loading

0 comments on commit e66b689

Please sign in to comment.