Skip to content

Commit

Permalink
Set up Windows workflow (#12)
Browse files Browse the repository at this point in the history
* Used C++14 to compile the code
* Fixed Windows compile error on C++20 caused by dropping `const`
  * Which means I could leave the standard at C++20.
  * However, C++14 is reasonably recent, while still old enough that most compilers will support it.
* Added Windows package workflow using cibuildwheel
* Added back macOS 13 UTs
  * Although I package only on macOS 14 (because Hatch produces universal wheels).
  * Nonetheless, I should still test on the older architecture.
  • Loading branch information
tfpf authored Nov 23, 2024
1 parent 5d5d7cc commit 4fd78aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
name: wheel-${{ matrix.os }}-${{ matrix.python }}
path: dist/*.whl

# Hatch builds wheels with a platform tag not permitted by PyPI. Hence, use
# cibuildwheel.
build_linux:
# Hatch builds Linux wheels with a platform tag not permitted by PyPI. Hence,
# use cibuildwheel.
build_ubuntu_windows:
strategy:
matrix:
os: ['ubuntu-22.04']
os: ['ubuntu-22.04', 'windows-2022']
name: build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -45,7 +45,7 @@ jobs:

release:
if: github.ref_type == 'tag'
needs: [build_macos, build_linux]
needs: [build_macos, build_ubuntu_windows]
runs-on: ubuntu-22.04
permissions: write-all
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
os: ['macos-14', 'ubuntu-22.04']
os: ['macos-13', 'macos-14', 'ubuntu-22.04', 'windows-2022']
python: ['3.10', '3.11', '3.12', '3.13']
name: test on ${{ matrix.os }} with ${{ matrix.python }}
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import platform

import setuptools

setuptools.setup(
ext_modules=[
setuptools.Extension(
name="pysorteddict",
extra_compile_args=["-std=c++20"],
extra_compile_args=["/std:c++14" if platform.system() == "Windows" else "-std=c++14"],
sources=["src/pysorteddict/pysorteddict.cc"],
py_limited_api=True,
)
Expand Down
10 changes: 7 additions & 3 deletions src/pysorteddict/pysorteddict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ static PyObject* sorted_dict_type_new(PyTypeObject* type, PyObject* args, PyObje
}

SortedDictType* sd = (SortedDictType*)self;
// Casting a string constant to a non-const pointer is not permitted in
// C++, but the signature of this function is such that I am forced to.
char* args_names[] = { "key_type", nullptr };
// Up to Python 3.12, the argument parser below took an array of pointers
// (with each pointer pointing to a C string) as its fourth argument.
// However, C++ does not allow converting a string constant to a pointer.
// Hence, I use a character array to construct the C string, and then place
// it in an array of pointers.
char key_type[] = "key_type";
char* args_names[] = { key_type, nullptr };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|", args_names, &sd->key_type))
{
Py_DECREF(self);
Expand Down

0 comments on commit 4fd78aa

Please sign in to comment.