Skip to content

Commit

Permalink
Merge pull request #1262 from mhsmith/libcxx-update
Browse files Browse the repository at this point in the history
Update chaquopy-libcxx
  • Loading branch information
mhsmith authored Oct 22, 2024
2 parents 003fa15 + 77b4197 commit 3cb3528
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 35 deletions.
12 changes: 6 additions & 6 deletions server/pypi/build-wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}


Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions server/pypi/packages/chaquopy-libcxx/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/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
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

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
6 changes: 5 additions & 1 deletion server/pypi/packages/chaquopy-libcxx/meta.yaml
Original file line number Diff line number Diff line change
@@ -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: "11000" # See PKG_VERSION in build.sh, and COMPILER_LIBS in build-wheel.py.
version: "180000" # See version.sh.

source: null
9 changes: 9 additions & 0 deletions server/pypi/packages/chaquopy-libcxx/version.sh
Original file line number Diff line number Diff line change
@@ -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/"
14 changes: 10 additions & 4 deletions server/pypi/packages/chaquopy-libomp/build.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion server/pypi/packages/chaquopy-libomp/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions server/pypi/packages/chaquopy-libomp/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -eu -o pipefail

toolchain=$(realpath $(dirname $AR)/..)

cd $toolchain/lib/clang
echo *
7 changes: 3 additions & 4 deletions server/pypi/packages/cmake-example/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions server/pypi/packages/cmake-example/patches/chaquopy.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,8 +9,6 @@ index 2a3e1ed7..dcd8f98a 100644
target_link_libraries(module INTERFACE $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/pypi/packages/dlib/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions server/pypi/packages/dlib/patches/chaquopy.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/pypi/packages/greenlet/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package:
version: "3.0.1"

build:
number: 0
number: 1

0 comments on commit 3cb3528

Please sign in to comment.