From a21a3d7950b89e288472f8814b3e796637279471 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 9 Oct 2024 16:30:39 +0000 Subject: [PATCH 1/3] Update chaquopy-libcxx --- server/pypi/packages/chaquopy-libcxx/build.sh | 14 +++++++++----- server/pypi/packages/chaquopy-libcxx/meta.yaml | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/pypi/packages/chaquopy-libcxx/build.sh b/server/pypi/packages/chaquopy-libcxx/build.sh index 2d1aa77c4c..149e3225b7 100755 --- a/server/pypi/packages/chaquopy-libcxx/build.sh +++ b/server/pypi/packages/chaquopy-libcxx/build.sh @@ -1,13 +1,17 @@ #!/bin/bash -set -eu +set -eu -o pipefail -toolchain=$(realpath $(dirname $CC)/..) +toolchain=$(realpath $(dirname $AR)/..) -header_version=$(cat $toolchain/sysroot/usr/include/c++/v1/__libcpp_version) -if [[ $header_version != $PKG_VERSION ]]; then +pattern='^ *# *define +_LIBCPP_VERSION +([0-9]+)$' +header_version=$( + grep -E "$pattern" "$toolchain/sysroot/usr/include/c++/v1/__config" | + sed -E "s/$pattern/\1/" +) +if [ "$header_version" != "$PKG_VERSION" ]; then echo "Header version '$header_version' doesn't match meta.yaml version '$PKG_VERSION'" exit 1 fi mkdir -p $PREFIX/lib -cp $toolchain/sysroot/usr/lib/$CHAQUOPY_TRIPLET/libc++_shared.so $PREFIX/lib +cp $toolchain/sysroot/usr/lib/$HOST/libc++_shared.so $PREFIX/lib diff --git a/server/pypi/packages/chaquopy-libcxx/meta.yaml b/server/pypi/packages/chaquopy-libcxx/meta.yaml index af5d2dd9a3..c07b207e15 100644 --- a/server/pypi/packages/chaquopy-libcxx/meta.yaml +++ b/server/pypi/packages/chaquopy-libcxx/meta.yaml @@ -1,5 +1,5 @@ package: name: chaquopy-libcxx - version: "11000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py. + version: "180000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py. source: null From fd125d04f076738366c431a199149eec6a399cb5 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Tue, 22 Oct 2024 19:59:38 +0000 Subject: [PATCH 2/3] Make build-wheel get compiler library versions from the NDK using the same code as their own build scripts --- server/pypi/build-wheel.py | 12 ++++++------ server/pypi/packages/chaquopy-libcxx/build.sh | 10 +++------- server/pypi/packages/chaquopy-libcxx/meta.yaml | 6 +++++- server/pypi/packages/chaquopy-libcxx/version.sh | 9 +++++++++ server/pypi/packages/chaquopy-libomp/build.sh | 14 ++++++++++---- server/pypi/packages/chaquopy-libomp/meta.yaml | 6 +++++- server/pypi/packages/chaquopy-libomp/version.sh | 7 +++++++ 7 files changed, 45 insertions(+), 19 deletions(-) create mode 100755 server/pypi/packages/chaquopy-libcxx/version.sh create mode 100755 server/pypi/packages/chaquopy-libomp/version.sh diff --git a/server/pypi/build-wheel.py b/server/pypi/build-wheel.py index 4cd1e94b1e..166c76930a 100755 --- a/server/pypi/build-wheel.py +++ b/server/pypi/build-wheel.py @@ -48,12 +48,9 @@ # Not including chaquopy-libgfortran: the few packages which require it must specify it in # meta.yaml. That way its location will always be passed to the linker with an -L flag, and we # won't need to worry about the multilib subdirectory structure of the armeabi-v7a toolchain. -# -# TODO: break out the build script fragments which get the actual version numbers from the -# toolchain, and call them here. COMPILER_LIBS = { - "libc++_shared.so": ("chaquopy-libcxx", "11000"), - "libomp.so": ("chaquopy-libomp", "9.0.9"), + "libc++_shared.so": "chaquopy-libcxx", + "libomp.so": "chaquopy-libomp", } @@ -852,7 +849,10 @@ def check_requirements(self, filename, available_libs): if tag.entry.d_tag == "DT_NEEDED": req = COMPILER_LIBS.get(tag.needed) if req: - reqs.append(req) + version = run( + f"{RECIPES_DIR}/{req}/version.sh", capture_output=True + ).stdout.strip() + reqs.append((req, version)) elif tag.needed in available_libs: pass else: diff --git a/server/pypi/packages/chaquopy-libcxx/build.sh b/server/pypi/packages/chaquopy-libcxx/build.sh index 149e3225b7..e7ef5d5d1d 100755 --- a/server/pypi/packages/chaquopy-libcxx/build.sh +++ b/server/pypi/packages/chaquopy-libcxx/build.sh @@ -3,13 +3,9 @@ set -eu -o pipefail toolchain=$(realpath $(dirname $AR)/..) -pattern='^ *# *define +_LIBCPP_VERSION +([0-9]+)$' -header_version=$( - grep -E "$pattern" "$toolchain/sysroot/usr/include/c++/v1/__config" | - sed -E "s/$pattern/\1/" -) -if [ "$header_version" != "$PKG_VERSION" ]; then - echo "Header version '$header_version' doesn't match meta.yaml version '$PKG_VERSION'" +ndk_version=$("$RECIPE_DIR/version.sh") +if [ "$ndk_version" != "$PKG_VERSION" ]; then + echo "Version '$ndk_version' from NDK doesn't match version '$PKG_VERSION' from meta.yaml" exit 1 fi diff --git a/server/pypi/packages/chaquopy-libcxx/meta.yaml b/server/pypi/packages/chaquopy-libcxx/meta.yaml index c07b207e15..ce9b5926a6 100644 --- a/server/pypi/packages/chaquopy-libcxx/meta.yaml +++ b/server/pypi/packages/chaquopy-libcxx/meta.yaml @@ -1,5 +1,9 @@ +# Updates to this package should be backward-compatible, but it doesn't always work that +# way, so make sure to test new versions with existing packages +# (https://github.com/chaquo/chaquopy/issues/1171#issuecomment-2402757412). + package: name: chaquopy-libcxx - version: "180000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py. + version: "180000" # See version.sh. source: null diff --git a/server/pypi/packages/chaquopy-libcxx/version.sh b/server/pypi/packages/chaquopy-libcxx/version.sh new file mode 100755 index 0000000000..c1e0f831a9 --- /dev/null +++ b/server/pypi/packages/chaquopy-libcxx/version.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -eu -o pipefail + +toolchain=$(realpath $(dirname $AR)/..) + +pattern='^ *# *define +_LIBCPP_VERSION +([0-9]+)$' + +grep -E "$pattern" "$toolchain/sysroot/usr/include/c++/v1/__config" | + sed -E "s/$pattern/\1/" diff --git a/server/pypi/packages/chaquopy-libomp/build.sh b/server/pypi/packages/chaquopy-libomp/build.sh index ef04d39cc3..5bae45a2b9 100755 --- a/server/pypi/packages/chaquopy-libomp/build.sh +++ b/server/pypi/packages/chaquopy-libomp/build.sh @@ -1,8 +1,14 @@ #!/bin/bash -set -eu +set -eu -o pipefail -toolchain=$(realpath $(dirname $CC)/..) -arch=$(echo $CHAQUOPY_TRIPLET | sed 's/-.*//; s/i686/i386/') +toolchain=$(realpath $(dirname $AR)/..) +arch=$(echo $HOST | sed 's/-.*//; s/i686/i386/') + +ndk_version=$("$RECIPE_DIR/version.sh") +if [ "$ndk_version" != "$PKG_VERSION" ]; then + echo "Version '$ndk_version' from NDK doesn't match version '$PKG_VERSION' from meta.yaml" + exit 1 +fi mkdir -p $PREFIX/lib -cp $toolchain/lib64/clang/$PKG_VERSION/lib/linux/$arch/libomp.so $PREFIX/lib +cp $toolchain/lib/clang/$PKG_VERSION/lib/linux/$arch/libomp.so $PREFIX/lib diff --git a/server/pypi/packages/chaquopy-libomp/meta.yaml b/server/pypi/packages/chaquopy-libomp/meta.yaml index ef4995f065..5551595df7 100644 --- a/server/pypi/packages/chaquopy-libomp/meta.yaml +++ b/server/pypi/packages/chaquopy-libomp/meta.yaml @@ -1,5 +1,9 @@ +# Updates to this package should be backward-compatible, but it doesn't always work that +# way, so make sure to test new versions with existing packages +# (https://github.com/chaquo/chaquopy/issues/1171#issuecomment-2402757412). + package: name: chaquopy-libomp - version: "9.0.9" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py. + version: "9.0.9" # See version.sh. source: null diff --git a/server/pypi/packages/chaquopy-libomp/version.sh b/server/pypi/packages/chaquopy-libomp/version.sh new file mode 100755 index 0000000000..2f9f583e92 --- /dev/null +++ b/server/pypi/packages/chaquopy-libomp/version.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -eu -o pipefail + +toolchain=$(realpath $(dirname $AR)/..) + +cd $toolchain/lib/clang +echo * From 77b419789962ee6ffe43631f6472d2c8098ac5e0 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Tue, 22 Oct 2024 20:17:55 +0000 Subject: [PATCH 3/3] Rebuild greenlet and dlib against new libc++ --- server/pypi/packages/cmake-example/meta.yaml | 7 +++---- server/pypi/packages/cmake-example/patches/chaquopy.patch | 6 ------ server/pypi/packages/dlib/meta.yaml | 4 ++-- server/pypi/packages/dlib/patches/chaquopy.patch | 8 ++++---- server/pypi/packages/greenlet/meta.yaml | 2 +- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/server/pypi/packages/cmake-example/meta.yaml b/server/pypi/packages/cmake-example/meta.yaml index 72ad05fc14..2fb35265c7 100644 --- a/server/pypi/packages/cmake-example/meta.yaml +++ b/server/pypi/packages/cmake-example/meta.yaml @@ -1,8 +1,7 @@ -# This recipe contains three patches to add libpython to the link. Each package will -# probably only need one of those patches, but we keep them all for two reasons: +# This recipe contains a patch to add libpython to the link. It should be possible to +# apply this to any other package by copying the patch file and adjusting the paths. # -# * To serve as an example for other packages. -# * As the basis for a future PR to merge this into upstream pybind11. +# TODO: make this into a PR and submit it to upstream pybind11. package: name: cmake_example diff --git a/server/pypi/packages/cmake-example/patches/chaquopy.patch b/server/pypi/packages/cmake-example/patches/chaquopy.patch index c6976b23dd..4a6a8d164c 100644 --- a/server/pypi/packages/cmake-example/patches/chaquopy.patch +++ b/server/pypi/packages/cmake-example/patches/chaquopy.patch @@ -1,5 +1,3 @@ -diff --git a/pybind11/CMakeLists.txt b/pybind11/CMakeLists.txt -index 2a3e1ed7..dcd8f98a 100644 --- a/pybind11/CMakeLists.txt +++ b/pybind11/CMakeLists.txt @@ -105,7 +105,7 @@ if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) # CMake >= 3.0 @@ -11,8 +9,6 @@ index 2a3e1ed7..dcd8f98a 100644 target_link_libraries(module INTERFACE $) elseif(APPLE) target_link_libraries(module INTERFACE "-undefined dynamic_lookup") -diff --git a/pybind11/tools/pybind11Config.cmake.in b/pybind11/tools/pybind11Config.cmake.in -index 3dd1b2c1..3e96af80 100644 --- a/pybind11/tools/pybind11Config.cmake.in +++ b/pybind11/tools/pybind11Config.cmake.in @@ -86,7 +86,7 @@ if(NOT TARGET ${PN}::pybind11) @@ -24,8 +20,6 @@ index 3dd1b2c1..3e96af80 100644 set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) endif() -diff --git a/pybind11/tools/pybind11Tools.cmake b/pybind11/tools/pybind11Tools.cmake -index a7c471a0..dbb84c3f 100644 --- a/pybind11/tools/pybind11Tools.cmake +++ b/pybind11/tools/pybind11Tools.cmake @@ -146,8 +146,8 @@ function(pybind11_add_module target_name) diff --git a/server/pypi/packages/dlib/meta.yaml b/server/pypi/packages/dlib/meta.yaml index e13aa35e8d..fe286bdb9c 100644 --- a/server/pypi/packages/dlib/meta.yaml +++ b/server/pypi/packages/dlib/meta.yaml @@ -3,11 +3,11 @@ package: version: "19.19.0" build: - number: 4 + number: 5 requirements: build: - - cmake + - cmake 3.28.1 host: - chaquopy-openblas 0.2.20 diff --git a/server/pypi/packages/dlib/patches/chaquopy.patch b/server/pypi/packages/dlib/patches/chaquopy.patch index aa254c6534..9448e32f30 100644 --- a/server/pypi/packages/dlib/patches/chaquopy.patch +++ b/server/pypi/packages/dlib/patches/chaquopy.patch @@ -6,17 +6,17 @@ diff -ur src-original/setup.py src/setup.py '-DPYTHON_EXECUTABLE=' + sys.executable] + # Chaquopy -+ abi = os.environ["CHAQUOPY_ABI"] ++ host = os.environ["HOST"] + cmake_args += [ -+ "-DCMAKE_TOOLCHAIN_FILE=" + os.path.abspath("../chaquopy.toolchain.cmake"), ++ "-DCMAKE_VERBOSE_MAKEFILE=TRUE", + "-DDLIB_USE_CUDA=no", + + # By default, dlib/cmake_utils/set_compiler_specific_options.cmake sets these + # options by running executables on the host, so force them according to + # https://developer.android.com/ndk/guides/abis. -+ f"-DSSE4_IS_AVAILABLE_ON_HOST={abi == 'x86_64'}", ++ f"-DSSE4_IS_AVAILABLE_ON_HOST={host.startswith('x86_64')}", + f"-DAVX_IS_AVAILABLE_ON_HOST=False", -+ f"-DARM_NEON_IS_AVAILABLE={abi == 'arm64-v8a'}", ++ f"-DARM_NEON_IS_AVAILABLE={host.startswith('arm')}", + ] + cmake_args += cmake_extra_options diff --git a/server/pypi/packages/greenlet/meta.yaml b/server/pypi/packages/greenlet/meta.yaml index 419e6af506..86c7873e0a 100644 --- a/server/pypi/packages/greenlet/meta.yaml +++ b/server/pypi/packages/greenlet/meta.yaml @@ -3,4 +3,4 @@ package: version: "3.0.1" build: - number: 0 + number: 1