Skip to content
Open
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
2 changes: 0 additions & 2 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion anaconda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ upstream_sources:
from_pattern: ^v(\d+\.\d+\.\d+)$
to_pattern: \1
packages:
- python
- libpython
- libpython-static
- python
- cpython
- python-freethreading
- python-gil
- python-jit
Expand Down
9 changes: 8 additions & 1 deletion recipe/build_base.bat
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if "%DEBUG_C%"=="yes" (
:: AP doesn't support PGO atm?
set PGO=

if "%PY_GIL_DISABLED%" == "yes" (
if "%PY_FREETHREADING%" == "yes" (
set "FREETHREADING=--disable-gil"
set "THREAD=t"
set "EXE_T=%VER%t"
Expand All @@ -75,6 +75,13 @@ set TCLTK_MSBUILD_PROPS="/p:TclVersion=%tk%" "/p:TkVersion=%tk%"

cd PCbuild

:: CF (skipped): CONDA_BUILD_CROSS_COMPILATION host-vs-build extra MSBuild.
:: AR native workers only; ARCH/BUILD_PATH above, not CF HOST_DIR/BUILD_DIR.
:: if "%CONDA_BUILD_CROSS_COMPILATION%" == "1" (
:: set LIBRARY_PREFIX=%BUILD_PREFIX%\\Library
:: call build.bat %CONFIG% %FREETHREADING% -m -e -v -p %BUILD_PLATFORM% %TCLTK_MSBUILD_PROPS%
:: )

:: Twice because:
:: error : importlib_zipimport.h updated. You will need to rebuild pythoncore to see the changes.
call build.bat %PGO% %CONFIG% %FREETHREADING% -m -e -v -p %PLATFORM% %TCLTK_MSBUILD_PROPS%
Expand Down
80 changes: 53 additions & 27 deletions recipe/build_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cp $BUILD_PREFIX/share/libtool/build-aux/config.* .
# https://docs.python.org/3.14/using/configure.html#cmdoption-enable-experimental-jit
# says we want a python>=3.11 to build python.
if [[ ! -d ${SRC_DIR}/python-bin ]]; then
# AR: bootstrap from main (CF uses -c conda-forge).
CONDA_SUBDIR=$build_platform conda create -p ${SRC_DIR}/python-bin "python>=3.11" -c main --override-channels --yes --quiet
export PATH=${SRC_DIR}/python-bin/bin:${PATH}
fi
Expand All @@ -35,40 +36,40 @@ _buildd_shared=build-shared
_ENABLE_SHARED=--enable-shared
# We *still* build a shared lib here for non-static embedded use cases
_DISABLE_SHARED=--disable-shared
# Hack to allow easily comparing static vs shared interpreter performance
# .. hack because we just build it shared in both the build-static and
# build-shared directories.
# Yes this hack is a bit confusing, sorry about that.
if [[ ${PY_INTERP_LINKAGE_NATURE} == shared ]]; then
_DISABLE_SHARED=--enable-shared
_ENABLE_SHARED=--enable-shared
fi

# For debugging builds, set this to no to disable profile-guided optimization
if [[ ${DEBUG_C} == yes ]]; then
if [[ ${PY_INTERP_DEBUG} == yes || ${DEBUG_C} == yes ]]; then
_OPTIMIZED=no
else
_OPTIMIZED=yes
fi

# CF (skipped): debug builds on conda-forge main must not ship; AR has no python_debug channel.
# if [[ ${PY_INTERP_DEBUG} == yes ]]; then
# if [[ "$CI" != "" && "$channel_targets" == "conda-forge main" ]]; then
# exit 1
# fi
# fi

declare -a _dbg_opts
if [[ ${DEBUG_PY} == yes ]]; then
if [[ ${PY_INTERP_DEBUG} == yes ]]; then
# This Python will not be usable with non-debug Python modules.
_dbg_opts+=(--with-pydebug)
DBG=d
else
DBG=
fi

if [[ ${PY_GIL_DISABLED} == yes ]]; then
if [[ ${PY_FREETHREADING} == yes ]]; then
# This Python will not be usable with non-free threading Python modules.
THREAD=t
else
THREAD=
fi

ABIFLAGS=${DBG}
ABIFLAGS=${DBG}${THREAD}
VERABI=${VER}${THREAD}${DBG}
VERABI_NO_DBG=${VER}${THREAD}

# Make sure the "python" value in conda_build_config.yaml is up to date.
test "${PY_VER}" = "${VER}"
Expand Down Expand Up @@ -107,6 +108,12 @@ if [[ ${_OPTIMIZED} = yes ]]; then
CXXFLAGS=$(echo "${CXXFLAGS}" | sed "s/-O2/-O3/g")
fi

if [[ ${PY_INTERP_DEBUG} == yes ]]; then
CPPFLAGS=$(echo "${CPPFLAGS}" | sed "s/-O2/-O0/g")
CFLAGS=$(echo "${CFLAGS}" | sed "s/-O2/-O0/g")
CXXFLAGS=$(echo "${CXXFLAGS}" | sed "s/-O2/-O0/g")
fi

if [[ "$target_platform" == linux-* ]]; then
cp ${PREFIX}/include/uuid/uuid.h ${PREFIX}/include/uuid.h
fi
Expand Down Expand Up @@ -170,6 +177,7 @@ if [[ "${CONDA_BUILD_CROSS_COMPILATION}" == "1" ]]; then
echo "ac_cv_file__dev_ptc=no" >> config.site
echo "ac_cv_pthread=yes" >> config.site
echo "ac_cv_little_endian_double=yes" >> config.site
# CF also lists linux-riscv64 here; AR does not build it.
if [[ "${target_platform}" == "osx-arm64" || "${target_platform}" == "linux-ppc64le" || "${target_platform}" == "linux-aarch64" ]]; then
echo "ac_cv_aligned_required=no" >> config.site
echo "ac_cv_pthread_is_default=yes" >> config.site
Expand Down Expand Up @@ -207,6 +215,7 @@ if [[ ${target_platform} == osx-64 ]]; then
# TODO: check with LLVM 12 if the following hack is needed.
# https://reviews.llvm.org/D76461 may have fixed the need for the following hack.
echo '#!/bin/bash' > $BUILD_PREFIX/bin/$HOST-llvm-ar
# AR: versioned llvm-ar (CF uses unversioned llvm-ar → LLVM 20 Abort).
echo "$BUILD_PREFIX/bin/llvm-ar-$LLVM_VER --format=darwin" '"$@"' >> $BUILD_PREFIX/bin/$HOST-llvm-ar
chmod +x $BUILD_PREFIX/bin/$HOST-llvm-ar
export ARCHFLAGS="-arch x86_64"
Expand Down Expand Up @@ -253,14 +262,13 @@ _common_configure_args+=(--with-tzpath=${PREFIX}/share/zoneinfo)
_common_configure_args+=(--with-computed-gotos)
_common_configure_args+=(--with-system-expat)
_common_configure_args+=(--enable-loadable-sqlite-extensions)
# TODO: Remove this comment in PR#256
# Dropped dead tcltk configure flags — log-confirmed unused in 3.15.0rc2:
# configure: WARNING: unrecognized options: --with-tcltk-includes, --with-tcltk-libs
# _tkinter already comes from pkg-config.
_common_configure_args+=(--with-platlibdir=lib)
_common_configure_args+=(--with-system-libmpdec=yes)

if [[ "${DEBUG_PY}" == "yes" || "${target_platform}" != *"64" || ${PY_GIL_DISABLED} == yes ]]; then
if [[ "${PY_INTERP_DEBUG}" == "yes" || "${target_platform}" != *"-64" || ${PY_FREETHREADING} == yes ]]; then
_common_configure_args+=(--enable-experimental-jit=no)
else
_common_configure_args+=(--enable-experimental-jit=yes-off)
Expand All @@ -271,7 +279,7 @@ if [[ "${target_platform}" == osx-* ]]; then
_common_configure_args+=(--with-tail-call-interp)
fi

if [[ ${PY_GIL_DISABLED} == yes ]]; then
if [[ ${PY_FREETHREADING} == yes ]]; then
_common_configure_args+=(--disable-gil)
fi

Expand Down Expand Up @@ -337,8 +345,8 @@ pushd ${_buildd_static}
popd

make -j${CPU_COUNT} -C ${_buildd_static} \
EXTRA_CFLAGS="${EXTRA_CFLAGS}" \
${_MAKE_TARGET} "${_PROFILE_TASK[@]}" 2>&1 | tee make-static.log
EXTRA_CFLAGS="${EXTRA_CFLAGS}" \
${_MAKE_TARGET} "${_PROFILE_TASK[@]}" 2>&1 | tee make-static.log
if rg "Failed to build these modules" make-static.log; then
echo "(static) :: Failed to build some modules, check the log"
exit 1
Expand Down Expand Up @@ -370,7 +378,7 @@ fi
# build a static library with PIC objects and without LTO/PGO
make -j${CPU_COUNT} -C ${_buildd_shared} \
EXTRA_CFLAGS="${EXTRA_CFLAGS}" \
LIBRARY=libpython${VERABI}-pic.a libpython${VERABI}-pic.a
LIBRARY=libpython${VERABI_NO_DBG}-pic.a libpython${VERABI_NO_DBG}-pic.a

make -C ${_buildd_static} install

Expand All @@ -389,13 +397,23 @@ if [[ ${_OPTIMIZED} == yes ]]; then
_FLAGS_REPLACE+=("")
done
fi
# Use sysconfigdata from the shared build, as we want packages to prefer
# linking against the shared library. Issue #565.
SYSCONFIG=$(find ${_buildd_shared}/$(cat ${_buildd_shared}/pybuilddir.txt) -name "_sysconfigdata*.py" -print0)
# Use sysconfig from the shared build so extensions prefer .so (CF #565).
# Shared libpython*.so/.dylib is installed by the libpython output, not here.
BUILD_DIR=$(< ${_buildd_shared}/pybuilddir.txt)
SYSCONFIG=$(find ${_buildd_shared}/${BUILD_DIR} -name "_sysconfigdata*.py" -print0)
cat ${SYSCONFIG} | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
"${_FLAGS_REPLACE[@]}" \
> ${PREFIX}/lib/python${VERABI}/$(basename ${SYSCONFIG})
MAKEFILE=$(find ${PREFIX}/lib/python${VERABI}/ -path "*config-*/Makefile" -print0)
> ${PREFIX}/lib/python${VERABI_NO_DBG}/$(basename ${SYSCONFIG})
# CF copies build-details.json from the shared build (#565). Native only:
# AR does not cross-compile (CONDA_BUILD_CROSS_COMPILATION is never 1).
# if [[ "${CONDA_BUILD_CROSS_COMPILATION}" == "1" ]]; then
# # build-details.json is incorrect when cross-compiling:
# # https://github.com/python/cpython/issues/136267
# ...
# fi
BUILD_DETAILS=${_buildd_shared}/${BUILD_DIR}/build-details.json
cp ${BUILD_DETAILS} ${PREFIX}/lib/python${VERABI_NO_DBG}/
MAKEFILE=$(find ${PREFIX}/lib/python${VERABI_NO_DBG}/ -path "*config-*/Makefile" -print0)
cp ${MAKEFILE} /tmp/Makefile-$$
cat /tmp/Makefile-$$ | ${SYS_PYTHON} "${RECIPE_DIR}"/replace-word-pairs.py \
"${_FLAGS_REPLACE[@]}" \
Expand All @@ -417,7 +435,7 @@ ln -s ${PREFIX}/bin/pydoc${VER} ${PREFIX}/bin/pydoc
# Remove test data to save space
# Though keep `support` as some things use that.
# TODO :: Make a subpackage for this once we implement multi-level testing.
pushd ${PREFIX}/lib/python${VERABI}
pushd ${PREFIX}/lib/python${VERABI_NO_DBG}
mkdir test_keep
mv test/__init__.py test/support test/test_support* test/test_script_helper* test_keep/
rm -rf test */test
Expand All @@ -430,7 +448,7 @@ pushd ${PREFIX}
chmod +w lib/libpython${VERABI}.a
${STRIP} -S lib/libpython${VERABI}.a
fi
CONFIG_LIBPYTHON=$(find lib/python${VERABI}/config-${VERABI}* -name "libpython${VERABI}.a")
CONFIG_LIBPYTHON=$(find lib/python${VERABI_NO_DBG}/config-${VERABI}* -name "libpython${VERABI}.a")
if [[ -f lib/libpython${VERABI}.a ]] && [[ -f ${CONFIG_LIBPYTHON} ]]; then
chmod +w ${CONFIG_LIBPYTHON}
rm ${CONFIG_LIBPYTHON}
Expand All @@ -440,7 +458,7 @@ popd
# Copy sysconfig that gets recorded to a non-default name
# using the new compilers with python will require setting _PYTHON_SYSCONFIGDATA_NAME
# to the name of this file (minus the .py extension)
pushd "${PREFIX}"/lib/python${VERABI}
pushd "${PREFIX}"/lib/python${VERABI_NO_DBG}
# On Python 3.5 _sysconfigdata.py was getting copied in here and compiled for some reason.
# This breaks our attempt to find the right one as recorded_name.
find lib-dynload -name "_sysconfigdata*.py*" -exec rm {} \;
Expand Down Expand Up @@ -497,6 +515,7 @@ pushd "${PREFIX}"/lib/python${VERABI}
popd

if [[ ${HOST} =~ .*linux.* ]]; then
# AR: historical path (CF uses share/python_compiler_compat).
mkdir -p ${PREFIX}/compiler_compat
ln -s ${PREFIX}/bin/${HOST}-ld ${PREFIX}/compiler_compat/ld
echo "Files in this folder are to enhance backwards compatibility of anaconda software with older compilers." > ${PREFIX}/compiler_compat/README
Expand All @@ -505,6 +524,13 @@ fi

python -c "import compileall,os;compileall.compile_dir(os.environ['PREFIX'])"
rm ${PREFIX}/lib/libpython${VERABI}.a

if [[ ${PY_INTERP_DEBUG} == yes ]]; then
rm ${PREFIX}/bin/python${VER}
ln -s ${PREFIX}/bin/python${VERABI} ${PREFIX}/bin/python${VER}
ln -s ${PREFIX}/include/python${VERABI} ${PREFIX}/include/python${VER}
fi

if [[ "$target_platform" == linux-* ]]; then
rm ${PREFIX}/include/uuid.h
fi
Expand All @@ -522,7 +548,7 @@ fi
# <prefix>/lib/python3.13t/site-packages.
# Note that these directories are not added to sys.path if they do not exist.
SP_DIR="${PREFIX}/lib/python${PY_VER}${THREAD}/site-packages"
if [[ ${PY_GIL_DISABLED} == yes ]]; then
if [[ ${PY_FREETHREADING} == yes ]]; then
echo "${PREFIX}/lib/python${PY_VER}/site-packages" >> $SP_DIR/conda-site.pth
fi
# Do not add ${PREFIX}/lib/python/site-packages (CF experimental ABI3/noarch
Expand Down
14 changes: 10 additions & 4 deletions recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ python_impl:
# Override aggregate global tk 8.6 — build/test against tk 9 from pkgs/main
tk:
- '9.0'
gil_type:
- normal
# Will be enabled as part of https://anaconda.atlassian.net/browse/PKG-5855
- disabled # [not (s390x or (osx and x86_64))]
# Whether to build free-threaded Python (3.13+)
freethreading:
- yes
- no

# Debug interpreter lives on PR #258 / PKG-2624, not this CF-align PR.
# Do not zip with channel_targets (F94): all variants upload to
# ad-testing/label/py315.
build_type:
- release

# Override aggregate global clang 20 on osx. CPython 3.15 JIT requires LLVM 21
# (Tools/jit/_llvm.py); mixing compiler('c')=20 with clang-21/llvm-tools-21
Expand Down
Loading