Skip to content

Commit b703e4d

Browse files
authored
Merge pull request #842 from mgorny/ldlibrary-so
Use sysconfigdata and `build-details.json` from shared library build
2 parents c223c6e + a407c5d commit b703e4d

8 files changed

Lines changed: 188 additions & 83 deletions

File tree

.scripts/run_osx_build.sh

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

recipe/build_base.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,20 +385,16 @@ if [[ ${_OPTIMIZED} == yes ]]; then
385385
_FLAGS_REPLACE+=("")
386386
done
387387
fi
388-
# Install the shared library (for people who embed Python only, e.g. GDB).
389-
# Linking module extensions to this on Linux is redundant (but harmless).
390-
# Linking module extensions to this on Darwin is harmful (multiply defined symbols).
391-
shopt -s extglob
392-
cp -pf ${_buildd_shared}/libpython*${SHLIB_EXT}!(.lto) ${PREFIX}/lib/
393-
shopt -u extglob
394-
if [[ ${target_platform} =~ .*linux.* ]]; then
395-
ln -sf ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT}.1.0 ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT}
396-
fi
397388

398-
SYSCONFIG=$(find ${_buildd_static}/$(cat ${_buildd_static}/pybuilddir.txt) -name "_sysconfigdata*.py" -print0)
389+
# Use sysconfigdata and build-details.json from the shared build, as we want packages to prefer
390+
# linking against the shared library. Issue #565.
391+
BUILD_DIR=$(< ${_buildd_shared}/pybuilddir.txt)
392+
SYSCONFIG=$(find ${_buildd_shared}/${BUILD_DIR} -name "_sysconfigdata*.py" -print0)
399393
cat ${SYSCONFIG} | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
400394
"${_FLAGS_REPLACE[@]}" \
401395
> ${PREFIX}/lib/python${VERABI_NO_DBG}/$(basename ${SYSCONFIG})
396+
BUILD_DETAILS=${_buildd_shared}/${BUILD_DIR}/build-details.json
397+
cp ${BUILD_DETAILS} ${PREFIX}/lib/python${VERABI_NO_DBG}/
402398
MAKEFILE=$(find ${PREFIX}/lib/python${VERABI_NO_DBG}/ -path "*config-*/Makefile" -print0)
403399
cp ${MAKEFILE} /tmp/Makefile-$$
404400
cat /tmp/Makefile-$$ | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
@@ -515,7 +511,6 @@ rm ${PREFIX}/lib/libpython${VERABI}.a
515511
if [[ ${PY_INTERP_DEBUG} == yes ]]; then
516512
rm ${PREFIX}/bin/python${VER}
517513
ln -s ${PREFIX}/bin/python${VERABI} ${PREFIX}/bin/python${VER}
518-
ln -s ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT} ${PREFIX}/lib/libpython${VERABI_NO_DBG}${SHLIB_EXT}
519514
ln -s ${PREFIX}/include/python${VERABI} ${PREFIX}/include/python${VER}
520515
fi
521516

recipe/build_shared.bat

Whitespace-only changes.

recipe/build_shared.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
_buildd_shared=build-shared
5+
if [[ ${PY_INTERP_DEBUG} == yes ]]; then
6+
DBG=d
7+
else
8+
DBG=
9+
fi
10+
if [[ ${PY_FREETHREADING} == yes ]]; then
11+
# This Python will not be usable with non-free threading Python modules.
12+
THREAD=t
13+
else
14+
THREAD=
15+
fi
16+
17+
VER=${PKG_VERSION%.*}
18+
ABIFLAGS=${DBG}${THREAD}
19+
VERABI=${VER}${THREAD}${DBG}
20+
VERABI_NO_DBG=${VER}${THREAD}
21+
22+
# Install the shared library (for people who embed Python only, e.g. GDB).
23+
# Linking module extensions to this on Linux is redundant (but harmless).
24+
# Linking module extensions to this on Darwin is harmful (multiply defined symbols).
25+
shopt -s extglob
26+
cp -pf ${_buildd_shared}/libpython*${SHLIB_EXT}!(.lto) ${PREFIX}/lib/
27+
shopt -u extglob
28+
if [[ ${target_platform} =~ .*linux.* ]]; then
29+
ln -sf ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT}.1.0 ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT}
30+
fi
31+
if [[ ${PY_INTERP_DEBUG} == yes ]]; then
32+
ln -s ${PREFIX}/lib/libpython${VERABI}${SHLIB_EXT} ${PREFIX}/lib/libpython${VERABI_NO_DBG}${SHLIB_EXT}
33+
fi

