Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Fix test compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Feb 16, 2024
1 parent 299aea8 commit 6c35790
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 86 deletions.
35 changes: 30 additions & 5 deletions .github/workflows/build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,35 @@ jobs:
matrix:
include:
- artifact-name: Rust Native - Windows x86_64 (CasADi)
backend: casadi
os: windows-2022
rust-target: x86_64-pc-windows-gnu

- artifact-name: Rust Native - macOS x86_64 (CasADi)
backend: casadi
os: macOS-13
rust-target: x86_64-apple-darwin

- artifact-name: Rust Native - macOS arm64 (CasADi)
os: macOS-13
backend: casadi
os: macOS-14
rust-target: aarch64-apple-darwin

- artifact-name: Rust Native - Linux x86_64 (CasADi)
backend: casadi
os: ubuntu-latest
rust-target: x86_64-unknown-linux-gnu
- artifact-name: Rust Native - Windows x86_64 (Sleipnir)
backend: sleipnir
os: windows-2022
rust-target: x86_64-pc-windows-gnu
- artifact-name: Rust Native - macOS x86_64 (Sleipnir)
backend: sleipnir
os: macOS-13
rust-target: x86_64-apple-darwin
- artifact-name: Rust Native - macOS arm64 (Sleipnir)
backend: sleipnir
os: macOS-14
rust-target: aarch64-apple-darwin
- artifact-name: Rust Native - Linux x86_64 (Sleipnir)
backend: sleipnir
os: ubuntu-latest
rust-target: x86_64-unknown-linux-gnu

Expand All @@ -47,12 +64,20 @@ jobs:
targets: ${{matrix.rust-target}}

- name: Set up Clang
if: matrix.os != 'macOS-13'
if: ${{ !startsWith(matrix.os, 'macOS') }}
uses: egor-tensin/setup-clang@v1
with:
version: latest
platform: x64

- name: Select backend (non-macOS)
if: ${{ !startsWith(matrix.os, 'macOS') }}
run: sed -i 's/"OPTIMIZER_BACKEND", "casadi"/"OPTIMIZER_BACKEND", "${{ matrix.backend }}"/' rust/build.rs

- name: Select backend (macOS)
if: ${{ startsWith(matrix.os, 'macOS') }}
run: sed -i '' 's/"OPTIMIZER_BACKEND", "casadi"/"OPTIMIZER_BACKEND", "${{ matrix.backend }}"/' rust/build.rs

- name: Build Rust
working-directory: rust
run: cargo build --target ${{ matrix.rust-target }}
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,40 @@ concurrency:

jobs:
build-cpp:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- artifact-name: Native - Windows (CasADi)
cmake-config-env-vars:
cmake-flags: "-G \"MinGW Makefiles\" -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++"
optimizer: casadi
os: windows-2022
- artifact-name: Native - macOS x86_64 (CasADi)
cmake-config-env-vars: CFLAGS="$CFLAGS -arch x86_64" CXXFLAGS="$CXXFLAGS -arch x86_64"
cmake-flags: "-DCMAKE_APPLE_SILICON_PROCESSOR=x86_64"
optimizer: casadi
os: macOS-13
- artifact-name: Native - macOS arm64 (CasADi)
cmake-config-env-vars: CFLAGS="$CFLAGS -arch arm64" CXXFLAGS="$CXXFLAGS -arch arm64"
cmake-flags: "-DCMAKE_APPLE_SILICON_PROCESSOR=arm64"
optimizer: casadi
os: macOS-13
os: macOS-14
- artifact-name: Native - Linux (CasADi)
cmake-config-env-vars:
cmake-flags:
optimizer: casadi
os: ubuntu-latest
- artifact-name: Native - Windows (Sleipnir)
cmake-config-env-vars:
cmake-flags:
optimizer: sleipnir
os: windows-2022
- artifact-name: Native - macOS universal (Sleipnir)
cmake-config-env-vars: CFLAGS="$CFLAGS -arch x86_64 -arch arm64" CXXFLAGS="$CXXFLAGS -arch x86_64 -arch arm64"
- artifact-name: Native - macOS x86_64 (Sleipnir)
cmake-flags:
optimizer: sleipnir
os: macOS-13
- artifact-name: Native - macOS arm64 (Sleipnir)
cmake-flags:
optimizer: sleipnir
os: macOS-14
- artifact-name: Native - Linux (Sleipnir)
cmake-config-env-vars:
cmake-flags:
optimizer: sleipnir
os: ubuntu-latest
Expand All @@ -62,11 +60,15 @@ jobs:
version: 12.2.0

