Skip to content

Commit

Permalink
"Stateful" C library + Python bindings (using cython) and JS bindings…
Browse files Browse the repository at this point in the history
… (using embind) (#1343)
  • Loading branch information
vespakoen authored Dec 9, 2024
1 parent 33f9cf9 commit a208201
Show file tree
Hide file tree
Showing 24 changed files with 3,278 additions and 311 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/build-wasmlib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

cd ..
git clone https://github.com/emscripten-core/emsdk.git --depth 1
cd emsdk
./emsdk install latest
./emsdk activate latest
cd ../solvespace
source ../emsdk/emsdk_env.sh
mkdir build-wasmlib || true
cd build-wasmlib
emcmake cmake .. \
-DCMAKE_RELEASE_TYPE=Debug \
-DENABLE_GUI="OFF" \
-DENABLE_CLI="OFF" \
-DENABLE_TESTS="OFF" \
-DENABLE_COVERAGE="OFF" \
-DENABLE_OPENMP="OFF" \
-DFORCE_VENDORED_Eigen3="ON" \
-DENABLE_LTO="ON" \
-DENABLE_EMSCRIPTEN_LIB="ON"
cmake --build . -j$(nproc)
171 changes: 171 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Python

on:
push:
branches: [ master, python, experiments, stateful-c-lib ]
tags: [ v* ]

jobs:
python-sdist:
name: python sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: git submodule update --init extlib/mimalloc extlib/eigen
- uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Pack
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version="${GITHUB_REF##*/}"
else
mkdir empty-build
cd empty-build
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
source version.env
cd ..
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.dev${GITHUB_RUN_NUMBER}"
fi
sed -i.bak "s/^version = .*/version = \"${version}\"/g" pyproject.toml && rm pyproject.toml.bak
python -m pip install -U setuptools build
python -m build --sdist
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: sdist
path: dist/*.tar.gz
python-wheel:
name: ${{ matrix.os_short }} python ${{ matrix.architecture }} cp${{ matrix.python_version }}
runs-on: ${{ matrix.os }}
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
os_arch: [
"windows-ia32",
"windows-x64",
# "windows-arm64",
"macos-x86_64",
"macos-arm64",
"linux-x86_64",
"linux-aarch64",
]
python_version: [
"37",
"38",
"39",
"310",
"311",
]
exclude:
- os_arch: "macos-arm64"
python_version: "37"
include:
- os_arch: "windows-ia32"
os: "windows-2022"
os_short: "windows"
architecture: "ia32"
cibuildwheel_architecture: "x86"
cmake_generator_platform: "Win32"
- os_arch: "windows-x64"
os: "windows-2022"
os_short: "windows"
architecture: "x64"
cibuildwheel_architecture: "AMD64"
cmake_generator_platform: "x64"
# - os_arch: "windows-arm64"
# os: "windows-2022"
# os_short: "windows"
# architecture: "arm64"
# cibuildwheel_architecture: "ARM64"
# cmake_generator_platform: "ARM64"
- os_arch: "macos-x86_64"
os: "macos-11.0"
os_short: "macos"
cibuildwheel_architecture: "x86_64"
architecture: "x86_64"
- os_arch: "macos-arm64"
os: "macos-11.0"
os_short: "macos"
cibuildwheel_architecture: "arm64"
architecture: "arm64"
- os_arch: linux-x86_64
os: "ubuntu-22.04"
os_short: "linux"
cibuildwheel_architecture: "x86_64"
architecture: "x86_64"
- os_arch: linux-aarch64
os: "ubuntu-22.04"
os_short: "linux"
cibuildwheel_architecture: "aarch64"
architecture: "aarch64"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git submodule update --init extlib/mimalloc extlib/eigen
- name: Set version
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version="${GITHUB_REF##*/}"
else
mkdir empty-build
cd empty-build
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
source version.env
cd ..
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.dev${GITHUB_RUN_NUMBER}"
fi
sed -i.bak "s/^version = .*/version = \"${version}\"/g" pyproject.toml && rm pyproject.toml.bak
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
if: matrix.architecture == 'aarch64'
with:
platforms: arm64
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: "cp${{ matrix.python_version }}-*"
CIBW_PLATFORM: "${{ matrix.os_short }}"
CIBW_BUILD_VERBOSITY: "1"
CIBW_ARCHS: "${{ matrix.cibuildwheel_architecture }}"
CIBW_ENVIRONMENT_WINDOWS: >
CMAKE_GENERATOR="Visual Studio 17 2022"
CMAKE_GENERATOR_PLATFORM="${{ matrix.cmake_generator_platform }}"
CIBW_ENVIRONMENT_PASS_WINDOWS: "CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM"
- uses: actions/upload-artifact@v3
with:
name: wheel-${{ matrix.os_short }}-${{ matrix.architecture }}
path: |
./wheelhouse/*.whl
publish-pypi:
name: publish to PyPi
needs: [
python-sdist,
python-wheel,
]
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v3
with:
path: prebuilds
- name: prepare
shell: bash
run: |
mkdir dist
ls prebuilds
mv prebuilds/*/* dist
ls dist
- name: Publish wheels to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish wheels to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
73 changes: 73 additions & 0 deletions .github/workflows/wasmlib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: WASM Library

on:
push:
branches: [ master, python, experiments, stateful-c-lib ]
tags: [ v* ]

jobs:
build-wasmlib:
name: WASM library
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: git submodule update --init extlib/mimalloc extlib/eigen
- name: Pack
shell: bash
run: |
.github/scripts/build-wasmlib.sh
cd build-wasmlib/bin
rm libmimalloc.a || true
zip -r slvs-wasmlib.zip .
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: slvs-wasmlib
path: build-wasmlib/bin/slvs-wasmlib.zip
publish-wasmlib:
name: publish WASM library
needs: [
build-wasmlib,
]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
registry-url: https://registry.npmjs.org/
- name: prepare
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git fetch --unshallow --tags
ls artifacts
unzip artifacts/slvs-wasmlib/slvs-wasmlib.zip -d js
ls js
# bump version
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version="${GITHUB_REF##*/}"
else
mkdir empty-build
cd empty-build
cmake .. -DENABLE_GUI=OFF -DENABLE_CLI=OFF -DENABLE_TESTS=OFF -DENABLE_COVERAGE=OFF -DENABLE_SANITIZERS=OFF -DENABLE_OPENMP=OFF
source version.env
cd ..
version="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-dev.${GITHUB_RUN_NUMBER}"
is_dev="1"
fi
jq --arg version "${version}" '.version = $version' package.json > package.json.tmp
mv package.json.tmp js/package.json
cd js
if [ "${is_dev}" == "1" ]; then
npm publish --access public --tag dev
else
npm publish --access public
fi
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
out/
.vs/
CMakeSettings.json
__pycache__/
solvespace.egg-info/
dist/
.DS_Store
Loading

0 comments on commit a208201

Please sign in to comment.