Skip to content

Commit

Permalink
Add repo and dependencies for common
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 15, 2023
1 parent 57643fc commit 8923cf4
Show file tree
Hide file tree
Showing 28 changed files with 521 additions and 9 deletions.
13 changes: 6 additions & 7 deletions .github/actions/bazel-ci-jammy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SOURCE_DEPENDENCIES="`pwd`/.github/ci/dependencies.yaml"
SOURCE_DEPENDENCIES_VERSIONED="`pwd`/.github/ci-$SYSTEM_VERSION/dependencies.yaml"

cd "$GITHUB_WORKSPACE"
mkdir -p ${GITHUB_WORKSPACE}/bazel-testlogs

# Restore cache
if [ ! -d "$BAZEL_CACHE" ]; then
Expand All @@ -29,6 +30,7 @@ chmod +x ${BAZEL}

# Import repos
mkdir -p ${WORKSPACE}/bazel

cd ${WORKSPACE}
shopt -s extglob
# Copy relevant bazel files into the build space
Expand Down Expand Up @@ -57,13 +59,10 @@ ${BAZEL} build $BAZEL_ARGS
echo ::endgroup::

echo ::group::Bazel test
${BAZEL} test $BAZEL_ARGS
EXIT_CODE=0
${BAZEL} test $BAZEL_ARGS || EXIT_CODE=$?
echo ::endgroup::

