Skip to content

Commit

Permalink
Update all dependencies, add pcl tests, and fix minor bugs (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgreenek committed Aug 14, 2023
1 parent c5c02a1 commit 10719f0
Show file tree
Hide file tree
Showing 9 changed files with 1,228 additions and 261 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@ on: [push]

jobs:
build_x86-64:
runs-on: ubuntu-18.04
name: Build on ubuntu18.04 x86_64
name: Build on ubuntu22.04 x86_64
runs-on: ubuntu-22.04
timeout-minutes: 720

steps:
- uses: actions/checkout@v2.1.0
- uses: actions/checkout@v3.5.3
- run: |
curl -sL https://github.com/bazelbuild/bazelisk/releases/download/v1.11.0/bazelisk-linux-amd64 -o /tmp/bazel
chmod 755 /tmp/bazel
cd example
- run: |
cd example && /tmp/bazel build "@pcl//..." --verbose_failures --show_progress_rate_limit=10
cd example && /tmp/bazel test "@pcl//..." --verbose_failures --show_progress_rate_limit=10
build_aarch64:
runs-on: ubuntu-18.04
name: Build on ubuntu18.04 aarch64
name: Build on ubuntu22.04 aarch64
runs-on: ubuntu-22.04
timeout-minutes: 720

steps:
- uses: actions/checkout@v2.1.0
- uses: uraimo/run-on-arch-action@v2.1.1
- uses: actions/checkout@v3.5.3
- uses: uraimo/run-on-arch-action@v2.5.0
name: Build and run tests on embedded platforms
with:
arch: aarch64
distro: ubuntu18.04
distro: ubuntu22.04

# Not required, but speeds up builds
githubToken: ${{ github.token }}
Expand All @@ -43,4 +45,6 @@ jobs:
chmod 755 /usr/bin/bazel
run: |
cd example && bazel build "@pcl//..." --verbose_failures --show_progress_rate_limit=10
# Only run small tests because the enumlated environment is super slow, so large tests
# would timeout and fail.
cd example && bazel test "@pcl//..." --verbose_failures --show_progress_rate_limit=10 --test_size_filters="small"
3 changes: 2 additions & 1 deletion bzl/pcl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _PCL_DEFAULT_COMPILER_CONFIG = {

def _compiler_config_value(value, kwargs):
# NOTE: __pcl_linux-aarch64 is defined by the pcl_config macro.
default_architecture_value = select({
default_architecture_value = select({
":__pcl_linux-aarch64": _PCL_AARCH64_COMPILER_CONFIG[value],
"//conditions:default": _PCL_DEFAULT_COMPILER_CONFIG[value],
})
Expand Down Expand Up @@ -158,6 +158,7 @@ def pcl_library(name, **kwargs):
native.cc_library(
name = name,
srcs = native.glob([
"{}/src/**/*.c".format(name),
"{}/src/**/*.cpp".format(name),
"{}/include/**/*.hpp".format(name),
], exclude = exclude_srcs),
Expand Down
42 changes: 24 additions & 18 deletions bzl/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def pcl_repositories():
# Latest commit as of: Dec 23, 2023
# NOTE: We cannot update beyond this commit without breaking aarch64 support due to lzma.
# See: https://github.com/nelhage/rules_boost/issues/374
maybe(
http_archive,
name = "com_github_nelhage_rules_boost",
strip_prefix = "rules_boost-96e9b631f104b43a53c21c87b01ac538ad6f3b48",
urls = ["https://github.com/nelhage/rules_boost/archive/96e9b631f104b43a53c21c87b01ac538ad6f3b48.tar.gz"],
sha256 = "490d11425393eed068966a4990ead1ff07c658f823fd982fddac67006ccc44ab",
strip_prefix = "rules_boost-57c99395e15720e287471d79178d36a85b64d6f6",
urls = ["https://github.com/nelhage/rules_boost/archive/57c99395e15720e287471d79178d36a85b64d6f6.tar.gz"],
)


maybe(
http_archive,
name = "com_google_googletest",
sha256 = "8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7",
strip_prefix = "googletest-1.14.0",
urls = ["https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz"],
)

maybe(
http_archive,
name = "eigen",
build_file = "@rules_pcl//third_party:eigen.BUILD",
sha256 = "a8d87c8df67b0404e97bcef37faf3b140ba467bc060e2b883192165b319cea8d",
strip_prefix = "eigen-git-mirror-3.3.7",
# NOTE: The official repo is hosted on gitlab, but gitlab appears to return a 406 error when
# trying to fetch archives. So we are using the deprecated github mirror instead until
# either bazel or gitlab fixes this issue.
# See:
# https://github.com/bazelbuild/bazel/issues/11187
# https://stackoverflow.com/questions/60864626/cannot-fetch-eigen-with-bazel-406-not-acceptable
urls = ["https://github.com/eigenteam/eigen-git-mirror/archive/3.3.7.tar.gz"],
sha256 = "8586084f71f9bde545ee7fa6d00288b264a2b7ac3607b974e54d13e7162c1c72",
strip_prefix = "eigen-3.4.0",
urls = ["https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz"],
)

# Latest commit as of April 6, 2019
Expand All @@ -38,9 +44,9 @@ def pcl_repositories():
http_archive,
name = "lz4",
build_file = "@rules_pcl//third_party:lz4.BUILD",
sha256 = "030644df4611007ff7dc962d981f390361e6c97a34e5cbc393ddfbe019ffe2c1",
strip_prefix = "lz4-1.9.3",
urls = ["https://github.com/lz4/lz4/archive/refs/tags/v1.9.3.tar.gz"],
sha256 = "0b0e3aa07c8c063ddf40b082bdf7e37a1562bda40a0ff5272957f3e987e0e54b",
strip_prefix = "lz4-1.9.4",
urls = ["https://github.com/lz4/lz4/archive/refs/tags/v1.9.4.tar.gz"],
)

maybe(
Expand Down Expand Up @@ -70,10 +76,10 @@ def pcl_repositories():
maybe(
http_archive,
name = "pcl",
sha256 = "b52e1424686843c94c5771795a79d7a33296708ce23173a3f32769c30ee3a993",
sha256 = "8ab98a9db371d822de0859084a375a74bdc7f31c96d674147710cf4101b79621",
build_file = "@rules_pcl//third_party:pcl.BUILD",
strip_prefix = "pcl-pcl-1.10.0",
urls = ["https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.10.0.zip"],
strip_prefix = "pcl-pcl-1.13.1",
urls = ["https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.13.1.tar.gz"],
)

maybe(
Expand Down
30 changes: 29 additions & 1 deletion example/.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
build --cxxopt='-std=c++14'
# Helpful flags: https://blog.aspect.dev/bazelrc-flags

# Build in release mode with debug symbols by default.
# These are disabled for quicker build-times in CI, but in your code you almost definitely want to
# set -c opt.
#build --compilation_mode opt
#build --copt -g

build --keep_going
# Fix the wrong default to generate __init__.py to delimit a Python package.
build --incompatible_default_to_explicit_init_py
build --cxxopt='-std=c++17'
# Ensure that you don't accidentally make non-hermetic actions/tests
# which depend on remote services. Tag an individual target with
# tags=["requires-network"] to opt-out of the enforcement.
build --sandbox_default_allow_network=false
# Don't let environment variables like $PATH sneak into the build,
# which can cause massive cache misses when they change.
build --incompatible_strict_action_env
# Helps debugging when Bazel runs out of memory
build --heap_dump_on_oom
# Speed up all builds by not checking if output files have been modified.
build --noexperimental_check_output_files

build --nolegacy_external_runfiles
run --nolegacy_external_runfiles
test --nolegacy_external_runfiles

test --test_output=errors
2 changes: 1 addition & 1 deletion example/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
6.2.1
206 changes: 206 additions & 0 deletions gen_test_targets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#!/usr/bin/env python3
import argparse
import os

EXCLUDE_TESTS = {
# This test loads a file in code using an env var rather than taking an argument.
"geometry": ["test_mesh_io"],
# This test has internal timeout testing that cannot be increased. It fails in CI on the aarch64
# target because it's running in an enumlated environment (so everything runs 5x slower than
# normal). Just disable it to prevent it from causing non-deterministic timing failures.
"sample_consensus": ["test_sample_consensus"],
}

MEDIUM_TESTS = {
"io": ["test_io"],
}
LARGE_TESTS = {
"common": ["test_eigen"],
# NOTE: The below tests only take a long time when running in CI's aarch64 emulated environment.
"filters": ["test_crop_hull"],
"octree": ["test_test_octree"],
"search": ["test_flann_search", "test_kdtree_search"],
}

RENAME_DEPS = {
":gtest": ":test",
"FLANN::FLANN": "@flann",
}

EXTRA_SRCS = {
"geometry": {
"all": ["test/geometry/test_mesh_common_functions.h"],
},
"search": {
"all": ["test/search/precise_distances.h"],
},
}

# These targets are missing required deps, which works with cmake but not bazel.
EXTRA_DEPS = {
"2d": {
"test_2d_keypoint_instantiation_with_precompile": [":2d"],
"test_2d_keypoint_instantiation_without_precompile": [":2d"],
},
"io": {
"test_buffers": [":io"]
},
"octree": {
"test_octree": [":octree"],
},
"registration": {
"test_correspondence_estimation": [":io"],
},
}

PARSER_STATE_NONE = "NONE"
PARSER_STATE_TEST_NAME = "TEST_NAME"
PARSER_STATE_SRCS = "SRCS"
PARSER_STATE_DEPS = "DEPS"
PARSER_STATE_ARGS = "ARGS"


def parse_args() -> tuple[list[str], any]:
parser = argparse.ArgumentParser(
description="Generates bazel BUILD targets for test targets")
parser.add_argument("--pcl_path", help="Path to the local pcl source code")
parser.add_argument("--pcl_lib",
help="The pcl library to generate tests for")
parser.add_argument("--out", "-o", help="Path to the output BUILD file")
return parser.parse_args()


def main():
args = parse_args()
test_lib_path = os.path.join(args.pcl_path, "test", args.pcl_lib)
cmakelists_path = os.path.join(test_lib_path, "CMakeLists.txt")
with open(cmakelists_path) as cmakelists_file:
with open(args.out, "w") as out_file:
parser_state = PARSER_STATE_NONE
test_name = None
srcs = []
deps = []
arguments = []
target_complete = False
for line in cmakelists_file:
line = line.strip()
# Example line defining a test:
# PCL_ADD_TEST(common_test_wrappers test_wrappers FILES test_wrappers.cpp LINK_WITH pcl_gtest pcl_common)
words = line.split()
word_index = 0
if parser_state == PARSER_STATE_NONE:
if not line.startswith("PCL_ADD_TEST"):
continue
# Handle spurious whitespace like "PCL_ADD_TEST (foo ...".
test_line_parts = line.split("(")
assert (len(test_line_parts) == 2)
words = test_line_parts[1].split()
test_name = words[1]
parser_state = PARSER_STATE_SRCS
print(test_name)
word_index = 2

while word_index < len(words):
word = words[word_index]
if word == "FILES":
parser_state = PARSER_STATE_SRCS
word_index += 1
continue
if word == "LINK_WITH":
parser_state = PARSER_STATE_DEPS
word_index += 1
continue
if word == "ARGUMENTS":
parser_state = PARSER_STATE_ARGS
word_index += 1
continue

if word.endswith(")"):
target_complete = True
word = word.rstrip(")").strip()

if parser_state == PARSER_STATE_SRCS:
srcs.append(os.path.join("test", args.pcl_lib, word))
elif parser_state == PARSER_STATE_DEPS:
dep = word.replace("pcl_", ":")
if dep in RENAME_DEPS:
dep = RENAME_DEPS[dep]
deps.append(dep)
elif parser_state == PARSER_STATE_ARGS:
arguments.append(word)

if target_complete:
if args.pcl_lib in EXCLUDE_TESTS and test_name in EXCLUDE_TESTS[
args.pcl_lib]:
print(
f"WARNING: Skipping excluded test {test_name}")
elif len(arguments) > 0:
# Some PCL tests require pass arguments. Maybe I'll figure out later how to landle
# this...
print(
f"WARNING: Skipping test {test_name} because it requires args"
)
else:
if args.pcl_lib in EXTRA_SRCS:
if "all" in EXTRA_SRCS[args.pcl_lib]:
for extra_src in EXTRA_SRCS[
args.pcl_lib]["all"]:
if extra_src not in srcs:
srcs.append(extra_src)
if test_name in EXTRA_SRCS[args.pcl_lib]:
srcs.extend(
EXTRA_SRCS[args.pcl_lib][test_name])
if args.pcl_lib in EXTRA_DEPS and test_name in EXTRA_DEPS[
args.pcl_lib]:
deps.extend(
EXTRA_DEPS[args.pcl_lib][test_name])
srcs.sort()
deps.sort()
arguments.sort()
size = "small"
if args.pcl_lib in LARGE_TESTS and test_name in LARGE_TESTS[
args.pcl_lib]:
size = "large"
elif args.pcl_lib in MEDIUM_TESTS and test_name in MEDIUM_TESTS[
args.pcl_lib]:
size = "medium"
out_file.write("cc_test(\n")
out_file.write(
f" name = \"{args.pcl_lib}_{test_name}\",\n"
)
out_file.write(f" size = \"{size}\",\n")
if len(srcs) == 1:
out_file.write(
f" srcs = [\"{srcs[0]}\"],\n")
else:
out_file.write(" srcs = [\n")
for src in srcs:
out_file.write(f" \"{src}\",\n")
out_file.write(" ],\n")
if len(deps) == 1:
out_file.write(
f" deps = [\"{deps[0]}\"],\n")
else:
out_file.write(" deps = [\n")
for dep in deps:
out_file.write(f" \"{dep}\",\n")
out_file.write(" ],\n")
out_file.write(")\n")
out_file.write("\n")

# Reset state
parser_state = PARSER_STATE_NONE
test_name = None
srcs = []
deps = []
arguments = []
target_complete = False

# Ignore the rest of the line.
break

word_index += 1


if __name__ == "__main__":
main()
Loading

0 comments on commit 10719f0

Please sign in to comment.