Skip to content

Commit 7801fc2

Browse files
author
Jose Fernandez
committed
pystark windows compilation fix
1 parent dcedf71 commit 7801fc2

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"python-envs.defaultEnvManager": "ms-python.python:conda",
3+
"python-envs.defaultPackageManager": "ms-python.python:conda"
4+
}

pystark/cpp/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ FetchContent_Declare(
2929
GIT_SHALLOW TRUE
3030
)
3131

32+
# nanobind caches NB_SUFFIX (the .pyd/.so extension tag) in CMakeCache.txt.
33+
# When the active Python interpreter changes (e.g. cp312 → cp311) the cached
34+
# value becomes stale because nanobind uses "set(... CACHE INTERNAL)" without
35+
# FORCE, so it never overwrites an existing entry. We query the interpreter
36+
# here and force-write the cache entry so that the generated library always
37+
# carries the correct tag regardless of previous configure runs.
38+
execute_process(
39+
COMMAND "${Python_EXECUTABLE}" "-c"
40+
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
41+
OUTPUT_VARIABLE _pystark_ext_suffix
42+
OUTPUT_STRIP_TRAILING_WHITESPACE
43+
)
44+
set(NB_SUFFIX "${_pystark_ext_suffix}" CACHE INTERNAL "" FORCE)
45+
set(NB_SUFFIX_S "${_pystark_ext_suffix}" CACHE INTERNAL "" FORCE)
46+
3247
FetchContent_MakeAvailable(nanobind)
3348

3449
# Source files

pystark/cpp/nanobind_stark_include_all.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ using namespace nb::literals;
1818

1919
#include <cstring>
2020

21+
// ssize_t is a POSIX type not provided by MSVC's standard headers.
22+
// Python's headers define Py_ssize_t; make ssize_t an alias so that nanobind's
23+
// ndarray.h (template <ssize_t... Is> struct shape) and our own templates
24+
// compile cleanly on Windows.
25+
#if defined(_MSC_VER) && !defined(ssize_t)
26+
using ssize_t = Py_ssize_t;
27+
#endif
28+
2129

2230
// Type shortcuts
2331
#include <stark>

0 commit comments

Comments
 (0)