echo ::group::Bazel test
ls -la ${WORKSPACE}
ls -la ${WORKSPACE}/bazel-testlogs
ls -la ${BAZEL_CACHE}
echo ::endgroup::
cp -RL ${WORKSPACE}/bazel-testlogs/* ${GITHUB_WORKSPACE}/bazel-testlogs/

cp -RL ${WORKSPACE}/bazel-testlogs ${GITHUB_WORKSPACE}/bazel-testlogs
exit $EXIT_CODE
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
${{ github.workspace }}/bazel_cache
key: cache-bazel-${{ hashFiles('example/bazel.repos') }}
restore-keys: |
cache-bazel-${{ hashFiles('example/bazel.repos') }}
cache-bazel-
- name: Compile and test
Expand All @@ -36,6 +37,7 @@ jobs:

- name: 'Upload Test Logs'
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: bazel-testlogs
path: ${{ github.workspace }}/bazel-testlogs
Expand Down
4 changes: 4 additions & 0 deletions example/bazel.repos
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
repositories:
common:
type: git
url: https://github.com/gazebosim/gz-common
version: gz-common5
math:
type: git
url: https://github.com/gazebosim/gz-math
Expand Down
3 changes: 3 additions & 0 deletions workspace/assimp/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()
21 changes: 21 additions & 0 deletions workspace/assimp/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- python -*-

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

licenses(["notice"])

cc_library(
name = "assimp",
hdrs = glob([
"include/assimp/*.h",
"include/assimp/Compiler/*.h",
"include/assimp/*.inl",
]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lassimp",
],
visibility = ["//visibility:public"],
)
30 changes: 30 additions & 0 deletions workspace/assimp/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/assimp/", "include/assimp/")

# 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/assimp:package.BUILD.bazel"),
"BUILD.bazel",
)

assimp_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
28 changes: 26 additions & 2 deletions workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

load("@gz//bazel/workspace:mirrors.bzl", "DEFAULT_MIRRORS")
load("@gz//bazel/workspace:os.bzl", "os_repository")
load("@gz//bazel/workspace/assimp:repository.bzl", "assimp_repository") # noqa
load("@gz//bazel/workspace/bazel_skylib:repository.bzl", "bazel_skylib_repository") # noqa
load("@gz//bazel/workspace/buildifier:repository.bzl", "buildifier_repository") # noqa
load("@gz//bazel/workspace/cli11:repository.bzl", "cli11_repository") # noqa
load("@gz//bazel/workspace/eigen3:repository.bzl", "eigen3_repository") # noqa
load("@gz//bazel/workspace/ffmpeg:repository.bzl", "ffmpeg_repository") # noqa
load("@gz//bazel/workspace/freeimage:repository.bzl", "freeimage_repository") # noqa
load("@gz//bazel/workspace/gdal:repository.bzl", "gdal_repository") # noqa
load("@gz//bazel/workspace/glib:repository.bzl", "glib_repository") # noqa
load("@gz//bazel/workspace/gtest:repository.bzl", "gtest_repository") # noqa
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_python:repository.bzl", "rules_python_repository") # noqa
load("@gz//bazel/workspace/tinyxml2:repository.bzl", "tinyxml2_repository") # noqa
load("@gz//bazel/workspace/uuid:repository.bzl", "uuid_repository") # noqa

def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
"""Declares workspace repositories for all externals needed by drake (other
Expand All @@ -19,20 +27,36 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
be useful if a WORKSPACE file has already supplied its own external
of a given name.
"""
if "assimp" not in excludes:
assimp_repository(name = "assimp")
if "bazel_skylib" not in excludes:
bazel_skylib_repository(name = "bazel_skylib", mirrors = mirrors)
if "buildifier" not in excludes:
buildifier_repository(name = "buildifier", mirrors = mirrors)
if "cli11" not in excludes:
cli11_repository(name = "cli11", mirrors = mirrors)
if "gtest" not in excludes:
gtest_repository(name = "gtest", mirrors = mirrors)
if "eigen3" not in excludes:
eigen3_repository(name = "eigen3")
if "ffmpeg" not in excludes:
ffmpeg_repository(name = "ffmpeg")
if "freeimage" not in excludes:
freeimage_repository(name = "freeimage")
if "gdal" not in excludes:
gdal_repository(name = "gdal")
if "glib" not in excludes:
glib_repository(name = "glib")
if "gtest" not in excludes:
gtest_repository(name = "gtest", mirrors = mirrors)
if "gts" not in excludes:
gts_repository(name = "gts")
if "pycodestyle" not in excludes:
pycodestyle_repository(name = "pycodestyle", mirrors = mirrors)
if "rules_python" not in excludes:
rules_python_repository(name = "rules_python", mirrors = mirrors)
if "tinyxml2" not in excludes:
tinyxml2_repository(name = "tinyxml2")
if "uuid" not in excludes:
uuid_repository(name = "uuid")

def add_default_toolchains(excludes = []):
"""Register toolchains for each language (e.g., "py") not explicitly
Expand Down
3 changes: 3 additions & 0 deletions workspace/ffmpeg/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()
84 changes: 84 additions & 0 deletions workspace/ffmpeg/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- python -*-

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

licenses(["restricted"]) # LGPL-2.0+

package(default_visibility = ["//visibility:public"])

cc_library(
name = "libavcodec",
hdrs = glob(["include/libavcodec/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavcodec",
],
)

cc_library(
name = "libavdevice",
hdrs = glob(["include/libavdevice/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavdevice",
],
)

cc_library(
name = "libavfilter",
hdrs = glob(["include/libavfilter/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavfilter",
],
)

cc_library(
name = "libavformat",
hdrs = glob(["include/libavformat/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavformat",
],
)

cc_library(
name = "libavresample",
hdrs = glob(["include/libavresample/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavresample",
],
)

cc_library(
name = "libswscale",
hdrs = glob(["include/libswscale/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lswscale",
],
)

cc_library(
name = "libavutil",
hdrs = glob(["include/libavutil/*.h"]),
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lavutil",
],
)
36 changes: 36 additions & 0 deletions workspace/ffmpeg/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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/x86_64-linux-gnu/libavcodec", "include/libavcodec") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libavdevice", "include/libavdevice") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libavfilter", "include/libavfilter") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libavformat", "include/libavformat") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libswresample", "include/libswresample") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libavutil", "include/libavutil") # noqa
repository_ctx.symlink("/usr/include/x86_64-linux-gnu/libswscale", "include/libswscale") # 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/ffmpeg:package.BUILD.bazel"),
"BUILD.bazel",
)

ffmpeg_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
3 changes: 3 additions & 0 deletions workspace/freeimage/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/freeimage/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- python -*-

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

licenses(["restricted"]) # GPL-2.0+

cc_library(
name = "freeimage",
hdrs = ["include/FreeImage.h"],
includes = ["include"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lfreeimage",
],
visibility = ["//visibility:public"],
)
30 changes: 30 additions & 0 deletions workspace/freeimage/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/FreeImage.h", "include/FreeImage.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/freeimage:package.BUILD.bazel"),
"BUILD.bazel",
)

freeimage_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
3 changes: 3 additions & 0 deletions workspace/gdal/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()
15 changes: 15 additions & 0 deletions workspace/gdal/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- python -*-

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

cc_library(
name = "gdal",
hdrs = glob(["include/gdal/*.h"]),
includes = ["include/gdal"],
linkopts = [
"-L" + LIBDIR,
"-Wl,-rpath," + LIBDIR,
"-lgdal",
],
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 8923cf4

Please sign in to comment.