diff --git a/examples/nanobind-project/cross-compile-linux.sh b/examples/nanobind-project/cross-compile-linux.sh index db3c4dc..8e7aa82 100755 --- a/examples/nanobind-project/cross-compile-linux.sh +++ b/examples/nanobind-project/cross-compile-linux.sh @@ -11,7 +11,7 @@ # # These toolchains include CMake toolchain files and configuration files for # py-build-cmake ({triple}.{python_version}.py-build-cmake cross.toml). When -# these configuration files are passed using the --cross argument, it will +# these configuration files are passed using the -C cross flag, it will # cause py-build-cmake to cross-compile the package for the given architecture # and Python version (which may be different from the architecture and version # of the Python interpreter that is used to drive the build process). @@ -23,13 +23,14 @@ cd "$(dirname "${BASH_SOURCE[0]}")" +# Select the architectures and Python versions to build for. triples=(x86_64-bionic-linux-gnu armv6-rpi-linux-gnueabihf armv7-neon-linux-gnueabihf aarch64-rpi3-linux-gnu) python_versions=("python3.8" "python3.9" "python3.10" "python3.11" "python3.12" "python3.13") pypy_triples=(x86_64-bionic-linux-gnu aarch64-rpi3-linux-gnu) pypy_versions=("pypy3.8-v7.3" "pypy3.9-v7.3" "pypy3.10-v7.3") -toolchain_folder="$PWD/../../toolchains" -build_python="$(which python3)" +# Ensure that the necessary toolchains are available. +toolchain_folder="$PWD/../../toolchains" if [ ! -d "$toolchain_folder/x-tools" ]; then echo "Cross-compilation toolchains not found." echo "Please run \"$(realpath "$PWD/../../scripts/download-cross-toolchains-linux.sh")\" first." @@ -38,29 +39,27 @@ fi set -ex -"$build_python" -m pip install --quiet --no-warn-script-location -U pip build +# Install PyPA build +python3 -m pip install --quiet --no-warn-script-location -U pip build + +# Link the C++ standard library statically to support systems that have an +# older version installed. Same for the GCC runtime library (libgcc). +export LDFLAGS="-static-libgcc -static-libstdc++" +# Cross-compile the package for CPython. for triple in ${triples[@]}; do - config="$triple.py-build-cmake.config.toml" - cat <<- EOF > "$config" - [cmake] - generator = "Ninja" - [cmake.options] - CMAKE_MODULE_LINKER_FLAGS = "-static-libgcc -static-libstdc++" - EOF - for py_version in ${python_versions[@]}; do + for python_version in ${python_versions[@]}; do rm -rf .py-build-cmake_cache - "$build_python" -m build . -w \ - -C--cross="$toolchain_folder/x-tools/$triple.$py_version.py-build-cmake.cross.toml" \ - -C--local="$PWD/$config" + python3 -m build . -w \ + -C cross="$toolchain_folder/x-tools/$triple.$python_version.py-build-cmake.cross.toml" done done +# Cross-compile the package for PyPy. for triple in ${pypy_triples[@]}; do - for py_version in ${pypy_versions[@]}; do + for python_version in ${pypy_versions[@]}; do rm -rf .py-build-cmake_cache - "$build_python" -m build . -w \ - -C--cross="$toolchain_folder/x-tools/$triple.$py_version.py-build-cmake.cross.toml" \ - -C--local="$PWD/$config" + python3 -m build . -w \ + -C cross="$toolchain_folder/x-tools/$triple.$python_version.py-build-cmake.cross.toml" done done diff --git a/examples/pybind11-project/cross-compile-linux.sh b/examples/pybind11-project/cross-compile-linux.sh index 0d59871..118e845 100755 --- a/examples/pybind11-project/cross-compile-linux.sh +++ b/examples/pybind11-project/cross-compile-linux.sh @@ -11,7 +11,7 @@ # # These toolchains include CMake toolchain files and configuration files for # py-build-cmake ({triple}.{python_version}.py-build-cmake cross.toml). When -# these configuration files are passed using the --cross argument, it will +# these configuration files are passed using the -C cross flag, it will # cause py-build-cmake to cross-compile the package for the given architecture # and Python version (which may be different from the architecture and version # of the Python interpreter that is used to drive the build process). @@ -23,13 +23,14 @@ cd "$(dirname "${BASH_SOURCE[0]}")" +# Select the architectures and Python versions to build for. triples=(x86_64-bionic-linux-gnu armv6-rpi-linux-gnueabihf armv7-neon-linux-gnueabihf aarch64-rpi3-linux-gnu) python_versions=("python3.7" "python3.8" "python3.9" "python3.10" "python3.11" "python3.12" "python3.13") pypy_triples=(x86_64-bionic-linux-gnu aarch64-rpi3-linux-gnu) pypy_versions=("pypy3.7-v7.3" "pypy3.8-v7.3" "pypy3.9-v7.3" "pypy3.10-v7.3") -toolchain_folder="$PWD/../../toolchains" -build_python="$(which python3)" +# Ensure that the necessary toolchains are available. +toolchain_folder="$PWD/../../toolchains" if [ ! -d "$toolchain_folder/x-tools" ]; then echo "Cross-compilation toolchains not found." echo "Please run \"$(realpath "$PWD/../../scripts/download-cross-toolchains-linux.sh")\" first." @@ -38,29 +39,27 @@ fi set -ex -"$build_python" -m pip install --quiet --no-warn-script-location -U pip build +# Install PyPA build +python3 -m pip install --quiet --no-warn-script-location -U pip build + +# Link the C++ standard library statically to support systems that have an +# older version installed. Same for the GCC runtime library (libgcc). +export LDFLAGS="-static-libgcc -static-libstdc++" +# Cross-compile the package for CPython. for triple in ${triples[@]}; do - config="$triple.py-build-cmake.config.toml" - cat <<- EOF > "$config" - [cmake] - generator = "Ninja" - [cmake.options] - CMAKE_MODULE_LINKER_FLAGS = "-static-libgcc -static-libstdc++" - EOF - for py_version in ${python_versions[@]}; do + for python_version in ${python_versions[@]}; do rm -rf .py-build-cmake_cache - "$build_python" -m build . -w \ - -C--cross="$toolchain_folder/x-tools/$triple.$py_version.py-build-cmake.cross.toml" \ - -C--local="$PWD/$config" + python3 -m build . -w \ + -C cross="$toolchain_folder/x-tools/$triple.$python_version.py-build-cmake.cross.toml" done done +# Cross-compile the package for PyPy. for triple in ${pypy_triples[@]}; do - for py_version in ${pypy_versions[@]}; do + for python_version in ${pypy_versions[@]}; do rm -rf .py-build-cmake_cache - "$build_python" -m build . -w \ - -C--cross="$toolchain_folder/x-tools/$triple.$py_version.py-build-cmake.cross.toml" \ - -C--local="$PWD/$config" + python3 -m build . -w \ + -C cross="$toolchain_folder/x-tools/$triple.$python_version.py-build-cmake.cross.toml" done done diff --git a/scripts/download-cross-toolchains-linux.sh b/scripts/download-cross-toolchains-linux.sh index 8bf5052..248aacc 100755 --- a/scripts/download-cross-toolchains-linux.sh +++ b/scripts/download-cross-toolchains-linux.sh @@ -8,19 +8,20 @@ cd "$( dirname "${BASH_SOURCE[0]}" )"/.. triples=(x86_64-bionic-linux-gnu armv6-rpi-linux-gnueabihf armv7-neon-linux-gnueabihf aarch64-rpi3-linux-gnu) +gcc_version="14" toolchain_version="0.1.0" python_dev_version="0.0.2" toolchain_folder="$PWD/toolchains" set -ex -mkdir -p "$toolchain_folder" +mkdir -p "$toolchain_folder/x-tools" for triple in ${triples[@]}; do - wget "https://github.com/tttapa/toolchains/releases/download/$toolchain_version/x-tools-$triple-gcc14.tar.xz" -O- | tar xJ -C "$toolchain_folder" + chmod u+w "$toolchain_folder/x-tools" + wget "https://github.com/tttapa/toolchains/releases/download/$toolchain_version/x-tools-$triple-gcc$gcc_version.tar.xz" -O- | tar xJ -C "$toolchain_folder" chmod u+w "$toolchain_folder/x-tools/$triple" wget "https://github.com/tttapa/python-dev/releases/download/$python_dev_version/python-dev-$triple.tar.xz" -O- | tar xJ -C "$toolchain_folder" - chmod u+w "$toolchain_folder/x-tools" done # To delete the toolchains again, use -# chmod -R u+w toolchains && rm -rf toolchains +# chmod -R u+w toolchains && rm -rf toolchains