Skip to content

Commit 4fd78aa

Browse files
authored
Set up Windows workflow (#12)
* 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.
1 parent 5d5d7cc commit 4fd78aa

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

Diff for: .github/workflows/package.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
name: wheel-${{ matrix.os }}-${{ matrix.python }}
2727
path: dist/*.whl
2828

29-
# Hatch builds wheels with a platform tag not permitted by PyPI. Hence, use
30-
# cibuildwheel.
31-
build_linux:
29+
# Hatch builds Linux wheels with a platform tag not permitted by PyPI. Hence,
30+
# use cibuildwheel.
31+
build_ubuntu_windows:
3232
strategy:
3333
matrix:
34-
os: ['ubuntu-22.04']
34+
os: ['ubuntu-22.04', 'windows-2022']
3535
name: build on ${{ matrix.os }}
3636
runs-on: ${{ matrix.os }}
3737
steps:
@@ -45,7 +45,7 @@ jobs:
4545

4646
release:
4747
if: github.ref_type == 'tag'
48-
needs: [build_macos, build_linux]
48+
needs: [build_macos, build_ubuntu_windows]
4949
runs-on: ubuntu-22.04
5050
permissions: write-all
5151
steps:

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
test:
66
strategy:
77
matrix:
8-
os: ['macos-14', 'ubuntu-22.04']
8+
os: ['macos-13', 'macos-14', 'ubuntu-22.04', 'windows-2022']
99
python: ['3.10', '3.11', '3.12', '3.13']
1010
name: test on ${{ matrix.os }} with ${{ matrix.python }}
1111
runs-on: ${{ matrix.os }}

Diff for: setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import platform
2+
13
import setuptools
24

35
setuptools.setup(
46
ext_modules=[
57
setuptools.Extension(
68
name="pysorteddict",
7-
extra_compile_args=["-std=c++20"],
9+
extra_compile_args=["/std:c++14" if platform.system() == "Windows" else "-std=c++14"],
810
sources=["src/pysorteddict/pysorteddict.cc"],
911
py_limited_api=True,
1012
)

Diff for: src/pysorteddict/pysorteddict.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ static PyObject* sorted_dict_type_new(PyTypeObject* type, PyObject* args, PyObje
7575
}
7676

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

0 commit comments

Comments
 (0)