Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build Python wheel #521

Closed
wants to merge 15 commits into from
23 changes: 23 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build

on: [push, pull_request]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
steps:
- run: git config --global submodule.fetchJobs 8
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Build wheels
uses: pypa/[email protected]
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we upload the artifact to the wheelhouse, but what do with it? Should we add a release action? Should we try TestPyPI first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



11 changes: 11 additions & 0 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,14 @@ jobs:
submodules: recursive
- uses: cachix/install-nix-action@v15
- run: nix build -L '.?submodules=1#manifold-${{matrix.variant}}'

build_nix_python:
timeout-minutes: 30
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: cachix/install-nix-action@v15
- run: nix build -L '.?submodules=1#manifold3d'
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ else()
option(CMAKE_BUILD_TYPE "Build type" Release)
endif()

set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -O3)
if(NOT MSVC)
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -O3)
endif()

if(EMSCRIPTEN)
message("Building for Emscripten")
Expand Down
24 changes: 17 additions & 7 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@
project(python)

add_subdirectory(third_party)
pybind11_add_module(manifold3d manifold3d.cpp)
target_link_libraries(manifold3d PRIVATE manifold)
target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(manifold3d PUBLIC cxx_std_17)
target_include_directories(manifold3d
set(module_name manifold3d)
pybind11_add_module(${module_name} manifold3d.cpp)
target_link_libraries(${module_name} PRIVATE manifold)
target_compile_options(${module_name} PRIVATE ${MANIFOLD_FLAGS}
-DMODULE_NAME=${module_name})
target_compile_features(${module_name} PUBLIC cxx_std_17)
target_include_directories(${module_name}
PRIVATE ${PYBIND11_DIR}/include
)
set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d")
set_target_properties(${module_name} PROPERTIES OUTPUT_NAME "${module_name}")
if(SKBUILD)
install(
TARGETS manifold3d
TARGETS ${module_name}
LIBRARY DESTINATION ${SKBUILD_PLATLIB_DIR}
COMPONENT bindings
)
else()
install(
TARGETS ${module_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
COMPONENT bindings
)
endif()
12 changes: 6 additions & 6 deletions bindings/python/examples/extrude.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from manifold3d import CrossSection, FillRule
from manifold3d import CrossSection


def run():
Expand All @@ -11,28 +11,28 @@ def run():
polygons = cross_section.to_polygons()
polygon = polygons[0]
if set(polygon) != set(polygon_points):
raise Exception(f"{polygon=} differs from {polygon_points=}")
raise Exception(f"polygon={polygon} differs from polygon_points={polygon_points}")

# extrude a polygon to create a manifold
extruded_polygon = cross_section.extrude(10.0)
eps = 0.001
observed_volume = extruded_polygon.get_volume()
expected_volume = 10.0
if abs(observed_volume - expected_volume) > eps:
raise Exception(f"{observed_volume=} differs from {expected_volume=}")
raise Exception(f"observed_volume={observed_volume} differs from expected_volume={expected_volume}")
observed_surface_area = extruded_polygon.get_surface_area()
expected_surface_area = 42.0
if abs(observed_surface_area - expected_surface_area) > eps:
raise Exception(f"{observed_surface_area=} differs from {expected_surface_area=}")
raise Exception(f"observed_surface_area={observed_surface_area} differs from expected_surface_area={expected_surface_area}")

# get bounding box from manifold
observed_bbox = extruded_polygon.bounding_box
expected_bbox = (0.0, 0.0, 0.0, 1.0, 1.0, 10.0)
if observed_bbox != expected_bbox:
raise Exception(f"{observed_bbox=} differs from {expected_bbox=}")
raise Exception(f"observed_bbox={observed_bbox} differs from expected_bbox={expected_bbox}")

return extruded_polygon


if __name__ == "__main__":
run()
run()
2 changes: 1 addition & 1 deletion bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::vector<T> toVector(const py::array_t<T> &arr) {
return std::vector<T>(arr.data(), arr.data() + arr.size());
}

PYBIND11_MODULE(manifold3d, m) {
PYBIND11_MODULE(MODULE_NAME, m) {
m.doc() = "Python binding for the Manifold library.";

m.def("set_min_circular_angle", Quality::SetMinCircularAngle,
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}: pkgs.stdenv.mkDerivation {
inherit doCheck;
pname = "manifold-${parallel-backend}";
version = "beta";
version = "2.2.0";
src = self;
nativeBuildInputs = (with pkgs; [
cmake
Expand Down Expand Up @@ -101,6 +101,36 @@
cp {extras,wasm}/*.wasm $out/
'';
};
# but how should we make it work with other python versions?
manifold3d = with pkgs.python3Packages; buildPythonPackage {
pname = "manifold3d";
version = "2.2.0";
src = self;
propagatedBuildInputs = [
numpy
];
buildInputs = with pkgs; [
tbb
];
nativeBuildInputs = with pkgs; [
cmake
ninja
setuptools
scikit-build-core
pyproject-metadata
pathspec
pkg-config
];
checkInputs = [
trimesh
];
format = "pyproject";
dontUseCmakeConfigure = true;
doCheck = true;
checkPhase = ''
python3 bindings/python/examples/run_all.py
'';
};
};
devShell = devShell { };
}
Expand Down
93 changes: 93 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[project]
name = "manifold3d"
version = "2.2.0"
authors = [
{ name="Emmett Lalish", email="[email protected]" },
]
description = "Library for geometric robustness"
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: C++",
"Topic :: Multimedia :: Graphics :: 3D Modeling",
]
requires-python = ">=3.7"

dependencies = [
"numpy; python_version<'3.12'",
"numpy>=1.26.0b1; python_version>='3.12'"
]

[project.urls]
"Homepage" = "https://github.com/elalish/manifold"
"Bug Tracker" = "https://github.com/elalish/manifold/issues"

[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
cmake.minimum-version = "3.18"
sdist.exclude = [
".github",
"bindings/c",
"bindings/wasm",
"docs",
"extras",
"meshIO",
"samples",
"test",
"oneTBB", # we may have this when we build with cibuildwheel
"bindings/python/third_party/pybind11/tests/",
"src/third_party/clipper2/CPP/Examples/",
"src/third_party/clipper2/CPP/Tests/",
"src/third_party/clipper2/CSharp/",
"src/third_party/clipper2/Delphi/",
"src/third_party/clipper2/DLL/",
"src/third_party/clipper2/Tests/",
"src/third_party/glm/doc/",
"src/third_party/glm/test/",
"src/third_party/thrust/dependencies/cub/",
"src/third_party/thrust/dependencies/libcudacxx/.upstream-tests/",
"src/third_party/thrust/dependencies/libcudacxx/docker/",
"src/third_party/thrust/dependencies/libcudacxx/test/",
"src/third_party/thrust/dependencies/libcudacxx/docs/",
"src/third_party/thrust/dependencies/libcudacxx/libcxx/",
"src/third_party/thrust/dependencies/libcudacxx/libcxxabi/",
"src/third_party/thrust/dependencies/libcudacxx/libunwind/",
"src/third_party/thrust/dependencies/libcudacxx/utils/google-benchmark/",
"src/third_party/thrust/docs/",
"src/third_party/thrust/testing/",
"src/third_party/thrust/internal/test/",
"src/third_party/thrust/examples/",
"src/third_party/thrust/thrust/system/cuda",
]
wheel.packages = ["manifold3d"]
cmake.args = ["-DMANIFOLD_PAR=TBB", "-DMANIFOLD_TEST=OFF"]
install.components = ["bindings"]

[tool.cibuildwheel]
build-frontend = "build"
test-requires = ["trimesh"]
test-command = "python {project}/bindings/python/examples/run_all.py"
# Setuptools bug causes collision between pypy and cpython artifacts
manylinux-x86_64-image = "manylinux_2_28"
musllinux-x86_64-image = "musllinux_1_2"
skip = ["*-win32", "*_i686", "pp*", "*-musllinux*"]

# only clone TBB once
before-all = "git clone --depth 1 --branch v2021.10.0 https://github.com/oneapi-src/oneTBB.git"
[tool.cibuildwheel.config-settings]
"cmake.define.FETCHCONTENT_SOURCE_DIR_TBB" = "./oneTBB"
"cmake.define.FETCHCONTENT_UPDATES_DISCONNECTED" = "ON"

[tool.cibuildwheel.macos]
archs = ["x86_64", "arm64"]
environment = "MACOSX_DEPLOYMENT_TARGET=10.14"
test-skip = "*-macosx_arm64 *-macosx_universal2:arm64"

[tool.cibuildwheel.windows]
before-build = "pip install delvewheel"
repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel}"
2 changes: 1 addition & 1 deletion src/cross_section/src/cross_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ std::shared_ptr<const PathImpl> CrossSection::GetPaths() const {
if (transform_ == glm::mat3x2(1.0f)) {
return paths_;
}
paths_ = shared_paths(transform(paths_->paths_, transform_));
paths_ = shared_paths(::transform(paths_->paths_, transform_));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does :: do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It search for the transform function defined in the anonymous namespace. By default it should search for the one in the current namespace, i.e. the transform function defined in par.
I found this error when I was experimenting with precompiled headers (minor compile time improvement)

transform_ = glm::mat3x2(1.0f);
return paths_;
}
Expand Down
2 changes: 0 additions & 2 deletions src/manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include "impl.h"

#include <thrust/logical.h>

#include <algorithm>
#include <atomic>
#include <map>
Expand Down
4 changes: 0 additions & 4 deletions src/manifold/src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <thrust/count.h>
#include <thrust/logical.h>
#include <thrust/transform_reduce.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


#include <limits>

#include "impl.h"
Expand Down
2 changes: 0 additions & 2 deletions src/manifold/src/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <thrust/sequence.h>

#include <atomic>
#include <numeric>
#include <set>
Expand Down
1 change: 1 addition & 0 deletions src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if(MANIFOLD_PAR STREQUAL "TBB")
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(TBB)
set_property(DIRECTORY ${TBB_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
endif()
target_compile_options(${PROJECT_NAME} INTERFACE -DMANIFOLD_PAR='T')
if(TARGET TBB::tbb)
Expand Down
6 changes: 3 additions & 3 deletions test/boolean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ TEST(Boolean, BooleanVolumes) {
// m7 = m1 + m2 + m3
auto m1 = Manifold::Cube({1, 1, 1});
auto m2 = Manifold::Cube({2, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0, 0)));
glm::mat4x3(glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0, 0))));
auto m4 = Manifold::Cube({4, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(3.0f, 0, 0)));
glm::mat4x3(glm::translate(glm::mat4(1.0f), glm::vec3(3.0f, 0, 0))));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're using Transform instead of Translate directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I found that we actually set GLM_FORCE_EXPLICIT_CTOR in public.h, and compile with precompiled header will cause errors. I think it is something related to include order which causes it to pass compilation in normal builds, but error when I tried using precompiled header.

auto m3 = Manifold::Cube({3, 1, 1});
auto m7 = Manifold::Cube({7, 1, 1});

Expand Down Expand Up @@ -906,4 +906,4 @@ TEST(Boolean, Sweep) {
#endif

PolygonParams().processOverlaps = false;
}
}
2 changes: 1 addition & 1 deletion test/cross_section_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST(CrossSection, Transform) {
0.0f, 3.0f, 0.0f, //
0.0f, 0.0f, 1.0f);

auto b = sq.Transform(trans * scale * rot);
auto b = sq.Transform(glm::mat3x2(trans * scale * rot));
auto b_copy = CrossSection(b);

auto ex_b = Manifold::Extrude(b, 1.).GetMesh();
Expand Down
2 changes: 1 addition & 1 deletion test/manifold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ TEST(Manifold, Invalid) {
auto invalid = Manifold::Error::InvalidConstruction;
auto circ = CrossSection::Circle(10.);
auto empty_circ = CrossSection::Circle(-2.);
auto empty_sq = CrossSection::Square(glm::vec3(0.0f));
auto empty_sq = CrossSection::Square(glm::vec2(0.0f));

EXPECT_EQ(Manifold::Sphere(0).Status(), invalid);
EXPECT_EQ(Manifold::Cylinder(0, 5).Status(), invalid);
Expand Down
Loading