Skip to content

Commit a208201

Browse files
authored
"Stateful" C library + Python bindings (using cython) and JS bindings (using embind) (#1343)
1 parent 33f9cf9 commit a208201

24 files changed

+3278
-311
lines changed

.github/scripts/build-wasmlib.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
cd ..
4+
git clone https://github.com/emscripten-core/emsdk.git --depth 1
5+
cd emsdk
6+
./emsdk install latest
7+
./emsdk activate latest
8+
cd ../solvespace
9+
source ../emsdk/emsdk_env.sh
10+
mkdir build-wasmlib || true
11+
cd build-wasmlib
12+
emcmake cmake .. \
13+
-DCMAKE_RELEASE_TYPE=Debug \
14+
-DENABLE_GUI="OFF" \
15+
-DENABLE_CLI="OFF" \
16+
-DENABLE_TESTS="OFF" \
17+
-DENABLE_COVERAGE="OFF" \
18+
-DENABLE_OPENMP="OFF" \
19+
-DFORCE_VENDORED_Eigen3="ON" \
20+
-DENABLE_LTO="ON" \
21+
-DENABLE_EMSCRIPTEN_LIB="ON"
22+
cmake --build . -j$(nproc)

.github/workflows/python.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: Python
2+
3+
on:
4+
push:
5+
branches: [ master, python, experiments, stateful-c-lib ]
6+
tags: [ v* ]
7+
8+
jobs:
9+
python-sdist:
10+
name: python sdist
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- run: git submodule update --init extlib/mimalloc extlib/eigen
15+
- uses: actions/setup-python@v3
16+
with:
17+
python-version: "3.10"
18+
- name: Pack
19+
shell: bash
20+
run: |
21+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
22+
version="${GITHUB_REF##*/}"
23+
else
24+
mkdir empty-build
25+
cd empty-build
26+
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
27+
source version.env
28+
cd ..
29+
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.dev${GITHUB_RUN_NUMBER}"
30+
fi
31+
sed -i.bak "s/^version = .*/version = \"${version}\"/g" pyproject.toml && rm pyproject.toml.bak
32+
python -m pip install -U setuptools build
33+
python -m build --sdist
34+
- name: Upload artifact
35+
uses: actions/upload-artifact@v3
36+
with:
37+
name: sdist
38+
path: dist/*.tar.gz
39+
python-wheel:
40+
name: ${{ matrix.os_short }} python ${{ matrix.architecture }} cp${{ matrix.python_version }}
41+
runs-on: ${{ matrix.os }}
42+
timeout-minutes: 240
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
os_arch: [
47+
"windows-ia32",
48+
"windows-x64",
49+
# "windows-arm64",
50+
"macos-x86_64",
51+
"macos-arm64",
52+
"linux-x86_64",
53+
"linux-aarch64",
54+
]
55+
python_version: [
56+
"37",
57+
"38",
58+
"39",
59+
"310",
60+
"311",
61+
]
62+
exclude:
63+
- os_arch: "macos-arm64"
64+
python_version: "37"
65+
include:
66+
- os_arch: "windows-ia32"
67+
os: "windows-2022"
68+
os_short: "windows"
69+
architecture: "ia32"
70+
cibuildwheel_architecture: "x86"
71+
cmake_generator_platform: "Win32"
72+
- os_arch: "windows-x64"
73+
os: "windows-2022"
74+
os_short: "windows"
75+
architecture: "x64"
76+
cibuildwheel_architecture: "AMD64"
77+
cmake_generator_platform: "x64"
78+
# - os_arch: "windows-arm64"
79+
# os: "windows-2022"
80+
# os_short: "windows"
81+
# architecture: "arm64"
82+
# cibuildwheel_architecture: "ARM64"
83+
# cmake_generator_platform: "ARM64"
84+
- os_arch: "macos-x86_64"
85+
os: "macos-11.0"
86+
os_short: "macos"
87+
cibuildwheel_architecture: "x86_64"
88+
architecture: "x86_64"
89+
- os_arch: "macos-arm64"
90+
os: "macos-11.0"
91+
os_short: "macos"
92+
cibuildwheel_architecture: "arm64"
93+
architecture: "arm64"
94+
- os_arch: linux-x86_64
95+
os: "ubuntu-22.04"
96+
os_short: "linux"
97+
cibuildwheel_architecture: "x86_64"
98+
architecture: "x86_64"
99+
- os_arch: linux-aarch64
100+
os: "ubuntu-22.04"
101+
os_short: "linux"
102+
cibuildwheel_architecture: "aarch64"
103+
architecture: "aarch64"
104+
steps:
105+
- uses: actions/checkout@v3
106+
with:
107+
fetch-depth: 0
108+
- run: git submodule update --init extlib/mimalloc extlib/eigen
109+
- name: Set version
110+
shell: bash
111+
run: |
112+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
113+
version="${GITHUB_REF##*/}"
114+
else
115+
mkdir empty-build
116+
cd empty-build
117+
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
118+
source version.env
119+
cd ..
120+
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.dev${GITHUB_RUN_NUMBER}"
121+
fi
122+
sed -i.bak "s/^version = .*/version = \"${version}\"/g" pyproject.toml && rm pyproject.toml.bak
123+
- name: Set up QEMU
124+
uses: docker/setup-qemu-action@v2
125+
if: matrix.architecture == 'aarch64'
126+
with:
127+
platforms: arm64
128+
- name: Build wheels
129+
uses: pypa/cibuildwheel@v2.11.2
130+
env:
131+
CIBW_BUILD: "cp${{ matrix.python_version }}-*"
132+
CIBW_PLATFORM: "${{ matrix.os_short }}"
133+
CIBW_BUILD_VERBOSITY: "1"
134+
CIBW_ARCHS: "${{ matrix.cibuildwheel_architecture }}"
135+
CIBW_ENVIRONMENT_WINDOWS: >
136+
CMAKE_GENERATOR="Visual Studio 17 2022"
137+
CMAKE_GENERATOR_PLATFORM="${{ matrix.cmake_generator_platform }}"
138+
CIBW_ENVIRONMENT_PASS_WINDOWS: "CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM"
139+
- uses: actions/upload-artifact@v3
140+
with:
141+
name: wheel-${{ matrix.os_short }}-${{ matrix.architecture }}
142+
path: |
143+
./wheelhouse/*.whl
144+
publish-pypi:
145+
name: publish to PyPi
146+
needs: [
147+
python-sdist,
148+
python-wheel,
149+
]
150+
runs-on: ubuntu-22.04
151+
steps:
152+
- uses: actions/download-artifact@v3
153+
with:
154+
path: prebuilds
155+
- name: prepare
156+
shell: bash
157+
run: |
158+
mkdir dist
159+
ls prebuilds
160+
mv prebuilds/*/* dist
161+
ls dist
162+
- name: Publish wheels to Test PyPI
163+
uses: pypa/gh-action-pypi-publish@release/v1
164+
with:
165+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
166+
repository_url: https://test.pypi.org/legacy/
167+
- name: Publish wheels to PyPI
168+
if: startsWith(github.ref, 'refs/tags')
169+
uses: pypa/gh-action-pypi-publish@release/v1
170+
with:
171+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/wasmlib.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: WASM Library
2+
3+
on:
4+
push:
5+
branches: [ master, python, experiments, stateful-c-lib ]
6+
tags: [ v* ]
7+
8+
jobs:
9+
build-wasmlib:
10+
name: WASM library
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- run: git submodule update --init extlib/mimalloc extlib/eigen
15+
- name: Pack
16+
shell: bash
17+
run: |
18+
.github/scripts/build-wasmlib.sh
19+
cd build-wasmlib/bin
20+
rm libmimalloc.a || true
21+
zip -r slvs-wasmlib.zip .
22+
- name: Upload artifact
23+
uses: actions/upload-artifact@v3
24+
with:
25+
name: slvs-wasmlib
26+
path: build-wasmlib/bin/slvs-wasmlib.zip
27+
publish-wasmlib:
28+
name: publish WASM library
29+
needs: [
30+
build-wasmlib,
31+
]
32+
runs-on: ubuntu-22.04
33+
steps:
34+
- uses: actions/checkout@v3
35+
- uses: actions/download-artifact@v3
36+
with:
37+
path: artifacts
38+
- name: Setup Node
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version: '14.x'
42+
registry-url: https://registry.npmjs.org/
43+
- name: prepare
44+
shell: bash
45+
env:
46+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
47+
run: |
48+
git fetch --unshallow --tags
49+
50+
ls artifacts
51+
unzip artifacts/slvs-wasmlib/slvs-wasmlib.zip -d js
52+
ls js
53+
54+
# bump version
55+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
56+
version="${GITHUB_REF##*/}"
57+
else
58+
mkdir empty-build
59+
cd empty-build
60+
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
61+
source version.env
62+
cd ..
63+
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-dev.${GITHUB_RUN_NUMBER}"
64+
is_dev="1"
65+
fi
66+
jq --arg version "${version}" '.version = $version' package.json > package.json.tmp
67+
mv package.json.tmp js/package.json
68+
cd js
69+
if [ "${is_dev}" == "1" ]; then
70+
npm publish --access public --tag dev
71+
else
72+
npm publish --access public
73+
fi

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919
out/
2020
.vs/
2121
CMakeSettings.json
22+
__pycache__/
23+
solvespace.egg-info/
24+
dist/
25+
.DS_Store

0 commit comments

Comments
 (0)