Skip to content

Commit e2b4fff

Browse files
authored
Fix mutability for newer NumPy versions (3.14+) (#448)
* Fix mutability for newer NumPy versions (3.14+) * Update macos image * Try to fix illegal instruction errors on CI. * Switch to arm64. * Fix CI Cache key. * Try macos-15-intel runner.
1 parent d93b233 commit e2b4fff

File tree

4 files changed

+50
-34
lines changed

4 files changed

+50
-34
lines changed

.github/workflows/all.yml

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
${{ github.workspace }}/pedalboard/build/lib*
144144
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
145145
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
146-
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache
146+
key: ${{ matrix.os }}-${{ matrix.compiler }}-ccache
147147
- name: Build pedalboard locally
148148
env:
149149
CCACHE_DIR: ${{ github.workspace }}/.ccache
@@ -190,7 +190,7 @@ jobs:
190190
matrix:
191191
include:
192192
- {
193-
os: macos-13,
193+
os: macos-15-intel,
194194
python-version: "3.12",
195195
compiler: "clang",
196196
cc: "ccache clang",
@@ -227,7 +227,7 @@ jobs:
227227
${{ github.workspace }}/pedalboard/build/lib*
228228
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
229229
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
230-
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache
230+
key: ${{ matrix.os }}-${{ matrix.compiler }}-ccache
231231
- name: Build pedalboard locally
232232
env:
233233
CCACHE_DIR: ${{ github.workspace }}/.ccache
@@ -241,7 +241,7 @@ jobs:
241241
# Use the minimum macOS deployment target supported by our version of PyBind:
242242
MACOSX_DEPLOYMENT_TARGET: "10.14"
243243
CCACHE_LOGFILE: ${{ github.workspace }}/.ccache_log
244-
# This build caching is only to speed up tests on CI, so we only care about x86_64 for now.
244+
# This build caching is only to speed up tests on CI, so we only care about x86_64 (macos-15-intel runners).
245245
# Without limiting to a single architecture, ccache can't properly cache mixed Objective-C and C++ builds.
246246
# Fun fact: this is supported in Python itself! https://github.com/python/cpython/blob/893c9cc/Lib/_osx_support.py#L314-L328
247247
ARCHFLAGS: -arch x86_64
@@ -339,7 +339,7 @@ jobs:
339339
${{ github.workspace }}/pedalboard/build/lib*
340340
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
341341
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
342-
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache
342+
key: ${{ matrix.os }}-${{ matrix.compiler }}-ccache
343343
- name: Build pedalboard locally
344344
env:
345345
CCACHE_DIR: ${{ github.workspace }}/.ccache
@@ -351,6 +351,7 @@ jobs:
351351
CCACHE_IGNOREOPTIONS: "-fno-strict-overflow -fwrapv -W* -arch x86_64 arm64 -dynamic -fno-common -g -I/usr/local/opt/*"
352352
CCACHE_LOGFILE: ${{ github.workspace }}/.ccache_log
353353
USE_ASAN: "1"
354+
USE_PORTABLE_SIMD: "1" # Use portable SIMD to avoid "Illegal instruction" on different runner CPUs
354355
DISABLE_LTO: "1" # Speeds up un-cacheable link step which doesn't really increase performance in tests anyways
355356
CC: ${{ matrix.cc }}
356357
CXX: ${{ matrix.cxx }}
@@ -443,7 +444,7 @@ jobs:
443444
${{ github.workspace }}/pedalboard/build/lib*
444445
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
445446
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
446-
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache
447+
key: ${{ matrix.os }}-${{ matrix.compiler }}-ccache
447448
- name: Print Restored ${{ runner.os }} Objects
448449
run: ls -lashR ${{ github.workspace }}
449450
# Without this, distutils will recompile the extension even though we already have the .so built:
@@ -505,35 +506,35 @@ jobs:
505506
matrix:
506507
include:
507508
- {
508-
os: macos-13,
509+
os: macos-15-intel,
509510
python-version: "3.10",
510511
compiler: "clang",
511512
cc: "ccache clang",
512513
cxx: "ccache clang++",
513514
}
514515
- {
515-
os: macos-13,
516+
os: macos-15-intel,
516517
python-version: "3.11",
517518
compiler: "clang",
518519
cc: "ccache clang",
519520
cxx: "ccache clang++",
520521
}
521522
- {
522-
os: macos-13,
523+
os: macos-15-intel,
523524
python-version: "3.12",
524525
compiler: "clang",
525526
cc: "ccache clang",
526527
cxx: "ccache clang++",
527528
}
528529
- {
529-
os: macos-13,
530+
os: macos-15-intel,
530531
python-version: "3.13",
531532
compiler: "clang",
532533
cc: "ccache clang",
533534
cxx: "ccache clang++",
534535
}
535536
- {
536-
os: macos-13,
537+
os: macos-15-intel,
537538
python-version: "3.14",
538539
compiler: "clang",
539540
cc: "ccache clang",
@@ -672,7 +673,7 @@ jobs:
672673
${{ github.workspace }}/pedalboard/build/lib*
673674
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
674675
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
675-
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache
676+
key: ${{ matrix.os }}-${{ matrix.compiler }}-ccache
676677
# Without this, distutils will recompile the extension even though we already have the shared object built:
677678
- name: Touch Restored ${{ runner.os }} Objects to Prevent Cache Miss
678679
if: runner.os == 'Linux' || runner.os == 'macOS'
@@ -694,7 +695,7 @@ jobs:
694695
CCACHE_DEBUG: "1"
695696
# Use the minimum macOS deployment target supported by our version of PyBind:
696697
MACOSX_DEPLOYMENT_TARGET: "10.14"
697-
# This build caching is only to speed up tests on CI, so we only care about x86_64 for now.
698+
# This build caching is only to speed up tests on CI, so we only care about x86_64 (macos-15-intel runners).
698699
# Without limiting to a single architecture, ccache can't properly cache mixed Objective-C and C++ builds.
699700
# Fun fact: this is supported in Python itself! https://github.com/python/cpython/blob/893c9cc/Lib/_osx_support.py#L314-L328
700701
ARCHFLAGS: -arch x86_64
@@ -786,11 +787,12 @@ jobs:
786787
${{ github.workspace }}/pedalboard/build/lib*
787788
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/pedalboard/juce_overrides
788789
${{ github.workspace }}/pedalboard/build/temp${{ github.workspace }}/pedalboard/vendors
789-
key: ${{ runner.os }}-clang-ccache
790+
key: ${{ matrix.os }}-clang-ccache
790791
- name: Build pedalboard locally
791792
env:
792793
DEBUG: "0"
793794
USE_ASAN: "1"
795+
USE_PORTABLE_SIMD: "1" # Use portable SIMD to avoid "Illegal instruction" on different runner CPUs
794796
CCACHE_DIR: ${{ github.workspace }}/.ccache
795797
CCACHE_BASEDIR: ${{ github.workspace }}
796798
CCACHE_DEBUGDIR: ${{ github.workspace }}/.ccache_debug
@@ -827,22 +829,22 @@ jobs:
827829
strategy:
828830
matrix:
829831
include:
830-
- { os: macos-13, build: cp310-macosx_x86_64 }
831-
- { os: macos-13, build: cp311-macosx_x86_64 }
832-
- { os: macos-13, build: cp312-macosx_x86_64 }
833-
- { os: macos-13, build: cp313-macosx_x86_64 }
834-
- { os: macos-13, build: cp313t-macosx_x86_64 }
832+
- { os: macos-15-intel, build: cp310-macosx_x86_64 }
833+
- { os: macos-15-intel, build: cp311-macosx_x86_64 }
834+
- { os: macos-15-intel, build: cp312-macosx_x86_64 }
835+
- { os: macos-15-intel, build: cp313-macosx_x86_64 }
836+
- { os: macos-15-intel, build: cp313t-macosx_x86_64 }
835837
# Universal wheels are rarely used; only support them for Python 3.12:
836-
- { os: macos-13, build: cp312-macosx_universal2 }
837-
- { os: macos-13, build: cp310-macosx_arm64 }
838-
- { os: macos-13, build: cp311-macosx_arm64 }
839-
- { os: macos-13, build: cp312-macosx_arm64 }
840-
- { os: macos-13, build: cp313-macosx_arm64 }
841-
- { os: macos-13, build: cp313t-macosx_arm64 }
842-
- { os: macos-13, build: cp314-macosx_arm64 }
843-
- { os: macos-13, build: cp314t-macosx_arm64 }
844-
# - { os: macos-13, build: pp38-macosx_x86_64 }
845-
# - { os: macos-13, build: pp39-macosx_x86_64 }
838+
- { os: macos-15-intel, build: cp312-macosx_universal2 }
839+
- { os: macos-15-intel, build: cp310-macosx_arm64 }
840+
- { os: macos-15-intel, build: cp311-macosx_arm64 }
841+
- { os: macos-15-intel, build: cp312-macosx_arm64 }
842+
- { os: macos-15-intel, build: cp313-macosx_arm64 }
843+
- { os: macos-15-intel, build: cp313t-macosx_arm64 }
844+
- { os: macos-15-intel, build: cp314-macosx_arm64 }
845+
- { os: macos-15-intel, build: cp314t-macosx_arm64 }
846+
# - { os: macos-15-intel, build: pp38-macosx_x86_64 }
847+
# - { os: macos-15-intel, build: pp39-macosx_x86_64 }
846848
- { os: windows-latest, build: cp39-win_amd64 }
847849
- { os: windows-latest, build: cp310-win_amd64 }
848850
- { os: windows-latest, build: cp311-win_amd64 }

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ elseif(UNIX AND NOT APPLE)
199199
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
200200
add_compile_definitions(HAVE_NEON=1)
201201
else()
202-
add_compile_options(-march=native)
202+
# Use -march=native for local builds to optimize for the current CPU,
203+
# but use a portable baseline for CI builds to avoid "Illegal instruction" errors
204+
# when ccache restores objects built on different runner hardware.
205+
if(DEFINED ENV{USE_PORTABLE_SIMD})
206+
add_compile_options(-mavx)
207+
else()
208+
add_compile_options(-march=native)
209+
endif()
203210
add_compile_definitions(HAVE_AVX)
204211
endif()
205212

pedalboard/io/ReadableAudioFile.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,13 @@ class ReadableAudioFile
277277

278278
long long numSamplesToKeep = numSamples;
279279

280-
py::buffer_info outputInfo = buffer.request();
280+
// Get the data pointer directly without keeping a buffer_info reference
281+
// that would prevent resizing later (needed for Python 3.14+ / NumPy 2.x)
282+
float *outputPtr = buffer.mutable_data();
281283

282284
{
283285
py::gil_scoped_release release;
284-
numSamplesToKeep =
285-
readInternal(numChannels, numSamples, (float *)outputInfo.ptr);
286+
numSamplesToKeep = readInternal(numChannels, numSamples, outputPtr);
286287

287288
// After this point, we no longer need to hold the read lock as we don't
288289
// interact with the reader object anymore. Releasing this early (before

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ def ignore_files_matching(files, *matches):
175175
else:
176176
# And on x86, ignore the ARM-specific SIMD code (and KCVI; not GCC or Clang compatible).
177177
fftw_paths = ignore_files_matching(fftw_paths, "neon")
178-
ALL_CFLAGS.append("-march=native")
178+
# Use -march=native for local builds to optimize for the current CPU,
179+
# but use a portable baseline for CI builds to avoid "Illegal instruction" errors
180+
# when ccache restores objects built on different runner hardware.
181+
if os.getenv("USE_PORTABLE_SIMD"):
182+
ALL_CFLAGS.append("-mavx")
183+
else:
184+
ALL_CFLAGS.append("-march=native")
179185
# Enable SIMD instructions:
180186
ALL_CFLAGS.extend(
181187
[

0 commit comments

Comments
 (0)