Skip to content

Commit

Permalink
Bazel support for garden
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed Feb 10, 2023
1 parent d2a48c1 commit d1bbce4
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 0 deletions.
4 changes: 4 additions & 0 deletions example/bazel.repos
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ repositories:
type: git
url: https://github.com/gazebosim/sdformat
version: mjcarroll/garden_bazel
transport:
type: git
url: https://github.com/gazebosim/gz-transport
version: mjcarroll/garden_bazel
utils:
type: git
url: https://github.com/gazebosim/gz-utils
Expand Down
6 changes: 6 additions & 0 deletions workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ load("@gz//bazel/workspace/gts:repository.bzl", "gts_repository") # noqa
load("@gz//bazel/workspace/pycodestyle:repository.bzl", "pycodestyle_repository") # noqa
load("@gz//bazel/workspace/rules_proto:repository.bzl", "rules_proto_repository") # noqa
load("@gz//bazel/workspace/rules_python:repository.bzl", "rules_python_repository") # noqa
load("@gz//bazel/workspace/sqlite3:repository.bzl", "sqlite3_repository") # noqa
load("@gz//bazel/workspace/tinyxml2:repository.bzl", "tinyxml2_repository") # noqa
load("@gz//bazel/workspace/uuid:repository.bzl", "uuid_repository") # noqa
load("@gz//bazel/workspace/zmq:repository.bzl", "zmq_repository") # noqa

def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
"""Declares workspace repositories for all externals needed by drake (other
Expand Down Expand Up @@ -56,10 +58,14 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
rules_proto_repository(name = "rules_proto", mirrors = mirrors)
if "rules_python" not in excludes:
rules_python_repository(name = "rules_python", mirrors = mirrors)
if "sqlite3" not in excludes:
sqlite3_repository(name = "sqlite3")
if "tinyxml2" not in excludes:
tinyxml2_repository(name = "tinyxml2")
if "uuid" not in excludes:
uuid_repository(name = "uuid")
if "zmq" not in excludes:
zmq_repository(name = "zmq")

def add_default_toolchains(excludes = []):
"""Register toolchains for each language (e.g., "py") not explicitly
Expand Down
Empty file added workspace/sqlite3/BUILD.bazel
Empty file.
17 changes: 17 additions & 0 deletions workspace/sqlite3/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- python -*-

load(":vars.bzl", "LIBDIR")

cc_library(
name = "sqlite3",
hdrs = glob([
"include/sqlite3.h",
]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lsqlite3",
],
visibility = ["//visibility:public"],
)
30 changes: 30 additions & 0 deletions workspace/sqlite3/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@gz//bazel/workspace:os.bzl", "determine_os")

def _impl(repository_ctx):
os_result = determine_os(repository_ctx)

if os_result.error != None:
fail(os_result.error)

if os_result.is_ubuntu:
libdir = "/usr/lib/x86_64-linux-gnu"
repository_ctx.symlink("/usr/include/sqlite3.h", "include/sqlite3.h")

# Declare the libdir
repository_ctx.file(
"vars.bzl",
content = "LIBDIR = \"{}\"\n".format(libdir),
executable = False,
)

# Add the BUILD file.
repository_ctx.symlink(
Label("@gz//bazel/workspace/sqlite3:package.BUILD.bazel"),
"BUILD.bazel",
)

sqlite3_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
3 changes: 3 additions & 0 deletions workspace/tinyxml2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load("@gz//bazel/lint:lint.bzl", "add_lint_tests")

add_lint_tests()
3 changes: 3 additions & 0 deletions workspace/zmq/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load("@gz//bazel/lint:lint.bzl", "add_lint_tests")

add_lint_tests()
17 changes: 17 additions & 0 deletions workspace/zmq/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- python -*-

load(":vars.bzl", "LIBDIR")

cc_library(
name = "zmq",
hdrs = glob([
"include/zmq.h",
]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lzmq",
],
visibility = ["//visibility:public"],
)
31 changes: 31 additions & 0 deletions workspace/zmq/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@gz//bazel/workspace:os.bzl", "determine_os")

def _impl(repository_ctx):
os_result = determine_os(repository_ctx)

if os_result.error != None:
fail(os_result.error)

if os_result.is_ubuntu:
libdir = "/usr/lib/x86_64-linux-gnu"
repository_ctx.symlink("/usr/include/zmq.h", "include/zmq.h")
repository_ctx.symlink("/usr/include/zmq_utils.h", "include/zmq_utils.h") # noqa

# Declare the libdir
repository_ctx.file(
"vars.bzl",
content = "LIBDIR = \"{}\"\n".format(libdir),
executable = False,
)

# Add the BUILD file.
repository_ctx.symlink(
Label("@gz//bazel/workspace/zmq:package.BUILD.bazel"),
"BUILD.bazel",
)

zmq_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)

0 comments on commit d1bbce4

Please sign in to comment.