Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 78 additions & 78 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,80 +20,80 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Cache dependencies
id: cache-vcpkg-deps
uses: actions/cache@v4
with:
path: vcpkg_installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}

- 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: Acquire vcpkg
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: "Microsoft/vcpkg"
path: vcpkg
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93

- name: Install libraries with vcpkg.json
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
shell: bash
run: |
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install --host-triplet="$VCPKG_HOST_TRIPLET"

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "**/pyproject.toml"

- name: Build pybmds
if: runner.os != 'Windows'
run: |
uv pip install pybind11==3.0.0 --target=./pybind11

uv venv --python=${{ matrix.python-version }}

source .venv/bin/activate

export CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)

uv pip install -v -e ".[dev]"

py.test

- name: Build pybmds
if: runner.os == 'Windows'
run: |
uv pip install pybind11==3.0.0 --target=./pybind11

uv venv --python=${{ matrix.python-version }}

.venv/Scripts/activate

$env:CMAKE_PREFIX_PATH="${{ github.workspace }}\pybind11\pybind11\share\cmake"
$env:CMAKE_BUILD_PARALLEL_LEVEL = [Environment]::ProcessorCount

uv pip install -v -e ".[dev]"

py.test
- uses: actions/checkout@v4

- name: Cache dependencies
id: cache-vcpkg-deps
uses: actions/cache@v4
with:
path: vcpkg_installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}

- 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: Acquire vcpkg
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: "Microsoft/vcpkg"
path: vcpkg
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93

- name: Install libraries with vcpkg.json
if: steps.cache-vcpkg-deps.outputs.cache-hit != 'true'
shell: bash
run: |
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install --host-triplet="$VCPKG_HOST_TRIPLET"

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "**/pyproject.toml"

- name: Build pybmds
if: runner.os != 'Windows'
run: |
uv pip install pybind11==3.0.0 --target=./pybind11

uv venv --python=${{ matrix.python-version }}

source .venv/bin/activate

export CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)

uv pip install -v -e ".[dev]"

py.test

- name: Build pybmds
if: runner.os == 'Windows'
run: |
uv pip install pybind11==3.0.0 --target=./pybind11

uv venv --python=${{ matrix.python-version }}

.venv/Scripts/activate

$env:CMAKE_PREFIX_PATH="${{ github.workspace }}\pybind11\pybind11\share\cmake"
$env:CMAKE_BUILD_PARALLEL_LEVEL = [Environment]::ProcessorCount

uv pip install -v -e ".[dev]"

py.test
94 changes: 47 additions & 47 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ 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
- main

jobs:
build_wheels:
Expand All @@ -19,61 +19,61 @@ jobs:
os: [ubuntu-24.04, windows-2022, macos-14]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Cache dependencies
id: cache-vcpkg-deps
uses: actions/cache@v4
with:
path: vcpkg_installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}
- name: Cache dependencies
id: cache-vcpkg-deps
uses: actions/cache@v4
with:
path: vcpkg_installed
key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}

- name: Acquire vcpkg
uses: actions/checkout@v4
with:
repository: "Microsoft/vcpkg"
path: vcpkg
ref: c9c17dcea3016bc241df0422e82b8aea212dcb93
- name: Acquire vcpkg
uses: actions/checkout@v4
with:
repository: "Microsoft/vcpkg"
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
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

- uses: pypa/cibuildwheel@v3.1.3
env:
CIBW_BUILD: "cp313-*"
CIBW_SKIP: "*musllinux* *win32*"
CIBW_TEST_COMMAND: pytest {project}/tests
CIBW_TEST_EXTRAS: dev
- uses: pypa/cibuildwheel@v3.1.3
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"
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"

CIBW_ENVIRONMENT_PASS_LINUX: "VCPKG_HOST_TRIPLET RUNNER_OS"
CIBW_BEFORE_ALL_LINUX: "source tools/cibw_before.sh"
CIBW_ENVIRONMENT_LINUX: "CMAKE_PREFIX_PATH=/project/pybind11/pybind11/share/cmake"
CIBW_ENVIRONMENT_PASS_LINUX: "VCPKG_HOST_TRIPLET RUNNER_OS"
CIBW_BEFORE_ALL_LINUX: "source tools/cibw_before.sh"
CIBW_ENVIRONMENT_LINUX: "CMAKE_PREFIX_PATH=/project/pybind11/pybind11/share/cmake"

CIBW_BEFORE_ALL_MACOS: "source tools/cibw_before.sh"
CIBW_ENVIRONMENT_MACOS: "CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake"
MACOSX_DEPLOYMENT_TARGET: "14.0"
CIBW_BEFORE_ALL_MACOS: "source tools/cibw_before.sh"
CIBW_ENVIRONMENT_MACOS: "CMAKE_PREFIX_PATH=${{ github.workspace }}/pybind11/pybind11/share/cmake"
MACOSX_DEPLOYMENT_TARGET: "14.0"

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

merge_wheels:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs: build_wheels
steps:
- name: Merge Artifacts
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ _generate/
*.egg-info
*env*

cfg/
pybind11/
vcpkg/
vcpkg_installed/
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,3 @@ 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
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}
)
47 changes: 11 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
"win32": "Win32",
"win-amd64": "x64",
Expand All @@ -14,25 +13,20 @@
}


# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: str = "") -> None:
super().__init__(name, sources=[])
self.sourcedir = os.fspath(Path(sourcedir).resolve())
self.sourcedir = str(Path(sourcedir).resolve())


class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()
ext_fullpath = Path(self.get_ext_fullpath(ext.name)).resolve()
extdir = ext_fullpath.parent

debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"

cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
Expand All @@ -41,35 +35,16 @@ def build_extension(self, ext: CMakeExtension) -> None:
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

if self.compiler.compiler_type != "msvc":
if not cmake_generator or cmake_generator == "Ninja":
try:
import ninja

ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
cmake_args += [
"-GNinja",
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
]
except ImportError:
pass

else:
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

if not single_config and not contains_arch:
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

if not single_config:
cmake_args += [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
]
build_args += ["--config", cfg]
if self.compiler.compiler_type == "msvc":
cmake_args += [
"-A",
PLAT_TO_CMAKE[self.plat_name],
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}",
]
build_args += ["--config", cfg]

build_temp = Path(self.build_temp) / ext.name
if not build_temp.exists():
build_temp.mkdir(parents=True)
build_temp.mkdir(parents=True, exist_ok=True)

subprocess.run(
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
Expand Down
Loading