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
32 changes: 32 additions & 0 deletions .github/scripts/test-macos-libraw-linking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -euxo pipefail

python -m pip install --upgrade pip
brew install libraw

# Put Homebrew's LibRaw before setuptools' library_dirs. The bundled build
# must still link against the LibRaw that it just compiled.
libraw_prefix=$(brew --prefix libraw)
export LDFLAGS="-L${libraw_prefix}/lib"

python -m pip wheel . --wheel-dir dist --no-deps

wheel=$(find dist -name 'rawpy-*.whl' -print -quit)
test -n "${wheel}"

wheel_dir=tmp_macos_libraw_linking
rm -rf "${wheel_dir}"
unzip -q "${wheel}" -d "${wheel_dir}"

extensions=("${wheel_dir}"/rawpy/_rawpy*.so)
test "${#extensions[@]}" -eq 1

dependencies=$(otool -L "${extensions[0]}")
echo "${dependencies}"

if grep -Fq "${libraw_prefix}/lib/libraw_r" <<<"${dependencies}"; then
echo "ERROR: rawpy linked against Homebrew LibRaw instead of the bundled library"
exit 1
fi

grep -Eq '[[:space:]]@rpath/libraw_r\.[0-9]+\.dylib' <<<"${dependencies}"
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,23 @@ jobs:
name: wheel-${{ matrix.config.os-name }}-${{ matrix.config.python-arch }}-${{ matrix.config.python-version }}
path: dist

test-macos-bundled-libraw-linking:
runs-on: macos-15
env:
HOMEBREW_NO_AUTO_UPDATE: 1

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Verify bundled LibRaw wins over Homebrew
run: .github/scripts/test-macos-libraw-linking.sh

test:
strategy:
fail-fast: false
Expand Down
13 changes: 11 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
libraries = ["libraw_r"]
include_dirs = [numpy.get_include()] # Always include numpy headers
library_dirs = []
extra_objects = []
extra_compile_args = []
extra_link_args = []
define_macros = []
Expand Down Expand Up @@ -311,8 +312,15 @@ def unix_libraw_compile():
# Build from source
install_dir = get_install_dir()
include_dirs += [os.path.join(install_dir, "include", "libraw")]
library_dirs += [os.path.join(install_dir, "lib")]
libraries = ["raw_r"]
if isMac or isLinux:
# Link the bundled library explicitly so an earlier -L from the Python
# configuration or environment cannot select a system LibRaw instead.
suffix = ".dylib" if isMac else ".so"
libraries = []
extra_objects = [os.path.join(install_dir, "lib", "libraw_r" + suffix)]
else:
library_dirs += [os.path.join(install_dir, "lib")]
libraries = ["raw_r"]
# If building from source, we know we have the config header
libraw_config_found = True
else:
Expand Down Expand Up @@ -390,6 +398,7 @@ def _copy_bundled_libs(self):
sources=[os.path.join("rawpy", "_rawpy.pyx")],
libraries=libraries,
library_dirs=library_dirs,
extra_objects=extra_objects,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
Expand Down
Loading