recipe/meta.yaml

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% set ver2 = '.'.join(version.split('.')[0:2]) %}
55
{% set ver2nd = ''.join(version.split('.')[0:2]) %}
66
{% set ver3nd = ''.join(version.split('.')[0:3]) %}
7-
{% set build_number = 0 %}
7+
{% set build_number = 1 %}
88

99
# this makes the linter happy
1010
{% set channel_targets = channel_targets or 'conda-forge main' %}
@@ -221,7 +221,6 @@ outputs:
221221
files:
222222
- tests/cmake/*
223223
- tests/cython/*
224-
- tests/prefix-replacement/*
225224
- run_test.py
226225
commands:
227226
- echo on # [win]
@@ -247,8 +246,11 @@ outputs:
247246
- _CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_conda_linux_gnu python -c "import sysconfig; print(sysconfig.get_config_var('CC'))" # [linux64]
248247
# check for unreplaced @ symbols in sysconfig files, excluding e.g. '"$@".lto'
249248
- for f in ${CONDA_PREFIX}/lib/python*/_sysconfig*.py; do echo "Checking $f:"; if [[ `rg @[^@]*@ $f` ]]; then echo "FAILED ON $f"; cat $f; exit 1; fi; done # [linux64 or osx]
250-
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.a # [unix]
251-
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.nolto.a # [unix]
249+
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.so # [unix]
250+
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.a # [unix]
251+
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.so # [linux]
252+
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.dylib # [osx]
253+
- test ! -f ${PREFIX}/lib/libpython${PKG_VERSION%.*}.nolto.a # [unix]
252254
{% if freethreading == "yes" %}
253255
- if not exist %PREFIX%\\libs\\python3t.lib exit 1 # [win]
254256
- if not exist %PREFIX%\\libs\\python{{ ver2nd }}t.lib exit 1 # [win]
@@ -265,14 +267,8 @@ outputs:
265267
- if not exist %PREFIX%\\Scripts\\pydoc.exe exit 1 # [win]
266268
- if not exist %PREFIX%\\include\\pyconfig.h exit 1 # [win]
267269
- pushd tests
268-
- pushd prefix-replacement # [unix]
269-
- bash build-and-test.sh # [unix]
270-
- popd # [unix]
271270
- pushd cmake
272-
{% if freethreading == "no" %}
273-
# TODO: use the new FindPython3 which supports freethreading
274-
- cmake -GNinja -DPY_VER={{ version }} --debug-find --trace --debug-output --debug-trycompile .
275-
{% endif %}
271+
- cmake -GNinja -DPY_VER={{ version }} -DEXTRA_COMPONENTS="Development.Module" --debug-find --trace --debug-output --debug-trycompile .
276272
- popd
277273
- popd
278274
- python run_test.py
@@ -283,6 +279,61 @@ outputs:
283279
# Test for wide character supported via ncursesw
284280
- TERM=xterm >/dev/null python -c "import curses; scr = curses.initscr(); curses.unget_wch('x'); assert 'x' == scr.get_wch()" # [unix]
285281

