From 133ba07df78e40a3091129ca3ad0b5368460876d Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 16:17:08 -0400 Subject: [PATCH 1/9] updates to readme and CMakeLists.txt --- .github/workflows/wheels.yml | 3 + CMakeLists.txt | 17 +++++- README.md | 103 ++++++++++++++++++++++++++++++++--- pyproject.toml | 18 +++--- src/demo/cppcore.pyi | 16 ++++++ 5 files changed, 137 insertions(+), 20 deletions(-) create mode 100644 src/demo/cppcore.pyi diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 929e237..325e0b5 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -58,7 +58,10 @@ jobs: env: CIBW_BUILD: "cp313-*" CIBW_SKIP: "*musllinux* *win32*" + CIBW_TEST_COMMAND: pytest {project}/tests + CIBW_TEST_EXTRAS: dev + CIBW_BEFORE_BUILD: rm -rf {project}/build CIBW_BEFORE_ALL_WINDOWS: bash tools\cibw_before.sh CIBW_ENVIRONMENT_WINDOWS: "CMAKE_PREFIX_PATH=D:/a/pycpp/pycpp/pybind11/pybind11/share/cmake" diff --git a/CMakeLists.txt b/CMakeLists.txt index 34d1481..36d0b71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.4...3.18) + +# required to find dependencies +if(NOT DEFINED ENV{VCPKG_HOST_TRIPLET}) + message(FATAL_ERROR "Environment variable 'VCPKG_HOST_TRIPLET' is not set") +endif() + project(cppcore) set(VCPKG_HOST_TRIPLET $ENV{VCPKG_HOST_TRIPLET}) @@ -27,9 +33,14 @@ find_library(NLOPT_LIB nlopt PATHS "${NLOPT_DIR_LIBRARY_DIR}") pybind11_add_module(cppcore src/cpp/main.cpp) -include_directories(${CMAKE_SOURCE_DIR}/src/cpp ${EIGEN_PATH} ${GSL_INCLUDE_DIR} ${NLOPT_DIR_INCLUDE_DIR}) -target_include_directories(cppcore PRIVATE ${GSL_INCLUDE_DIR} ${NLOPT_DIR_INCLUDE_DIR}) -target_link_libraries(cppcore PRIVATE ${GSL_LIB} ${GSLCBLAS_LIB} ${NLOPT_LIB}) +target_include_directories(cppcore PRIVATE ${CMAKE_SOURCE_DIR}/src/cpp) +target_include_directories(cppcore PRIVATE ${EIGEN_PATH}) +target_include_directories(cppcore PRIVATE ${GSL_INCLUDE_DIR}) +target_include_directories(cppcore PRIVATE ${NLOPT_DIR_INCLUDE_DIR}) + +target_link_libraries(cppcore PRIVATE ${NLOPT_LIB}) +target_link_libraries(cppcore PRIVATE ${GSL_LIB}) +target_link_libraries(cppcore PRIVATE ${GSLCBLAS_LIB}) target_compile_definitions( cppcore diff --git a/README.md b/README.md index 0f004f1..426018c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,29 @@ -# cppcore for pybind11 +# A Python Package with a C++ extension -MacOS installation: +Explorations in how to use Python, C++, and bindings between the two systems. Build compiled code in multiple environments via GitHub Actions. Key technologies used include [pybind11](https://pybind11.readthedocs.io/en/stable/), [vcpkg](https://github.com/microsoft/vcpkg), and [cibuildwheel](https://cibuildwheel.readthedocs.io/en/stable/). + +The project does the following: + +- Builds a simple C++ package +- Includes third party C++ packages installed via the vcpkg package manager +- Builds a python interface to the C++ package +- Has some tests to ensure the C++ package works correctly from python +- Automatically builds the packages on Mac, Linux, and Windows + +## Quickstart + +For this particular example, we install 3 scientific C++ packages: as dependencies for our library: + +* [Eigen3](https://vcpkg.io/en/package/eigen3.html) (headers only template library) +* [GNU Scientific Library](https://vcpkg.io/en/package/gsl.html) +* [NLopt](https://vcpkg.io/en/package/nlopt.html) + +Though you could customize this template as needed to install other packages from vcpkg. + +### MacOS/Linux: ```bash +# check out a single commit from a git repository mkdir vcpkg cd vcpkg git init @@ -11,14 +32,82 @@ git fetch --depth 1 origin c9c17dcea3016bc241df0422e82b8aea212dcb93 git checkout FETCH_HEAD cd .. -export VCPKG_HOST_TRIPLET=arm64-osx-dynamic +# build static dependencies; use the appropriate triplet (e.g., x64-linux, arm64-osx) +export $VCPKG_HOST_TRIPLET="arm64-osx" ./vcpkg/bootstrap-vcpkg.sh ./vcpkg/vcpkg install --host-triplet=$VCPKG_HOST_TRIPLET +# install pybind11 at the root so for our build phase +uv pip install pybind11==3.0.0 --target=./pybind11 + +# set environment variables for building python extension +export $CMAKE_PREFIX_PATH=export foo="$(readlink -f ./pybind11/pybind11/share/cmake)" +export $CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) + +echo "$VCPKG_HOST_TRIPLET" +echo "$CMAKE_PREFIX_PATH" +echo "$CMAKE_BUILD_PARALLEL_LEVEL" + +# create a new python virtual environment +uv venv --python=3.13 +.venv/bin/activate + +# compile and install the package +uv pip install -v -e . + +# generate typing stubs for C++ file +stubgen -p demo.cppcore -o src + +# test +pytest +``` + +### Windows: + +On Windows, install Visual Studio (2019 or 2022) and the C++ build packages (this is not related to Visual Studio Code). All commands below must be run within a Developer PowerShell for VS environment in order to use the appropriate compiler toolchain. + +We'll build static dependencies ([x64-windows-static-md](https://learn.microsoft.com/en-us/vcpkg/users/platforms/windows)) for C++ to make them easier to add to our custom Python module. +```ps1 +# check out a single commit from a git repository +mkdir vcpkg +cd vcpkg +git init +git remote add origin git@github.com:microsoft/vcpkg.git +git fetch --depth 1 origin c9c17dcea3016bc241df0422e82b8aea212dcb93 +git checkout FETCH_HEAD +cd .. + +# build static dependencies +$env:VCPKG_HOST_TRIPLET="x64-windows-static-md" +.\vcpkg\bootstrap-vcpkg.bat +.\vcpkg\vcpkg install --host-triplet="$env:VCPKG_HOST_TRIPLET" + +# install pybind11 at the root so for our build phase uv pip install pybind11==3.0.0 --target=./pybind11 -export VCPKG_HOST_TRIPLET=arm64-osx-dynamic -export CMAKE_PREFIX_PATH=/Users/andyshapiro/dev/pycpp/pybind11/pybind11/share/cmake -export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) -uv pip install -e . && pytest + +# set environment variables for building python extension +$env:CMAKE_PREFIX_PATH=Resolve-Path "./pybind11/pybind11/share/cmake" | Select-Object -ExpandProperty Path +$env:CMAKE_BUILD_PARALLEL_LEVEL=[Environment]::ProcessorCount + +echo "$env:VCPKG_HOST_TRIPLET" +echo "$env:CMAKE_PREFIX_PATH" +echo "$env:CMAKE_BUILD_PARALLEL_LEVEL" + +# create a new python virtual environment +uv venv --python=3.13 +.venv/Scripts/activate + +# compile and install the package +uv pip install -v -e . + +# generate typing stubs for C++ file +stubgen -p demo.cppcore -o src + +# test +pytest ``` + +## Distributable Python Wheels + +See the GitHub Actions. diff --git a/pyproject.toml b/pyproject.toml index 5249c89..85e3a0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,12 @@ authors = [ requires-python = ">=3.13" dependencies = [ "numpy", - "pytest", +] + +[project.optional-dependencies] +dev = [ + "pytest~=8.4.1", + "mypy~=1.17.1", ] [tool.setuptools.dynamic] @@ -20,18 +25,11 @@ include = ["demo*"] [build-system] requires = [ - "setuptools", - "pybind11" + "setuptools", + "pybind11~=3.0.0" ] build-backend = "setuptools.build_meta" [tool.pytest.ini_options] testpaths = "tests" python_files = ["test_*.py"] - -[tool.cibuildwheel] -test-command = "pytest {project}/tests" -test-extras = ["test"] -test-skip = ["*universal2:arm64"] -# Setuptools bug causes collision between pypy and cpython artifacts -before-build = "rm -rf {project}/build" diff --git a/src/demo/cppcore.pyi b/src/demo/cppcore.pyi new file mode 100644 index 0000000..0dfa17d --- /dev/null +++ b/src/demo/cppcore.pyi @@ -0,0 +1,16 @@ +import collections.abc +import numpy +import numpy.typing +import typing + +def add(arg0: typing.SupportsInt, arg1: typing.SupportsInt) -> int: ... +def eigen_matmul( + arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float64], + arg1: typing.Annotated[numpy.typing.ArrayLike, numpy.float64], +) -> numpy.typing.NDArray[numpy.float64]: ... +def gsl_bessel(arg0: typing.SupportsFloat) -> float: ... +def nlopt_optimize( + lower_bounds: collections.abc.Sequence[typing.SupportsFloat], + upper_bounds: collections.abc.Sequence[typing.SupportsFloat], +) -> list[float]: ... +def subtract(arg0: typing.SupportsInt, arg1: typing.SupportsInt) -> int: ... From b39a2b19f36bebe791a483da8c9a3b3e5b44ef7e Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 18:26:06 -0400 Subject: [PATCH 2/9] check on macos --- .github/workflows/test.yml | 4 ++-- README.md | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87d27d7..a97d946 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,7 +76,7 @@ jobs: export CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) - uv pip install -v -e . + uv pip install -v -e ".[dev]" py.test @@ -92,6 +92,6 @@ jobs: $env:CMAKE_PREFIX_PATH="${{ github.workspace }}\pybind11\pybind11\share\cmake" $env:CMAKE_BUILD_PARALLEL_LEVEL = [Environment]::ProcessorCount - uv pip install -v -e . + uv pip install -v -e ".[dev]" py.test diff --git a/README.md b/README.md index 426018c..665c5bc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ git checkout FETCH_HEAD cd .. # build static dependencies; use the appropriate triplet (e.g., x64-linux, arm64-osx) -export $VCPKG_HOST_TRIPLET="arm64-osx" +export VCPKG_HOST_TRIPLET="arm64-osx" ./vcpkg/bootstrap-vcpkg.sh ./vcpkg/vcpkg install --host-triplet=$VCPKG_HOST_TRIPLET @@ -41,8 +41,8 @@ export $VCPKG_HOST_TRIPLET="arm64-osx" uv pip install pybind11==3.0.0 --target=./pybind11 # set environment variables for building python extension -export $CMAKE_PREFIX_PATH=export foo="$(readlink -f ./pybind11/pybind11/share/cmake)" -export $CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) +export CMAKE_PREFIX_PATH="$(readlink -f ./pybind11/pybind11/share/cmake)" +export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) echo "$VCPKG_HOST_TRIPLET" echo "$CMAKE_PREFIX_PATH" @@ -50,10 +50,10 @@ echo "$CMAKE_BUILD_PARALLEL_LEVEL" # create a new python virtual environment uv venv --python=3.13 -.venv/bin/activate +source .venv/bin/activate # compile and install the package -uv pip install -v -e . +uv pip install -v -e ".[dev]" # generate typing stubs for C++ file stubgen -p demo.cppcore -o src @@ -99,7 +99,7 @@ uv venv --python=3.13 .venv/Scripts/activate # compile and install the package -uv pip install -v -e . +uv pip install -v -e ".[dev]" # generate typing stubs for C++ file stubgen -p demo.cppcore -o src From eb19d4c78fa5d548286054cf812fdef3ca5c2aec Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 18:46:11 -0400 Subject: [PATCH 3/9] add cronjobs; use mapping instead of switch --- .github/workflows/test.yml | 19 ++++++++++--------- .github/workflows/wheels.yml | 29 +++++++++++------------------ 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a97d946..f5ee246 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,8 @@ name: Run tests on: workflow_dispatch: pull_request: + schedule: + - cron: '14 3 15 * *' # Runs at 03:14 UTC on the 15th of every month push: branches: - main @@ -27,18 +29,17 @@ jobs: path: vcpkg_installed key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} - - name: Set compile target + - name: Export vcpkg host triplet for compilation shell: bash run: | - if [[ "$RUNNER_OS" == "Windows" ]]; then - VCPKG_HOST_TRIPLET=x64-windows-static-md - elif [[ "$RUNNER_OS" == "Linux" ]]; then - VCPKG_HOST_TRIPLET=x64-linux - elif [[ "$RUNNER_OS" == "macOS" ]]; then - VCPKG_HOST_TRIPLET=arm64-osx - fi + declare -A tripletMapping=( + ["Linux"]="x64-linux" + ["Windows"]="x64-windows-static-md" + ["macOS"]="arm64-osx" + ) + export VCPKG_HOST_TRIPLET="${tripletMapping[$RUNNER_OS]}" echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV - echo $VCPKG_HOST_TRIPLET + echo "$VCPKG_HOST_TRIPLET" - name: Acquire vcpkg if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 325e0b5..ce35603 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -3,6 +3,8 @@ name: Build package wheels on: workflow_dispatch: pull_request: + schedule: + - cron: '14 3 15 * *' # Runs at 03:14 UTC on the 15th of every month push: branches: - main @@ -19,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cache dependencies. # TODO - this may not work on linux b/c os is different than container? + - name: Cache dependencies id: cache-vcpkg-deps uses: actions/cache@v4 with: @@ -33,26 +35,17 @@ jobs: path: vcpkg ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 - - name: Install libraries with vcpkg.json (macOS/Linux) + - name: Export vcpkg host triplet for compilation shell: bash run: | - case "${RUNNER_OS}" in - "Windows") - VCPKG_HOST_TRIPLET="x64-windows-static-md" - ;; - "Linux") - VCPKG_HOST_TRIPLET="x64-linux" - ;; - "macOS") - VCPKG_HOST_TRIPLET="arm64-osx" - ;; - *) - echo "Unsupported RUNNER_OS: ${RUNNER_OS}" - exit 1 - ;; - esac + declare -A tripletMapping=( + ["Linux"]="x64-linux" + ["Windows"]="x64-windows-static-md" + ["macOS"]="arm64-osx" + ) + export VCPKG_HOST_TRIPLET="${tripletMapping[$RUNNER_OS]}" echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV - echo $VCPKG_HOST_TRIPLET + echo "$VCPKG_HOST_TRIPLET" - uses: pypa/cibuildwheel@v3.1.3 env: From b56a74dc39595f094cfd4ea5e85f79fa42e8f0be Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 18:58:05 -0400 Subject: [PATCH 4/9] use node for universal runner --- .github/workflows/test.yml | 32 +++++++++++++++++--------------- .github/workflows/wheels.yml | 23 ++++++++++++----------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5ee246..d36f11b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: pull_request: schedule: - - cron: '14 3 15 * *' # Runs at 03:14 UTC on the 15th of every month + - cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month push: branches: - main @@ -27,22 +27,24 @@ jobs: uses: actions/cache@v4 with: path: vcpkg_installed - key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} + key: vcpkg-${{ runner.os }}-${{ hashFiles("vcpkg.json") }} - name: Export vcpkg host triplet for compilation - shell: bash + shell: node run: | - declare -A tripletMapping=( - ["Linux"]="x64-linux" - ["Windows"]="x64-windows-static-md" - ["macOS"]="arm64-osx" - ) - export VCPKG_HOST_TRIPLET="${tripletMapping[$RUNNER_OS]}" - echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV - echo "$VCPKG_HOST_TRIPLET" + const mapping = { + Linux: "x64-linux", + Windows: "x64-windows-static-md", + macOS: "arm64-osx" + }; + const value = mapping[process.env.RUNNER_OS]; + const fs = require("fs"); + fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); + print(value); + - name: Acquire vcpkg - if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' + if: steps.cache-vcpkg-deps.outputs.cache-hit != "true" uses: actions/checkout@v4 with: repository: "Microsoft/vcpkg" @@ -50,7 +52,7 @@ jobs: ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 - name: Install libraries with vcpkg.json - if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' + if: steps.cache-vcpkg-deps.outputs.cache-hit != "true" shell: bash run: | ./vcpkg/bootstrap-vcpkg.sh @@ -66,7 +68,7 @@ jobs: cache-dependency-glob: "**/pyproject.toml" - name: Build pybmds - if: runner.os != 'Windows' + if: runner.os != "Windows" run: | uv pip install pybind11==3.0.0 --target=./pybind11 @@ -82,7 +84,7 @@ jobs: py.test - name: Build pybmds - if: runner.os == 'Windows' + if: runner.os == "Windows" run: | uv pip install pybind11==3.0.0 --target=./pybind11 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index ce35603..c8e8a7d 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: pull_request: schedule: - - cron: '14 3 15 * *' # Runs at 03:14 UTC on the 15th of every month + - cron: "14 3 15 * *" # Runs at 03:14 UTC on the 15th of every month push: branches: - main @@ -26,7 +26,7 @@ jobs: uses: actions/cache@v4 with: path: vcpkg_installed - key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} + key: vcpkg-${{ runner.os }}-${{ hashFiles("vcpkg.json") }} - name: Acquire vcpkg uses: actions/checkout@v4 @@ -36,16 +36,17 @@ jobs: ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 - name: Export vcpkg host triplet for compilation - shell: bash + shell: node run: | - declare -A tripletMapping=( - ["Linux"]="x64-linux" - ["Windows"]="x64-windows-static-md" - ["macOS"]="arm64-osx" - ) - export VCPKG_HOST_TRIPLET="${tripletMapping[$RUNNER_OS]}" - echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV - echo "$VCPKG_HOST_TRIPLET" + const mapping = { + Linux: "x64-linux", + Windows: "x64-windows-static-md", + macOS: "arm64-osx" + }; + const value = mapping[process.env.RUNNER_OS]; + const fs = require("fs"); + fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); + print(value); - uses: pypa/cibuildwheel@v3.1.3 env: From 0d5b320af17756fb079f051f50e86b30862b547e Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 18:59:17 -0400 Subject: [PATCH 5/9] single quotes --- .github/workflows/test.yml | 2 +- .github/workflows/wheels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d36f11b..6d599da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: uses: actions/cache@v4 with: path: vcpkg_installed - key: vcpkg-${{ runner.os }}-${{ hashFiles("vcpkg.json") }} + key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} - name: Export vcpkg host triplet for compilation shell: node diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index c8e8a7d..dc6a8d9 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -26,7 +26,7 @@ jobs: uses: actions/cache@v4 with: path: vcpkg_installed - key: vcpkg-${{ runner.os }}-${{ hashFiles("vcpkg.json") }} + key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} - name: Acquire vcpkg uses: actions/checkout@v4 From 98e52d49c61ec8ecbe63f61568f8bd3e092b6d2a Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 19:02:42 -0400 Subject: [PATCH 6/9] node shell doesn't exist --- .github/workflows/test.yml | 22 +++++++++++----------- .github/workflows/wheels.yml | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d599da..6c83d33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,18 +30,18 @@ jobs: key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} - name: Export vcpkg host triplet for compilation - shell: node run: | - const mapping = { - Linux: "x64-linux", - Windows: "x64-windows-static-md", - macOS: "arm64-osx" - }; - const value = mapping[process.env.RUNNER_OS]; - const fs = require("fs"); - fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); - print(value); - + node -e " + const mapping = { + Linux: 'x64-linux', + Windows: 'x64-windows-static-md', + macOS: 'arm64-osx' + }; + const value = mapping[process.env.RUNNER_OS]; + const fs = require('fs'); + fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); + print(value); + " - name: Acquire vcpkg if: steps.cache-vcpkg-deps.outputs.cache-hit != "true" diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index dc6a8d9..2523934 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -36,17 +36,18 @@ jobs: ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 - name: Export vcpkg host triplet for compilation - shell: node run: | - const mapping = { - Linux: "x64-linux", - Windows: "x64-windows-static-md", - macOS: "arm64-osx" - }; - const value = mapping[process.env.RUNNER_OS]; - const fs = require("fs"); - fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); - print(value); + node -e " + const mapping = { + Linux: 'x64-linux', + Windows: 'x64-windows-static-md', + macOS: 'arm64-osx' + }; + const value = mapping[process.env.RUNNER_OS]; + const fs = require('fs'); + fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); + print(value); + " - uses: pypa/cibuildwheel@v3.1.3 env: From 23bc802cfcfb899ad4316682ba0c8b2557b91307 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 19:03:45 -0400 Subject: [PATCH 7/9] more single quotes --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c83d33..e24ea4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,7 +44,7 @@ jobs: " - name: Acquire vcpkg - if: steps.cache-vcpkg-deps.outputs.cache-hit != "true" + if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' uses: actions/checkout@v4 with: repository: "Microsoft/vcpkg" @@ -52,7 +52,7 @@ jobs: ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 - name: Install libraries with vcpkg.json - if: steps.cache-vcpkg-deps.outputs.cache-hit != "true" + if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' shell: bash run: | ./vcpkg/bootstrap-vcpkg.sh From fef1aba47c8a913f10d5ee4dc89897ad00169209 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 19:08:04 -0400 Subject: [PATCH 8/9] don't be fancy; back to bash --- .github/workflows/test.yml | 27 +++++++++++++-------------- .github/workflows/wheels.yml | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e24ea4b..e439cde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Run tests +name: Run Tests on: workflow_dispatch: @@ -30,18 +30,17 @@ jobs: key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }} - name: Export vcpkg host triplet for compilation + shell: bash run: | - node -e " - const mapping = { - Linux: 'x64-linux', - Windows: 'x64-windows-static-md', - macOS: 'arm64-osx' - }; - const value = mapping[process.env.RUNNER_OS]; - const fs = require('fs'); - fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); - print(value); - " + if [[ "$RUNNER_OS" == "Windows" ]]; then + VCPKG_HOST_TRIPLET=x64-windows-static-md + elif [[ "$RUNNER_OS" == "Linux" ]]; then + VCPKG_HOST_TRIPLET=x64-linux + elif [[ "$RUNNER_OS" == "macOS" ]]; then + VCPKG_HOST_TRIPLET=arm64-osx + fi + echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV + echo $VCPKG_HOST_TRIPLET - name: Acquire vcpkg if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true' @@ -68,7 +67,7 @@ jobs: cache-dependency-glob: "**/pyproject.toml" - name: Build pybmds - if: runner.os != "Windows" + if: runner.os != 'Windows' run: | uv pip install pybind11==3.0.0 --target=./pybind11 @@ -84,7 +83,7 @@ jobs: py.test - name: Build pybmds - if: runner.os == "Windows" + if: runner.os == 'Windows' run: | uv pip install pybind11==3.0.0 --target=./pybind11 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 2523934..47acde1 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -1,4 +1,4 @@ -name: Build package wheels +name: Build Python Wheels on: workflow_dispatch: @@ -35,6 +35,19 @@ jobs: path: vcpkg ref: c9c17dcea3016bc241df0422e82b8aea212dcb93 + - name: Export vcpkg host triplet for compilation + shell: bash + run: | + if [[ "$RUNNER_OS" == "Windows" ]]; then + VCPKG_HOST_TRIPLET=x64-windows-static-md + elif [[ "$RUNNER_OS" == "Linux" ]]; then + VCPKG_HOST_TRIPLET=x64-linux + elif [[ "$RUNNER_OS" == "macOS" ]]; then + VCPKG_HOST_TRIPLET=arm64-osx + fi + echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV + echo $VCPKG_HOST_TRIPLET + - name: Export vcpkg host triplet for compilation run: | node -e " From ed1e46f8bb30d011e6efc4ce1534850cc4ad7bfb Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Tue, 12 Aug 2025 19:10:12 -0400 Subject: [PATCH 9/9] fix copy paste error --- .github/workflows/wheels.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 47acde1..0e192a2 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -48,20 +48,6 @@ jobs: echo VCPKG_HOST_TRIPLET="$VCPKG_HOST_TRIPLET" >> $GITHUB_ENV echo $VCPKG_HOST_TRIPLET - - name: Export vcpkg host triplet for compilation - run: | - node -e " - const mapping = { - Linux: 'x64-linux', - Windows: 'x64-windows-static-md', - macOS: 'arm64-osx' - }; - const value = mapping[process.env.RUNNER_OS]; - const fs = require('fs'); - fs.appendFileSync(process.env.GITHUB_ENV, `VCPKG_HOST_TRIPLET=${value}\n`); - print(value); - " - - uses: pypa/cibuildwheel@v3.1.3 env: CIBW_BUILD: "cp313-*"