Skip to content

Commit 4c750f7

Browse files
Feature/cibuildwheel (#50)
* initial attempt at cibuildwheel for develop * fix event syntax * fix name and turn on dev branch * (wip) add source dep options for cibuildwheel * fix random build issues * (wip) start splitting bindings for faster compile * fix compilation and formatting * fix get_layer_id usage * replicate zmq interface for send/recv in python * also port ZmqGraph implementation to python * turn on other platforms * get branch name right * drop old osx * use pack pramga for msvc * fix missing headers and other msvc compile issues * fix ub with uniform generator * use filepath to avoid wstring issue * switch to building on release only * rework external deps to use system packages when available * add dependencies to external projects * switch back to fetch content
1 parent c371dd4 commit 4c750f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2038
-1124
lines changed

.cmake-format.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ parse:
1313
pybind11_add_module:
1414
pargs: 1
1515
format:
16-
line_width: 100
16+
line_width: 120
1717
tab_size: 2
1818
use_tabchars: false
1919
max_subgroups_hwrap: 3

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Dependencies
3737
run: |
3838
python -m pip install --upgrade pip
39-
sudo apt-get update && sudo apt install libgtest-dev libeigen3-dev nlohmann-json3-dev libzmq3-dev python3-dev
39+
sudo apt-get update && sudo apt install python3-dev
4040
- name: Install
4141
run: python -m pip install ${{github.workspace}}
4242
- name: Test

.github/workflows/wheels.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
# Adapted from:
3+
# https://github.com/pypa/cibuildwheel?tab=readme-ov-file#example-setup
4+
name: 'Spark-DSG Wheels'
5+
on: {release: {types: [published]}}
6+
jobs:
7+
build_wheels:
8+
name: Build wheels on ${{ matrix.os }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-latest]
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
- name: Install cibuildwheel
17+
run: python -m pip install cibuildwheel
18+
- name: Build wheels
19+
run: python -m cibuildwheel --output-dir wheelhouse
20+
- uses: actions/upload-artifact@v4
21+
with:
22+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
23+
path: ./wheelhouse/*.whl

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,4 @@ Testing/
193193
# Versioning file
194194
include/spark_dsg_version.h
195195
.clangd
196+
wheelhouse

CMakeLists.txt

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,64 @@ option(SPARK_DSG_BUILD_EXAMPLES "Build examples" ON)
2424
option(SPARK_DSG_BUILD_PYTHON "Build python bindings" OFF)
2525
option(SPARK_DSG_BUILD_ZMQ "Build zmq message interface" ON)
2626

27-
find_package(nlohmann_json REQUIRED)
28-
find_package(Eigen3 REQUIRED)
29-
find_package(Threads REQUIRED)
27+
set(SPARK_DSG_INSTALL_PREFIX "")
28+
set(FIND_MODE REQUIRED)
29+
if(DEFINED SKBUILD AND "${SKBUILD}" GREATER 0)
30+
# nest headers, cmake and built lib under spark_dsg to make installation into sitepackages / wheel work correctly
31+
set(SPARK_DSG_INSTALL_PREFIX "${PROJECT_NAME}/")
32+
set(SPARK_DSG_BUILD_ZMQ OFF)
33+
set(FIND_MODE QUIET)
34+
endif()
3035

31-
find_package(PkgConfig REQUIRED)
32-
pkg_check_modules(zmq libzmq)
33-
if(SPARK_DSG_BUILD_ZMQ AND zmq_FOUND)
34-
set(SPARK_DSG_USE_ZMQ 1)
35-
else()
36-
message(WARNING "ZMQ not found! Disabling ZMQ interface")
37-
set(SPARK_DSG_USE_ZMQ 0)
36+
include(FetchContent)
37+
38+
find_package(nlohmann_json ${FIND_MODE})
39+
if(NOT ${nlohmann_json_FOUND})
40+
FetchContent_Declare(
41+
json
42+
GIT_REPOSITORY https://github.com/nlohmann/json.git
43+
GIT_TAG v3.11.3
44+
GIT_SHALLOW TRUE
45+
)
46+
47+
FetchContent_GetProperties(json)
48+
if(NOT json_POPULATED)
49+
FetchContent_Populate(json)
50+
endif()
51+
52+
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
53+
target_include_directories(nlohmann_json::nlohmann_json INTERFACE ${json_SOURCE_DIR}/single_include)
54+
endif()
55+
56+
find_package(Eigen3 ${FIND_MODE})
57+
if(NOT ${Eigen3_FOUND})
58+
FetchContent_Declare(
59+
eigen
60+
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip
61+
URL_HASH MD5=a83cb9a2cbba2dd52c137ac62d33d847
62+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
63+
)
64+
65+
FetchContent_GetProperties(eigen)
66+
if(NOT eigen_POPULATED)
67+
FetchContent_Populate(eigen)
68+
endif()
69+
70+
add_library(Eigen3::Eigen INTERFACE IMPORTED)
71+
target_include_directories(Eigen3::Eigen INTERFACE "${eigen_SOURCE_DIR}")
72+
endif()
73+
74+
set(SPARK_DSG_USE_ZMQ 0)
75+
if(SPARK_DSG_BUILD_ZMQ)
76+
find_package(PkgConfig REQUIRED)
77+
pkg_check_modules(zmq libzmq)
78+
if(zmq_FOUND)
79+
set(SPARK_DSG_USE_ZMQ 1)
80+
else()
81+
message(WARNING "ZMQ not found! Disabling ZMQ interface")
82+
endif()
3883
endif()
84+
3985
configure_file(cmake/spark_dsg_version.h.in include/spark_dsg_version.h)
4086

4187
add_library(
@@ -73,19 +119,18 @@ add_library(
73119
)
74120

75121
target_include_directories(
76-
${PROJECT_NAME}
77-
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
122+
${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
78123
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
79124
)
80-
target_link_libraries(
81-
${PROJECT_NAME} PUBLIC Eigen3::Eigen nlohmann_json::nlohmann_json
82-
PRIVATE Threads::Threads
83-
)
125+
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen nlohmann_json::nlohmann_json)
126+
84127
if(NOT BUILD_SHARED_LIBS)
85128
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1)
86129
endif()
130+
87131
if(SPARK_DSG_BUILD_ZMQ AND zmq_FOUND)
88-
target_link_libraries(${PROJECT_NAME} PRIVATE ${zmq_LIBRARIES})
132+
find_package(Threads REQUIRED)
133+
target_link_libraries(${PROJECT_NAME} PRIVATE ${zmq_LIBRARIES} Threads::Threads)
89134
target_include_directories(${PROJECT_NAME} PRIVATE ${zmq_INCLUDE_DIRS})
90135
endif()
91136

@@ -109,20 +154,11 @@ include(GNUInstallDirs)
109154
include(CMakePackageConfigHelpers)
110155

111156
write_basic_package_version_file(
112-
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake VERSION ${PROJECT_VERSION}
113-
COMPATIBILITY AnyNewerVersion
157+
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion
114158
)
115159

116-
set(SPARK_DSG_INSTALL_PREFIX "")
117-
if(SPARK_DSG_BUILDING_PYTHON_PACKAGE)
118-
# nest headers, cmake and built lib under spark_dsg to make installation
119-
# into sitepackages / wheel work correctly
120-
set(SPARK_DSG_INSTALL_PREFIX "${PROJECT_NAME}/")
121-
endif()
122-
123160
configure_package_config_file(
124-
${CMAKE_CURRENT_LIST_DIR}/cmake/spark_dsgConfig.cmake.in
125-
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake
161+
${CMAKE_CURRENT_LIST_DIR}/cmake/spark_dsgConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake
126162
INSTALL_DESTINATION "${SPARK_DSG_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg"
127163
)
128164

@@ -142,8 +178,6 @@ install(
142178
DESTINATION "${SPARK_DSG_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg"
143179
)
144180

145-
install(
146-
FILES ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake
147-
${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake
148-
DESTINATION "${SPARK_DSG_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg"
181+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/spark_dsgConfigVersion.cmake
182+
DESTINATION "${SPARK_DSG_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}/cmake/spark_dsg"
149183
)

include/spark_dsg/dynamic_scene_graph.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* -------------------------------------------------------------------------- */
3535
#pragma once
3636
#include <Eigen/Core>
37+
#include <filesystem>
3738
#include <nlohmann/json.hpp>
3839
#include <type_traits>
3940

@@ -454,14 +455,14 @@ class DynamicSceneGraph {
454455
* @param filepath Filepath to save graph to.
455456
* @param include_mesh Optionally encode mesh (defaults to true)
456457
*/
457-
void save(std::string filepath, bool include_mesh = true) const;
458+
void save(std::filesystem::path filepath, bool include_mesh = true) const;
458459

459460
/**
460461
* @brief Parse graph from binary or JSON file
461462
* @param filepath Complete path to file to read, including extension.
462463
* @returns Resulting parsed scene graph
463464
*/
464-
static Ptr load(std::string filepath);
465+
static Ptr load(std::filesystem::path filepath);
465466

466467
//! @brief Set the scene graph mesh
467468
void setMesh(const std::shared_ptr<Mesh>& mesh);

include/spark_dsg/mesh.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <Eigen/Dense>
3838
#include <array>
3939
#include <cstdint>
40+
#include <filesystem>
4041
#include <memory>
4142
#include <unordered_set>
4243
#include <vector>
@@ -212,14 +213,14 @@ class Mesh {
212213
*
213214
* @param filepath Filepath to save graph to.
214215
*/
215-
void save(std::string filepath) const;
216+
void save(std::filesystem::path filepath) const;
216217

217218
/**
218219
* @brief parse mesh from binary or JSON file
219220
* @param filepath Complete path to file to read, including extension.
220221
* @returns Resulting parsed mesh
221222
*/
222-
static Ptr load(std::string filepath);
223+
static Ptr load(std::filesystem::path filepath);
223224

224225
// ------ Modification ------
225226

include/spark_dsg/node_attributes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct SemanticNodeAttributes : public NodeAttributes {
169169
SemanticNodeAttributes();
170170
virtual ~SemanticNodeAttributes() = default;
171171
NodeAttributes::Ptr clone() const override;
172-
virtual void transform(const Eigen::Isometry3d& transform) override;
172+
void transform(const Eigen::Isometry3d& transform) override;
173173

174174
bool hasLabel() const;
175175
bool hasFeature() const;
@@ -210,7 +210,7 @@ struct ObjectNodeAttributes : public SemanticNodeAttributes {
210210
ObjectNodeAttributes();
211211
virtual ~ObjectNodeAttributes() = default;
212212
NodeAttributes::Ptr clone() const override;
213-
virtual void transform(const Eigen::Isometry3d& transform);
213+
void transform(const Eigen::Isometry3d& transform) override;
214214

215215
//! Mesh vertice connections
216216
std::list<size_t> mesh_connections;
@@ -375,7 +375,7 @@ struct AgentNodeAttributes : public NodeAttributes {
375375
NodeId external_key);
376376
virtual ~AgentNodeAttributes() = default;
377377
NodeAttributes::Ptr clone() const override;
378-
virtual void transform(const Eigen::Isometry3d& transform) override;
378+
void transform(const Eigen::Isometry3d& transform) override;
379379

380380
std::chrono::nanoseconds timestamp;
381381
Eigen::Quaterniond world_R_body;

include/spark_dsg/node_symbol.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ class NodeSymbol {
9393
private:
9494
union {
9595
NodeId value;
96-
struct __attribute__((packed)) {
96+
#pragma pack(push, 1)
97+
struct {
9798
NodeId index : 56;
9899
char key : 8;
99100
} symbol;
101+
#pragma pack(pop)
100102
} value_;
101103
};
102104

include/spark_dsg/serialization/file_io.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* -------------------------------------------------------------------------- */
3535
#pragma once
3636

37+
#include <filesystem>
3738
#include <memory>
3839
#include <optional>
3940
#include <string>
@@ -53,7 +54,7 @@ enum class FileType { JSON, BINARY, NONE, UNKNOWN };
5354
* @brief Identify the file type of a given filepath.
5455
* @param filepath The complete filepath to identify.
5556
*/
56-
FileType identifyFileType(const std::string& filepath);
57+
FileType identifyFileType(const std::filesystem::path& filepath);
5758

5859
/**
5960
* @brief Verify that the file extension of a given filepath is valid. If no extension
@@ -62,7 +63,7 @@ FileType identifyFileType(const std::string& filepath);
6263
* @throws std::runtime_error if the extension is invalid.
6364
* @return The file type of the resulting filepath.
6465
*/
65-
FileType verifyFileExtension(std::string& filepath);
66+
FileType verifyFileExtension(std::filesystem::path& filepath);
6667

6768
/**
6869
* @brief Save a DynamicSceneGraph to a JSON file.
@@ -71,15 +72,15 @@ FileType verifyFileExtension(std::string& filepath);
7172
* @param include_mesh If true, save the mesh data for each node.
7273
*/
7374
void saveDsgJson(const DynamicSceneGraph& graph,
74-
const std::string& filepath,
75+
const std::filesystem::path& filepath,
7576
bool include_mesh = false);
7677

7778
/**
7879
* @brief Load a DynamicSceneGraph from a JSON file.
7980
* @param filepath The filepath including extension to load from.
8081
* @return A pointer to the loaded graph or nullptr if loading failed.
8182
*/
82-
std::shared_ptr<DynamicSceneGraph> loadDsgJson(const std::string& filepath);
83+
std::shared_ptr<DynamicSceneGraph> loadDsgJson(const std::filesystem::path& filepath);
8384

8485
/**
8586
* @brief Save a DynamicSceneGraph to a file in binary serialization.
@@ -88,14 +89,14 @@ std::shared_ptr<DynamicSceneGraph> loadDsgJson(const std::string& filepath);
8889
* @param include_mesh If true, save the mesh data for each node.
8990
*/
9091
void saveDsgBinary(const DynamicSceneGraph& graph,
91-
const std::string& filepath,
92+
const std::filesystem::path& filepath,
9293
bool include_mesh = false);
9394

9495
/**
9596
* @brief Load a DynamicSceneGraph from a file in binary serialization.
9697
* @param filepath The filepath including extension to load from.
9798
* @return A pointer to the loaded graph or nullptr if loading failed.
9899
*/
99-
std::shared_ptr<DynamicSceneGraph> loadDsgBinary(const std::string& filepath);
100+
std::shared_ptr<DynamicSceneGraph> loadDsgBinary(const std::filesystem::path& filepath);
100101

101102
} // namespace spark_dsg::io

0 commit comments

Comments
 (0)