Skip to content

Commit

Permalink
test wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Jul 29, 2023
1 parent 59760b3 commit 5cbe93d
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 7 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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/cibuildwheel@v2.14.1
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1)
endif()

option(PYBIND11_FINDPYTHON "Enable PyBind to perform FindPython for you" ON)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

option(BUILD_TEST_CGAL "Build CGAL performance comparisons" OFF)

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/third_party/pybind11
Submodule pybind11 updated 113 files
14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@
cuda-support = true;
}
]);
manifold3d = ps: with ps; buildPythonPackage {
name = "manifold3d";
src = self;
nativeBuildInputs = with pkgs; [ cmake ninja pkg-config trimesh ];
buildInputs = with pkgs; [ tbb ];
# not sure why this is needed...
preBuild = ''
cd ..
'';
checkPhase = ''
python bindings/python/examples/run_all.py
'';
};
devShell = { additional ? [ ] }: pkgs.mkShell {
buildInputs = with pkgs; [
cmake
Expand Down Expand Up @@ -116,6 +129,7 @@
cp {extras,wasm}/*.wasm $out/
'';
};
manifold3d = manifold3d pkgs.python3Packages;
};
devShell = devShell { };
devShells.cuda = devShell {
Expand Down
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[project]
name = "manifold3d_elalish"
version = "2.2.0"
authors = [
{ name="Emmett Lalish", email="elalish@gmail.com" },
]
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",
]

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

[build-system]
requires = ["setuptools>=61.0", "wheel", "cmake>=3.12", "ninja"]
build-backend = "setuptools.build_meta"

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

[tool.cibuildwheel.linux]
before-build = "yum install -y tbb-devel"
environment = { LD_LIBRARY_PATH = "/usr/local/lib/" }

[tool.cibuildwheel.macos]
before-build = "brew install tbb pkg-config"
archs = ["x86_64", "arm64"]
environment = "MACOSX_DEPLOYMENT_TARGET=10.14"

[tool.cibuildwheel.windows]
before-build = "pip install delvewheel"
repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel}"

148 changes: 148 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
See https://github.com/pybind/cmake_example
"""
import os
import re
import subprocess
import sys
from pathlib import Path

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
"win32": "Win32",
"win-amd64": "x64",
"win-arm32": "ARM",
"win-arm64": "ARM64",
}


# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: str = "./") -> None:
super().__init__(name, sources=[], py_limited_api=True)
self.sourcedir = os.fspath(Path(sourcedir).resolve())


class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()

# Using this requires trailing slash for auto-detection & inclusion of
# auxiliary "native" libs

debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"

# CMake lets you override the generator - we need to check this.
# Can be set with Conda-Build, for example.
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
# from Python.
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
f"-DMANIFOLD_PYBIND=ON",
f"-DBUILD_SHARED_LIBS=ON",
]
if os.name == 'nt':
build_args += "--target ALL_BUILD".split(" ")
else:
cmake_args.append("-DMANIFOLD_PAR=TBB")
build_args = []
# Adding CMake arguments set as environment variable
# (needed e.g. to build for ARM OSx on conda-forge)
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

# In this example, we pass in the version to C++. You might not need to.
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"]

if self.compiler.compiler_type != "msvc":
# Using Ninja-build since it a) is available as a wheel and b)
# multithreads automatically. MSVC would require all variables be
# exported for Ninja to pick it up, which is a little tricky to do.
# Users can override the generator with CMAKE_GENERATOR in CMake
# 3.15+.
if not cmake_generator or cmake_generator == "Ninja":
try:
import ninja

ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
cmake_args += [
"-GNinja",
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
]
except ImportError:
pass

else:
# Single config generators are handled "normally"
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})

# CMake allows an arch-in-generator style for backward compatibility
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

# Specify the arch if using MSVC generator, but only if it doesn't
# contain a backward-compatibility arch spec already in the
# generator name.
if not single_config and not contains_arch:
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

# Multi-config generators have a different way to specify configs
if not single_config:
cmake_args += [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
]
build_args += ["--config", cfg]

if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
if hasattr(self, "parallel") and self.parallel:
# CMake 3.12+ only.
build_args += [f"-j{self.parallel}"]

build_temp = Path(self.build_temp) / "bindings" / "python" / ext.name
if not build_temp.exists():
build_temp.mkdir(parents=True)

subprocess.run(
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
)
subprocess.run(
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
)


# The information here can also be placed in setup.cfg - better separation of
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="manifold3d",
version="2.2.0",
author="Emmett Lalish",
author_email="elalish@gmail.com",
description="Geometry library for topological robustness ",
long_description="",
ext_modules=[CMakeExtension("manifold3d")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
python_requires=">=3.8",
)
15 changes: 10 additions & 5 deletions src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ if(MANIFOLD_PAR STREQUAL "OMP")
target_compile_options(${PROJECT_NAME} PUBLIC -DMANIFOLD_PAR='O' -fopenmp)
target_link_options(${PROJECT_NAME} PUBLIC -fopenmp)
elseif(MANIFOLD_PAR STREQUAL "TBB")
find_package(PkgConfig REQUIRED)
pkg_check_modules(TBB REQUIRED tbb)
target_include_directories(${PROJECT_NAME} PUBLIC ${TBB_INCLUDE_DIRS})
find_package(TBB)
if (NOT TBB_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(TBB REQUIRED tbb)
target_include_directories(${PROJECT_NAME} PUBLIC ${TBB_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${TBB_LINK_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME} PUBLIC TBB::tbb)
endif()
target_compile_options(${PROJECT_NAME} PUBLIC -DMANIFOLD_PAR='T')
target_link_libraries(${PROJECT_NAME} PUBLIC ${TBB_LINK_LIBRARIES})
elseif(MANIFOLD_PAR STREQUAL "NONE")
set(MANIFOLD_PAR "CPP")
else()
Expand Down Expand Up @@ -63,4 +68,4 @@ if(MANIFOLD_DEBUG)
PUBLIC -DMANIFOLD_DEBUG)
endif()

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)

0 comments on commit 5cbe93d

Please sign in to comment.