Skip to content

Commit

Permalink
bazel: updates for garden (#513)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Jan 31, 2024
1 parent 8e1aca6 commit 1016539
Show file tree
Hide file tree
Showing 9 changed files with 537 additions and 18 deletions.
130 changes: 130 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0

exports_files(["LICENSE"])

gz_configure_header(
name = "physics_config_hh",
src = "include/gz/physics/config.hh.in",
cmakelists = ["CMakeLists.txt"],
defines = {
# These definitions are unused,
# this is merely to suppress generator warnings
"GZ_PHYSICS_ENGINE_INSTALL_DIR": "unused",
},
package = "physics",
)

gz_export_header(
name = "include/gz/physics/Export.hh",
export_base = "GZ_PHYSICS",
lib_name = "gz-physics",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/physics/*.hh",
"include/gz/physics/detail/*.hh",
])

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

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

public_headers = public_headers_no_gen + [
"include/gz/physics/config.hh",
"include/gz/physics/Export.hh",
"include/gz/physics.hh",
]

cc_library(
name = "physics",
srcs = sources,
hdrs = public_headers,
defines = [
'GZ_PHYSICS_ENGINE_RELATIVE_INSTALL_DIR=\\"unused\\"',
"GZ_PHYSICS_BAZEL_BUILD=true",
],
includes = ["include"],
deps = [
GZ_ROOT + "math",
GZ_ROOT + "math/eigen3",
GZ_ROOT + "plugin:core",
GZ_ROOT + "plugin:loader",
GZ_ROOT + "utils",
],
)

cc_library(
name = "heightmap",
hdrs = [
"heightmap/include/gz/physics/heightmap/HeightmapShape.hh",
"heightmap/include/gz/physics/heightmap/detail/HeightmapShape.hh",
],
includes = ["heightmap/include"],
)

cc_library(
name = "mesh",
hdrs = [
"mesh/include/gz/physics/mesh/MeshShape.hh",
"mesh/include/gz/physics/mesh/detail/MeshShape.hh",
],
includes = ["mesh/include"],
)

cc_library(
name = "sdf",
hdrs = glob([
"sdf/include/gz/physics/sdf/*.hh",
]),
includes = ["sdf/include"],
deps = [
GZ_ROOT + "sdformat",
],
)

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

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "physics",
},
deps = [
":physics",
GZ_ROOT + "physics/test:test_headers",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]
45 changes: 45 additions & 0 deletions bullet-featherstone/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
)

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

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

cc_library(
name = "bullet-featherstone",
srcs = sources + private_headers,
includes = ["include"],
visibility = GZ_VISIBILITY,
deps = [
GZ_ROOT + "common",
GZ_ROOT + "common/graphics",
GZ_ROOT + "math/eigen3",
GZ_ROOT + "physics",
GZ_ROOT + "physics:sdf",
GZ_ROOT + "third_party/bullet3:BulletCollision",
GZ_ROOT + "third_party/bullet3:BulletDynamics",
],
)

cc_binary(
name = "libgz-physics-bullet-featherstone-plugin.so",
srcs = [
"src/plugin.cc",
],
linkshared = True,
visibility = GZ_VISIBILITY,
deps = [
":bullet-featherstone",
GZ_ROOT + "plugin:register",
],
)
55 changes: 55 additions & 0 deletions dartsim/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)

public_headers = ["include/gz/physics/dartsim/World.hh"]

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

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

cc_library(
name = "dartsim",
srcs = sources + private_headers,
hdrs = public_headers,
includes = ["include"],
visibility = GZ_VISIBILITY,
deps = [
GZ_ROOT + "common",
GZ_ROOT + "common/geospatial",
GZ_ROOT + "common/profiler",
GZ_ROOT + "math/eigen3",
GZ_ROOT + "physics",
GZ_ROOT + "physics:heightmap",
GZ_ROOT + "physics:mesh",
GZ_ROOT + "physics:sdf",
GZ_ROOT + "third_party/dart:simulation",
GZ_ROOT + "third_party/dart:collision-bullet",
GZ_ROOT + "third_party/dart:collision-ode",
],
)

cc_binary(
name = "libgz-physics-dartsim-plugin.so",
srcs = [
"src/plugin.cc",
],
linkshared = True,
visibility = GZ_VISIBILITY,
deps = [
":dartsim",
GZ_ROOT + "plugin:register",
],
)
1 change: 1 addition & 0 deletions include/gz/physics/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#define GZ_PHYSICS_VERSION "${PROJECT_VERSION}"
#define GZ_PHYSICS_VERSION_FULL "${PROJECT_VERSION_FULL}"
#define GZ_PHYSICS_VERSION_NAMESPACE v${PROJECT_VERSION_MAJOR}

#define GZ_PHYSICS_ENGINE_INSTALL_DIR _Pragma ("GCC warning \"'GZ_PHYSICS_ENGINE_INSTALL_DIR' macro is deprecated, use gz::physics::getEngineInstallDir() function instead. \"") "${GZ_PHYSICS_ENGINE_INSTALL_DIR}"

Expand Down
24 changes: 15 additions & 9 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@ namespace gz
{
namespace physics
{
inline namespace GZ_PHYSICS_VERSION_NAMESPACE {
namespace {

// We locally import the gz::common::joinPaths function
// See https://github.com/gazebosim/gz-physics/pull/507#discussion_r1186919267
// for more details

// Function imported from
// https://github.com/gazebosim/gz-common/blob/ignition-common4_4.6.2/src/FilesystemBoost.cc#L507
#ifndef WIN32
static const char preferred_separator = '/';
#ifndef _WIN32
const char preferred_separator = '/';
#else // Windows
static const char preferred_separator = '\\';
#endif
const std::string separator(const std::string &_p)
std::string separator(const std::string &_p)
{
return _p + preferred_separator;
}

#ifdef _WIN32
// Function imported from
// https://github.com/gazebosim/gz-common/blob/ignition-common4_4.6.2/src/Filesystem.cc#L227
std::string checkWindowsPath(const std::string _path)
std::string checkWindowsPath(const std::string &_path)
{
if (_path.empty())
return _path;
Expand All @@ -75,6 +76,7 @@ std::string checkWindowsPath(const std::string _path)
result, std::regex("[<>:\"|?*]"), "");
return result;
}
#endif

// Function imported from
// https://github.com/gazebosim/gz-common/blob/ignition-common4_4.6.2/src/Filesystem.cc#L256
Expand Down Expand Up @@ -142,14 +144,18 @@ std::string joinPaths(const std::string &_path1,
#endif // _WIN32
return path;
}
} // namespace

inline namespace GZ_PHYSICS_VERSION_NAMESPACE {
#ifdef GZ_PHYSICS_BAZEL_BUILD
std::string getInstallPrefix() { return "physics"; }
#endif

std::string getEngineInstallDir()
{
return gz::physics::joinPaths(
getInstallPrefix(), GZ_PHYSICS_ENGINE_RELATIVE_INSTALL_DIR);
}

}
}
}
} // namespace GZ_PHYSICS_VERSION_NAMESPACE
} // namespace physics
} // namespace gz
Loading

0 comments on commit 1016539

Please sign in to comment.