-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "OpenCTM"] | ||
path = upstream/OpenCTM | ||
url = https://github.com/Danny02/OpenCTM.git |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# openctm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" | ||
build-ctypes | ||
For a ctypes binding it is compiled on a specific platform | ||
but does not need to be recompiled for every version of Python. | ||
`cibuildwheel` isn't set up for this necessarily so we will | ||
do some level of manual wangling here. | ||
# Steps | ||
- build the wheel with `pip wheel` | ||
- build the library for the current platform using subprocess | ||
- inject the library into the wheel | ||
- fix the wheel tags to be py3 | ||
""" | ||
import os | ||
import zipfile | ||
import tempfile | ||
import platform | ||
import subprocess | ||
|
||
cwd = os.path.abspath(os.path.dirname(__file__)) | ||
ctm_lib = os.path.join(cwd, 'upstream', 'OpenCTM', 'lib') | ||
|
||
def build_manylinux(image: str): | ||
""" | ||
Build OpenCTM on a manylinux image. | ||
""" | ||
|
||
# remove any prior built artifacts from the library | ||
subprocess.check_call(['git', 'clean', '-xdf'], | ||
cwd=ctm_lib) | ||
|
||
# compose a docker command to run | ||
command = ['docker', 'run', | ||
'-v', f'{ctm_lib}:/ctmlib', | ||
'-w', '/ctmlib', | ||
image, | ||
'make -f Makefile.linux'] | ||
print(' '.join(command)) | ||
|
||
# build in the manylinux image | ||
# not sure why this doesn't work as a non-shell command | ||
subprocess.check_call(' '.join(command), shell=True) | ||
|
||
libname = 'libopenctm.so' | ||
with open(os.path.join(ctm_lib, libname), 'rb') as f: | ||
return {libname: f.read()} | ||
|
||
|
||
|
||
|
||
def to_wheel(libs: dict): | ||
|
||
with tempfile.TemporaryDirectory() as tmp: | ||
subprocess.check_call(['pip', 'wheel', '.', f'--wheel-dir={tmp}']) | ||
|
||
# there should only be one file in this temp directory | ||
wheel_name = os.listdir(tmp)[-1] | ||
file_name = os.path.join(tmp, wheel_name) | ||
assert file_name.endswith('.whl') | ||
|
||
# append the requested libraries to the zip archive | ||
with zipfile.ZipFile(file_name, 'a') as zipped: | ||
for lib, raw in libs.items(): | ||
zipped.writestr(f'openctm./{lib}', raw) | ||
|
||
with open(file_name, 'rb') as f: | ||
return {wheel_name: f.read()} | ||
|
||
def main(): | ||
|
||
wheelhouse = os.path.join(cwd, 'wheelhouse') | ||
os.makedirs(wheelhouse, exist_ok=True) | ||
|
||
if platform.system() == 'Linux': | ||
# build on specific manylinux tag images | ||
manylinux = ['quay.io/pypa/manylinux2014_x86_64', | ||
'quay.io/pypa/manylinux2014_i686'] | ||
for image in manylinux: | ||
tag_platform = image.rsplit('/', 1)[-1] | ||
wheel = to_wheel(build_manylinux(image)) | ||
tag_none = next(iter(wheel.keys())) | ||
# keep the `none` ABI | ||
# replace the `any` platform with manylinux | ||
tag_new = tag_none.replace('any', tag_platform) | ||
|
||
with open(os.path.join(wheelhouse, tag_new), 'wb') as f: | ||
f.write(wheel[tag_none]) | ||
|
||
elif platform.system() == 'Windows': | ||
build_windows() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[build-system] | ||
build-backend = "setuptools.build_meta" | ||
requires = ["setuptools >= 61.0", "wheel"] | ||
|
||
[project] | ||
name = "openctm" | ||
version = "0.0.1" | ||
requires-python = ">=3.7" | ||
authors = [{name = "Michael Dawson-Haggerty", email = "[email protected]"}] | ||
license = {file = "LICENSE.md"} | ||
description = "Provide a loader for OpenCTM files" | ||
keywords = ["graphics", "OpenCTM"] | ||
classifiers = [ | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Natural Language :: English", | ||
"Topic :: Scientific/Engineering", | ||
"Topic :: Multimedia :: Graphics", | ||
"Topic :: Multimedia :: Graphics :: 3D Modeling" | ||
] | ||
urls = {Homepage = "https://github.com/trimesh/cascadio"} | ||
|
||
[project.readme] | ||
file = "README.md" | ||
content-type = "text/markdown" | ||
|
||
[tool.setuptools] | ||
packages = [ | ||
"openctm", | ||
] | ||
|
||
[project.optional-dependencies] | ||
tests = ["pytest", "trimesh"] | ||
|
||
[tool.cibuildwheel] | ||
# `yum` would need to be replaced in the `before-all` | ||
# script before the musl linux can build OpenCASCADE | ||
skip = "*musl*" | ||
|
||
[tool.cibuildwheel.linux] | ||
# build OCCT on linux from source on the manylinux image | ||
before-all = [ | ||
'cd OpenCTM', | ||
'git clean -xdf', | ||
'cd lib', | ||
'make -f Makefile.linux' | ||
] | ||
|
||
test-extras = "tests" | ||
test-command = "pytest {project}/tests" | ||
|
||
# point auditwheel at the OCCT libraries | ||
repair-wheel-command = "LD_LIBRARY_PATH=/project/OpenCTM/lib auditwheel repair --lib-sdir . -w {dest_dir} {wheel}" |