Skip to content

Commit

Permalink
Try to restore C bindings as a separate library build. (#967)
Browse files Browse the repository at this point in the history
* Try to restore C bindings as a separate library build.

* Doesn't look like we need this define here now.

* meshIO isn't a separate library

* Right - manifoldc.h is in a different location
  • Loading branch information
starseeker authored Sep 30, 2024
1 parent 5a157a0 commit 3c8d486
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 58 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
cd ../
lcov --capture --gcov-tool gcov-${{ matrix.gcc }} --ignore-errors mismatch --directory . --output-file ./code_coverage_test.info
lcov --add-tracefile ./code_coverage_init.info --add-tracefile ./code_coverage_test.info --output-file ./code_coverage_total.info
lcov --remove ./code_coverage_total.info '/usr/*' '*/test/*' '*/extras/*' --output-file ./code_coverage.info
lcov --remove ./code_coverage_total.info '/usr/*' '*/test/*' '*/extras/*' '*/bindings/*' --output-file ./code_coverage.info
cd ../
- uses: codecov/codecov-action@v4
if: matrix.parallel_backend == 'OFF'
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_PYBIND=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=ON .. && make
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_PYBIND=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_CBIND=ON -DMANIFOLD_PAR=ON .. && make
- name: Test
run: |
cd build/test
Expand Down Expand Up @@ -205,7 +205,7 @@ jobs:
export MXETARGETDIR=$MXEDIR/usr/$MXE_TARGETS
export PATH=/mxe/usr/bin:$PATH
export CMAKE=$MXE_TARGETS-cmake
$CMAKE -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DMANIFOLD_PYBIND=OFF -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} .. && make
$CMAKE -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DMANIFOLD_PYBIND=OFF -DMANIFOLD_CBIND=OFF -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} .. && make
build_mac:
timeout-minutes: 30
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ option(MANIFOLD_PAR "Enable Parallel backend" OFF)
option(MANIFOLD_TEST "Enable testing suite" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON)
include(CMakeDependentOption)
cmake_dependent_option(MANIFOLD_CBIND "Build C (FFI) bindings" ON "MANIFOLD_CROSS_SECTION" OFF)
option(MANIFOLD_PYBIND "Build python bindings" OFF)
cmake_dependent_option(MANIFOLD_JSBIND "Build js binding" ON "EMSCRIPTEN" OFF)

Expand Down Expand Up @@ -301,6 +302,7 @@ message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}")
message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}")
message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}")
message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}")
message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}")
message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}")
message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}")
message(STATUS "MANIFOLD_EXCEPTIONS: ${MANIFOLD_EXCEPTIONS}")
Expand Down
4 changes: 4 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if (NOT MANIFOLD_CROSS_SECTION)
return()
endif()

if(NOT EMSCRIPTEN AND MANIFOLD_CBIND)
add_subdirectory(c)
endif()

if(NOT EMSCRIPTEN AND MANIFOLD_PYBIND)
add_subdirectory(python)
endif()
Expand Down
49 changes: 49 additions & 0 deletions bindings/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# this is a shared library for FFI bindings
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../../include
)

add_library(manifoldc SHARED
manifoldc.cpp
conv.cpp
box.cpp
cross.cpp
rect.cpp
)