- name: configure
run: ${{ matrix.cmake-config-env-vars }} cmake -B build -S . ${{ matrix.cmake-flags }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer }} -DWITH_JAVA=ON -DJAVA_INSTALL_JAR=OFF
run: cmake -B build -S . ${{ matrix.cmake-flags }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer }} -DWITH_JAVA=ON -DJAVA_INSTALL_JAR=OFF

- name: build
run: cmake --build build --config RelWithDebInfo --parallel $(nproc)

- name: test
working-directory: build
run: ctest -C RelWithDebInfo --output-on-failure

- name: install
run: cmake --install build --config RelWithDebInfo --prefix pkg

Expand Down
28 changes: 13 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,13 @@ target_compile_definitions(TrajoptLib PRIVATE TRAJOPT_EXPORTS)
include(FetchContent)

# fmt dependency
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS_SAVE})
set(FMT_INSTALL ON)
fetchcontent_declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.2.1
)
fetchcontent_makeavailable(fmt)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})

if(
${OPTIMIZER_BACKEND} STREQUAL "casadi"
Expand All @@ -105,8 +101,6 @@ endif()
target_link_libraries(TrajoptLib PUBLIC fmt::fmt)

# json dependency
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
set(JSON_BuildTests OFF)
set(JSON_Install ON)
fetchcontent_declare(
Expand All @@ -115,7 +109,6 @@ fetchcontent_declare(
GIT_TAG v3.11.2
)
fetchcontent_makeavailable(nlohmann_json)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})

target_link_libraries(TrajoptLib PUBLIC nlohmann_json::nlohmann_json)

Expand Down Expand Up @@ -203,11 +196,9 @@ install(
DESTINATION lib/cmake/TrajoptLib
)

# GoogleTest dependency (static linkage)
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
# GoogleTest dependency
option(INSTALL_GMOCK "Install GoogleTest's GMock" OFF)
option(INSTALL_GTEST "Install GoogleTest's GTest" OFF)
option(INSTALL_GTEST "Install GoogleTest's GTest" ON)
fetchcontent_declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
Expand All @@ -217,20 +208,27 @@ fetchcontent_declare(
FIND_PACKAGE_ARGS NAMES GTest
)
fetchcontent_makeavailable(googletest)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})

include(CMakeDependentOption)

cmake_dependent_option(
BUILD_TESTING
"Enable creation of tests."
OFF
ON
"PROJECT_IS_TOP_LEVEL"
OFF
)
if(BUILD_TESTING)
enable_testing()
include(GoogleTest)
if(
${OPTIMIZER_BACKEND} STREQUAL "casadi"
AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux"
AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU"
)
target_compile_definitions(gtest PUBLIC "_GLIBCXX_USE_CXX11_ABI=0")
target_compile_definitions(gtest_main PUBLIC "_GLIBCXX_USE_CXX11_ABI=0")
endif()
endif()

# Build TrajoptLib tests
Expand All @@ -247,7 +245,7 @@ if(BUILD_TESTING)
)
target_link_libraries(
TrajoptLibTest
PRIVATE TrajoptLib fmt::fmt GTest::gtest GTest::gtest_main
PRIVATE TrajoptLib fmt::fmt GTest::gtest_main
)
if(NOT CMAKE_TOOLCHAIN_FILE)
gtest_discover_tests(TrajoptLibTest)
Expand Down Expand Up @@ -289,7 +287,7 @@ foreach(example ${EXAMPLES})
)
target_link_libraries(
${example}Test
PRIVATE TrajoptLib GTest::gtest GTest::gtest_main
PRIVATE TrajoptLib GTest::gtest_main
)
if(NOT CMAKE_TOOLCHAIN_FILE)
gtest_discover_tests(${example}Test)
Expand Down
32 changes: 32 additions & 0 deletions examples/.styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cppHeaderFileInclude {
\.h$
\.hpp$
\.inc$
}

cppSrcFileInclude {
\.cpp$
}