282+
- name: libpython
283+
script: build_shared.sh # [unix]
284+
script: build_shared.bat # [win]
285+
build:
286+
number: {{ build_number }}
287+
activate_in_script: true
288+
ignore_run_exports:
289+
- python_abi
290+
script_env:
291+
- PY_INTERP_DEBUG={{ py_interp_debug }}
292+
- PY_FREETHREADING={{ freethreading }}
293+
string: h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}{{ debug }}_{{ abi_tag }}
294+
requirements:
295+
build:
296+
- {{ compiler('c') }}
297+
- {{ stdlib('c') }}
298+
- {{ compiler('cxx') }}
299+
host:
300+
- {{ pin_subpackage('python', exact=True) }}
301+
run:
302+
- {{ pin_subpackage('python', exact=True) }}
303+
test:
304+
files:
305+
- tests/cmake/*
306+
- tests/prefix-replacement/*
307+
requires:
308+
- {{ stdlib('c') }}
309+
- {{ compiler('c') }}
310+
# cmake expects a C++ compiler for some reason
311+
- {{ compiler('cxx') }}
312+
- ripgrep
313+
- cmake
314+
- ninja
315+
commands:
316+
- VER=${PKG_VERSION%.*} # [not win]
317+
- VERABI=${VER} # [not win]
318+
{% if freethreading == "yes" %}
319+
- VERABI=${VERABI}t # [not win]
320+
{% endif %}
321+
- VERABI_NO_DBG=${VERABI} # [not win]
322+
{% if py_interp_debug == "yes" %}
323+
- VERABI=${VERABI}d # [not win]
324+
{% endif %}
325+
- test -f ${PREFIX}/lib/libpython${VERABI}.so # [linux]
326+
- test -f ${PREFIX}/lib/libpython3.so # [linux and build_type == "release"]
327+
- test -f ${PREFIX}/lib/libpython${VERABI}.dylib # [osx]
328+
- pushd tests
329+
- pushd prefix-replacement # [unix]
330+
- bash build-and-test.sh # [unix]
331+
- popd # [unix]
332+
- pushd cmake
333+
- cmake -GNinja -DPY_VER={{ version }} -DEXTRA_COMPONENTS="Development.Embed" --debug-find --trace --debug-output --debug-trycompile .
334+
- popd
335+
- popd
336+
286337
- name: libpython-static
287338
script: build_static.sh # [unix]
288339
script: build_static.bat # [win]
@@ -306,10 +357,16 @@ outputs:
306357
- {{ pin_subpackage('python', exact=True) }}
307358
test:
308359
files:
360+
- tests/cmake/*
309361
- tests/prefix-replacement/*
310362
requires:
311363
- {{ stdlib('c') }}
312364
- {{ compiler('c') }}
365+
# cmake expects a C++ compiler for some reason
366+
- {{ compiler('cxx') }}
367+
- ripgrep
368+
- cmake
369+
- ninja
313370
commands:
314371
- VER=${PKG_VERSION%.*} # [not win]
315372
- VERABI=${VER} # [not win]
@@ -323,9 +380,14 @@ outputs:
323380
- test -f ${PREFIX}/lib/libpython${VERABI}.a # [unix]
324381
- test -f ${PREFIX}/lib/libpython${VERABI_NO_DBG}.nolto.a # [unix]
325382
- test -f ${PREFIX}/lib/python${VERABI_NO_DBG}/config-${VERABI}-darwin/libpython${VERABI}.a # [osx]
326-
- pushd tests/prefix-replacement # [unix]
327-
- bash build-and-test.sh # [unix]
328-
- popd # [unix]
383+
- pushd tests
384+
- pushd prefix-replacement # [unix]
385+
- bash build-and-test.sh # [unix]
386+
- popd # [unix]
387+
- pushd cmake
388+
- cmake -GNinja -DPY_VER={{ version }} -DEXTRA_COMPONENTS="Development.Embed" --debug-find --trace --debug-output --debug-trycompile .
389+
- popd
390+
- popd
329391

330392
- name: cpython
331393
build:

recipe/tests/cmake/CMakeLists.txt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
# https://martinopilia.com/posts/2018/09/15/building-python-extension.html
2-
# FindPythonInterp and FindPythonLibs are deprecated since cmake 3.12
3-
# These can be replaced by find_package(Python ${PY_VER} REQUIRED)
4-
# But these are still used by other packages, so we keep them.
1+
# https://scikit-build-core.readthedocs.io/en/latest/guide/cmakelists.html#finding-python
52

63
cmake_minimum_required(VERSION 3.10)
74
enable_language(C)
85
project(mymath)
96

10-
option(PY_VER, "Python version to use")
7+
option(PY_VER "Python version to use")
8+
option(EXTRA_COMPONENTS "Additional Python components to check for")
119

12-
find_package(PythonInterp ${PY_VER} REQUIRED)
13-
# PATHS $ENV{CONDA_PREFIX}
14-
15-
# This goes after, since it uses PythonInterp as hint
16-
find_package(PythonLibs ${PY_VER} REQUIRED)
10+
find_package(Python ${PY_VER} COMPONENTS Interpreter ${EXTRA_COMPONENTS} REQUIRED)

0 commit comments

Comments
 (0)