if(MSVC)
set_target_properties(manifoldc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_target_properties(manifoldc PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin )
set_target_properties(manifoldc PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin )
endif()

if(MANIFOLD_EXPORT)
target_sources(manifoldc PRIVATE meshIOc.cpp)
target_compile_options(manifoldc PUBLIC -DMANIFOLD_EXPORT)
endif()

target_link_libraries(manifoldc PRIVATE manifold)

target_include_directories(manifoldc PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/bindings/c/include>
)
target_compile_options(manifoldc PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(manifoldc PRIVATE cxx_std_17)

install(TARGETS manifoldc EXPORT manifoldTargets)
install(FILES
include/manifold/manifoldc.h
include/manifold/types.h DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/manifold)

# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
File renamed without changes.
8 changes: 0 additions & 8 deletions src/conv.cpp → bindings/c/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include <vector>

#include "manifold/common.h"
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "manifold/manifold.h"
#include "manifold/types.h"

Expand All @@ -31,15 +29,13 @@ ManifoldManifoldVec *to_c(ManifoldVec *ms) {
return reinterpret_cast<ManifoldManifoldVec *>(ms);
}

#ifdef MANIFOLD_CROSS_SECTION
ManifoldCrossSection *to_c(manifold::CrossSection *cs) {
return reinterpret_cast<ManifoldCrossSection *>(cs);
}

ManifoldCrossSectionVec *to_c(CrossSectionVec *csv) {
return reinterpret_cast<ManifoldCrossSectionVec *>(csv);
}
#endif

ManifoldSimplePolygon *to_c(manifold::SimplePolygon *m) {
return reinterpret_cast<ManifoldSimplePolygon *>(m);
Expand Down Expand Up @@ -136,15 +132,13 @@ ManifoldVec *from_c(ManifoldManifoldVec *ms) {
return reinterpret_cast<ManifoldVec *>(ms);
}

#ifdef MANIFOLD_CROSS_SECTION
const manifold::CrossSection *from_c(ManifoldCrossSection *cs) {
return reinterpret_cast<manifold::CrossSection *>(cs);
}

CrossSectionVec *from_c(ManifoldCrossSectionVec *csv) {
return reinterpret_cast<CrossSectionVec *>(csv);
}
#endif

const manifold::SimplePolygon *from_c(ManifoldSimplePolygon *m) {
return reinterpret_cast<manifold::SimplePolygon const *>(m);
Expand Down Expand Up @@ -173,7 +167,6 @@ OpType from_c(ManifoldOpType optype) {
return op;
}

#ifdef MANIFOLD_CROSS_SECTION
CrossSection::FillRule from_c(ManifoldFillRule fillrule) {
auto fr = CrossSection::FillRule::EvenOdd;
switch (fillrule) {
Expand Down Expand Up @@ -206,7 +199,6 @@ CrossSection::JoinType from_c(ManifoldJoinType join_type) {
};
return jt;
}
#endif

const manifold::Box *from_c(ManifoldBox *m) {
return reinterpret_cast<manifold::Box const *>(m);
Expand Down
10 changes: 0 additions & 10 deletions src/conv.h → bindings/c/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,18 @@
#include <vector>

#include "manifold/common.h"
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "manifold/manifold.h"
#include "manifold/types.h"

using namespace manifold;
using ManifoldVec = std::vector<Manifold>;
#ifdef MANIFOLD_CROSS_SECTION
using CrossSectionVec = std::vector<CrossSection>;
#endif

ManifoldManifold *to_c(manifold::Manifold *m);
ManifoldManifoldVec *to_c(ManifoldVec *ms);
#ifdef MANIFOLD_CROSS_SECTION
ManifoldCrossSection *to_c(manifold::CrossSection *cs);
ManifoldCrossSectionVec *to_c(CrossSectionVec *csv);
#endif
ManifoldSimplePolygon *to_c(manifold::SimplePolygon *p);
ManifoldPolygons *to_c(manifold::Polygons *ps);
ManifoldMeshGL *to_c(manifold::MeshGL *m);
Expand All @@ -48,18 +42,14 @@ ManifoldProperties to_c(manifold::Properties p);

const manifold::Manifold *from_c(ManifoldManifold *m);
ManifoldVec *from_c(ManifoldManifoldVec *ms);
#ifdef MANIFOLD_CROSS_SECTION
const manifold::CrossSection *from_c(ManifoldCrossSection *cs);
CrossSectionVec *from_c(ManifoldCrossSectionVec *csv);
#endif
const manifold::SimplePolygon *from_c(ManifoldSimplePolygon *m);
const manifold::Polygons *from_c(ManifoldPolygons *m);
const manifold::MeshGL *from_c(ManifoldMeshGL *m);
OpType from_c(ManifoldOpType op);
#ifdef MANIFOLD_CROSS_SECTION
CrossSection::FillRule from_c(ManifoldFillRule fillrule);
CrossSection::JoinType from_c(ManifoldJoinType jt);
#endif
const manifold::Box *from_c(ManifoldBox *m);
const manifold::Rect *from_c(ManifoldRect *r);
vec2 from_c(ManifoldVec2 v);
Expand Down
2 changes: 1 addition & 1 deletion src/cross_section/cross.cpp → bindings/c/cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "../conv.h"
#include "./conv.h"
#include "manifold/common.h"
#include "manifold/cross_section.h"
#include "manifold/types.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ ManifoldManifold *manifold_calculate_normals(void *mem, ManifoldManifold *m,
int min_sharp_angle);

// CrossSection Shapes/Constructors
#ifdef MANIFOLD_CROSS_SECTION
ManifoldCrossSection *manifold_cross_section_empty(void *mem);
ManifoldCrossSection *manifold_cross_section_copy(void *mem,
ManifoldCrossSection *cs);
Expand Down Expand Up @@ -300,7 +299,6 @@ ManifoldRect *manifold_cross_section_bounds(void *mem,
ManifoldCrossSection *cs);
ManifoldPolygons *manifold_cross_section_to_polygons(void *mem,
ManifoldCrossSection *cs);
#endif // MANIFOLD_CROSS_SECTION

// Rectangle

Expand Down
File renamed without changes.
8 changes: 0 additions & 8 deletions src/manifoldc.cpp → bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

#include "./conv.h"
#include "manifold/common.h"
#ifdef MANIFOLD_CROSS_SECTION
#include "manifold/cross_section.h"
#endif
#include "manifold/manifold.h"
#include "manifold/types.h"

Expand Down Expand Up @@ -588,12 +586,10 @@ int manifold_get_circular_segments(double radius) {
void manifold_reset_to_circular_defaults() { Quality::ResetToDefaults(); }

// memory size
#ifdef MANIFOLD_CROSS_SECTION
size_t manifold_cross_section_size() { return sizeof(CrossSection); }
size_t manifold_cross_section_vec_size() {
return sizeof(std::vector<CrossSection>);
}
#endif
size_t manifold_simple_polygon_size() { return sizeof(SimplePolygon); }
size_t manifold_polygons_size() { return sizeof(Polygons); }
size_t manifold_manifold_size() { return sizeof(Manifold); }
Expand All @@ -604,14 +600,12 @@ size_t manifold_box_size() { return sizeof(Box); }
size_t manifold_rect_size() { return sizeof(Rect); }

// pointer free + destruction
#ifdef MANIFOLD_CROSS_SECTION
void manifold_delete_cross_section(ManifoldCrossSection *c) {
delete from_c(c);
}
void manifold_delete_cross_section_vec(ManifoldCrossSectionVec *csv) {
delete from_c(csv);
}
#endif
void manifold_delete_simple_polygon(ManifoldSimplePolygon *p) {
delete from_c(p);
}
Expand All @@ -625,14 +619,12 @@ void manifold_delete_box(ManifoldBox *b) { delete from_c(b); }
void manifold_delete_rect(ManifoldRect *r) { delete from_c(r); }

// destruction
#ifdef MANIFOLD_CROSS_SECTION
void manifold_destruct_cross_section(ManifoldCrossSection *cs) {
from_c(cs)->~CrossSection();
}
void manifold_destruct_cross_section_vec(ManifoldCrossSectionVec *csv) {
from_c(csv)->~CrossSectionVec();
}
#endif
void manifold_destruct_simple_polygon(ManifoldSimplePolygon *p) {
from_c(p)->~SimplePolygon();
}
Expand Down
2 changes: 1 addition & 1 deletion src/meshIO/meshIOc.cpp → bindings/c/meshIOc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "../conv.h"
#include "./conv.h"
#include "manifold/meshIO.h"
#include "manifold/types.h"

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
];
cmakeFlags = [
"-DMANIFOLD_PYBIND=ON"
"-DMANIFOLD_CBIND=ON"
"-DMANIFOLD_EXPORT=ON"
"-DBUILD_SHARED_LIBS=ON"
"-DMANIFOLD_PAR=${pkgs.lib.strings.toUpper parallel-backend}"
Expand Down
6 changes: 0 additions & 6 deletions include/manifold/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ set(MANIFOLD_PUBLIC_HDRS
vec_view.h
)

set(MANIFOLD_C_BINDING_HDRS
manifoldc.h
types.h
)
list(APPEND MANIFOLD_PUBLIC_HDRS ${MANIFOLD_C_BINDING_HDRS})

if (MANIFOLD_CROSS_SECTION)
list(APPEND MANIFOLD_PUBLIC_HDRS cross_section.h)
endif()
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build-backend = "scikit_build_core.build"
cmake.minimum-version = "3.18"
sdist.exclude = [
".github",
"bindings/c",
"bindings/wasm",
"docs",
"extras",
Expand All @@ -43,7 +44,7 @@ sdist.exclude = [
"oneTBB", # we may have this when we build with cibuildwheel
]
wheel.packages = ["manifold3d"]
cmake.args = ["-DMANIFOLD_PYBIND=ON", "-DMANIFOLD_PAR=ON", "-DMANIFOLD_TEST=OFF", "-DBUILD_SHARED_LIBS=OFF"]
cmake.args = ["-DMANIFOLD_PYBIND=ON", "-DMANIFOLD_CBIND=OFF", "-DMANIFOLD_PAR=ON", "-DMANIFOLD_TEST=OFF", "-DBUILD_SHARED_LIBS=OFF"]
install.components = ["bindings"]

[tool.cibuildwheel]
Expand Down
18 changes: 0 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,15 @@ set(MANIFOLD_PRIVATE_HDRS
vec.h
)

set(MANIFOLD_C_BINDING_SRCS
manifoldc.cpp
conv.cpp
box.cpp
rect.cpp
)
list(APPEND MANIFOLD_SRCS ${MANIFOLD_C_BINDING_SRCS})

set(MANIFOLD_C_BINDING_PRIVATE_HDRS
conv.h
)
list(APPEND MANIFOLD_PRIVATE_HDRS ${MANIFOLD_C_BINDING_PRIVATE_HDRS})

if(MANIFOLD_CROSS_SECTION)
list(APPEND MANIFOLD_SRCS
cross_section/cross_section.cpp
cross_section/cross.cpp
)
endif()

if(MANIFOLD_EXPORT)
list(APPEND MANIFOLD_SRCS
meshIO/meshIO.cpp
meshIO/meshIOc.cpp
)
endif()

Expand Down Expand Up @@ -119,9 +104,6 @@ target_include_directories(manifold PUBLIC
if(MANIFOLD_EXCEPTIONS)
target_compile_options(manifold PRIVATE -DMANIFOLD_EXCEPTIONS=1)
endif()
if(MANIFOLD_CROSS_SECTION)
target_compile_options(manifold PRIVATE -DMANIFOLD_CROSS_SECTION)
endif()
if(MANIFOLD_DEBUG)
target_compile_options(manifold PRIVATE -DMANIFOLD_DEBUG)
endif()
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ if(MANIFOLD_FUZZ)
gtest_discover_tests(polygon_fuzz)
endif()

if(MANIFOLD_CBIND AND NOT EMSCRIPTEN)
target_link_libraries(manifold_test manifoldc)
endif()

if(MANIFOLD_CROSS_SECTION)
target_compile_options(manifold_test PUBLIC -DMANIFOLD_CROSS_SECTION)
endif()
Expand Down

0 comments on commit 3c8d486

Please sign in to comment.