modifiableFileExclude {
jni/jni\.h$
jni/darwin/jni_md\.h$
jni/linux/jni_md\.h$
jni/win32/jni_md\.h$
\.jar$
}

licenseUpdateExclude {
java/src/main/java/org/team2363/util/DependencyExtractor\.java$
java/src/main/java/org/team2363/util/RuntimeDetector\.java$
java/src/main/java/org/team2363/util/RuntimeLoader\.java$
}

includeOtherLibs {
^Eigen/
^fmt/
^casadi/
^sleipnir/
^trajopt/
^gtest/
}
28 changes: 14 additions & 14 deletions examples/Swerve/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
#include <vector>

#include <fmt/core.h>

#include "trajopt/IncompatibleTrajectoryException.h"
#include "trajopt/OptimalTrajectoryGenerator.h"
#include "trajopt/constraint/Constraint.h"
#include "trajopt/constraint/TranslationConstraint.h"
#include "trajopt/constraint/holonomic/HolonomicConstraint.h"
#include "trajopt/drivetrain/SwerveDrivetrain.h"
#include "trajopt/obstacle/Obstacle.h"
#include "trajopt/path/InitialGuessPoint.h"
#include "trajopt/path/Path.h"
#include "trajopt/path/SwervePathBuilder.h"
#include "trajopt/set/ConeSet2d.h"
#include "trajopt/solution/SwerveSolution.h"
#include "trajopt/trajectory/HolonomicTrajectory.h"
#include <trajopt/IncompatibleTrajectoryException.h>
#include <trajopt/OptimalTrajectoryGenerator.h>
#include <trajopt/constraint/Constraint.h>
#include <trajopt/constraint/TranslationConstraint.h>
#include <trajopt/constraint/holonomic/HolonomicConstraint.h>
#include <trajopt/drivetrain/SwerveDrivetrain.h>
#include <trajopt/obstacle/Obstacle.h>
#include <trajopt/path/InitialGuessPoint.h>
#include <trajopt/path/Path.h>
#include <trajopt/path/SwervePathBuilder.h>
#include <trajopt/set/ConeSet2d.h>
#include <trajopt/solution/SwerveSolution.h>
#include <trajopt/trajectory/HolonomicTrajectory.h>

int main() {
using namespace trajopt;

SwerveDrivetrain swerveDrivetrain{.mass = 45,
.moi = 6,
.modules = {{+0.6, +0.6, 0.04, 70, 2},
Expand Down
2 changes: 2 additions & 0 deletions include/trajopt/path/SwervePathBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder {
* @param heading the heading
*/
void PoseWpt(size_t idx, double x, double y, double heading);

/**
* Create a translation waypoint constraint on the waypoint at the
* provided index, and add an initial guess point with the same translation.
Expand Down Expand Up @@ -123,6 +124,7 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder {
* @param vtheta velocity vector polar angle
*/
void WptVelocityPolar(size_t idx, double vr, double vtheta);

/**
* Specify the required angular velocity of the robot to be zero
* at a waypoint
Expand Down
3 changes: 2 additions & 1 deletion rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ fn main() -> miette::Result<()> {

cmake_config
.profile("RelWithDebInfo")
.define("OPTIMIZER_BACKEND", "casadi");
.define("OPTIMIZER_BACKEND", "casadi")
.define("BUILD_TESTING", "OFF");

if cfg!(target_os = "windows") {
cmake_config
Expand Down
32 changes: 32 additions & 0 deletions test/.styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cppHeaderFileInclude {
\.h$
\.hpp$
\.inc$
}

cppSrcFileInclude {
\.cpp$
}

modifiableFileExclude {
jni/jni\.h$
jni/darwin/jni_md\.h$
jni/linux/jni_md\.h$
jni/win32/jni_md\.h$
\.jar$
}

licenseUpdateExclude {
java/src/main/java/org/team2363/util/DependencyExtractor\.java$
java/src/main/java/org/team2363/util/RuntimeDetector\.java$
java/src/main/java/org/team2363/util/RuntimeLoader\.java$
}

includeOtherLibs {
^Eigen/
^fmt/
^casadi/
^sleipnir/
^trajopt/
^gtest/
}
Loading

0 comments on commit 6c35790

Please sign in to comment.