Skip to content

Commit 3be3eec

Browse files
lhoestqkszucs
authored andcommitted
add poetry build for libviewer
1 parent b90295a commit 3be3eec

File tree

4 files changed

+563
-3
lines changed

4 files changed

+563
-3
lines changed

libs/libviewer/build-extension.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import shlex
3+
import shutil
4+
import subprocess
5+
import zipfile
6+
7+
from pathlib import Path
8+
9+
10+
def maturin(*args):
11+
subprocess.call(["maturin", *list(args)])
12+
13+
14+
def build():
15+
build_dir = Path(__file__).parent.joinpath("build")
16+
build_dir.mkdir(parents=True, exist_ok=True)
17+
18+
wheels_dir = Path(__file__).parent.joinpath("target/wheels")
19+
if wheels_dir.exists():
20+
shutil.rmtree(wheels_dir)
21+
22+
cargo_args = []
23+
if os.getenv("MATURIN_BUILD_ARGS"):
24+
cargo_args = shlex.split(os.getenv("MATURIN_BUILD_ARGS", ""))
25+
26+
maturin("build", "-r", *cargo_args)
27+
28+
# We won't use the wheel built by maturin directly since
29+
# we want Poetry to build it, but we need to retrieve the
30+
# compiled extensions from the maturin wheel.
31+
wheel = next(iter(wheels_dir.glob("*.whl")))
32+
with zipfile.ZipFile(wheel.as_posix()) as whl:
33+
whl.extractall(wheels_dir.as_posix())
34+
35+
for extension in wheels_dir.rglob("**/*.so"):
36+
shutil.copyfile(extension, Path(__file__).parent.joinpath("libviewer", extension.name))
37+
38+
shutil.rmtree(wheels_dir)
39+
40+
41+
if __name__ == "__main__":
42+
build()

0 commit comments

Comments
 (0)