diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de99f65..b444946 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,12 +121,14 @@ jobs: output-dir: wheelhouse env: # ---- Build selection ---- + # Linux/Windows: Python 3.10, 3.11, 3.12 + # macOS: Python 3.10, 3.11 only (skip 3.12) CIBW_BUILD: "cp310-* cp311-* cp312-*" - CIBW_SKIP: "pp* *-musllinux_*" + CIBW_SKIP: "pp* *-musllinux_* cp312-macosx*" CIBW_ARCHS: ${{ matrix.arch }} # ---- Dependencies ---- - CIBW_BEFORE_BUILD: pip install pybind11>=2.10.4 + CIBW_BEFORE_BUILD: pip install pybind11==2.10.1 # ---- Linux ---- CIBW_BEFORE_ALL_LINUX: bindings/python/tools/prepare_build_environment_linux.sh @@ -138,24 +140,8 @@ jobs: # ---- macOS ---- CIBW_BEFORE_ALL_MACOS: bindings/python/tools/prepare_build_environment_macos.sh - CIBW_ENVIRONMENT_MACOS: | - TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install - ICU_ROOT=${GITHUB_WORKSPACE}/icu - DYLD_LIBRARY_PATH=${GITHUB_WORKSPACE}/icu/lib:${DYLD_LIBRARY_PATH} - CIBW_REPAIR_WHEEL_COMMAND_MACOS: | - set -e - echo "=== Bundling ICU into wheel ===" - delocate-wheel -v -w {dest_dir} {wheel} - - REPAIRED_WHEEL=$(ls {dest_dir}/*.whl) - echo "=== Inspecting repaired wheel ===" - unzip -q "$REPAIRED_WHEEL" -d /tmp/wheel_check - SO_FILE=$(find /tmp/wheel_check -name "_ext*.so" | head -n1) - otool -L "$SO_FILE" - rm -rf /tmp/wheel_check - echo "=== Wheel ready: $REPAIRED_WHEEL ===" - - + CIBW_ENVIRONMENT_MACOS: TOKENIZER_ROOT=${GITHUB_WORKSPACE}/build/install + CIBW_REPAIR_WHEEL_COMMAND_MACOS: "" # ---- Windows ---- CIBW_BEFORE_ALL_WINDOWS: bash bindings/python/tools/prepare_build_environment_windows.sh @@ -164,6 +150,7 @@ jobs: # ---- Tests ---- CIBW_TEST_COMMAND: pytest {project}/bindings/python/test/test.py CIBW_TEST_REQUIRES: pytest + CIBW_TEST_SKIP: "*-macosx*" - name: Upload wheels uses: actions/upload-artifact@v4 diff --git a/bindings/python/setup.py b/bindings/python/setup.py index dc786f1..1ac44c9 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -40,7 +40,6 @@ def _maybe_add_library_root(lib_name, header_only=False): _maybe_add_library_root("TOKENIZER") -icu_lib_dir = _maybe_add_library_root("ICU") cflags = ["-std=c++17", "-fvisibility=hidden"] ldflags = [] @@ -48,19 +47,7 @@ def _maybe_add_library_root(lib_name, header_only=False): if sys.platform == "darwin": cflags.append("-mmacosx-version-min=10.14") - if icu_lib_dir: - icu_libs = ["icuuc", "icudata", "icui18n", "icuio"] - libraries.extend(icu_libs) - - # Link ICU with full paths so delocate can see it - for lib in icu_libs: - full_lib_path = os.path.join(icu_lib_dir, f"lib{lib}.dylib") - if os.path.isfile(full_lib_path): - ldflags.append(full_lib_path) - - # rpath for runtime - ldflags.append("-Wl,-rpath,@loader_path/../icu/lib") - + ldflags.append("-Wl,-rpath,/usr/local/lib") elif sys.platform == "win32": cflags = ["/std:c++17", "/d2FH4-"] package_data["pyonmttok"] = ["*.dll"] @@ -72,7 +59,7 @@ def _maybe_add_library_root(lib_name, header_only=False): extra_link_args=ldflags, include_dirs=include_dirs, library_dirs=library_dirs, - libraries=libraries, + libraries=["OpenNMTTokenizer"], ) setup( @@ -108,5 +95,7 @@ def _maybe_add_library_root(lib_name, header_only=False): packages=find_packages(), package_data=package_data, python_requires=">=3.10", + setup_requires=["pytest-runner"], + tests_require=["pytest"], ext_modules=[tokenizer_module], ) diff --git a/bindings/python/tools/prepare_build_environment_macos.sh b/bindings/python/tools/prepare_build_environment_macos.sh index 456cfec..fc7d33a 100755 --- a/bindings/python/tools/prepare_build_environment_macos.sh +++ b/bindings/python/tools/prepare_build_environment_macos.sh @@ -15,7 +15,8 @@ if [ ! -d "$ICU_ROOT/lib" ]; then rsync -a "$ICU_PREFIX/" "$ICU_ROOT/" fi -export DYLD_LIBRARY_PATH="$ICU_ROOT/lib:$DYLD_LIBRARY_PATH" +# Remove dynamic libraries to force static linking +rm -f "$ICU_ROOT/lib/"*.dylib || true if [[ "$(uname -m)" == "arm64" ]]; then CMAKE_EXTRA_ARGS="-DCMAKE_OSX_ARCHITECTURES=arm64" @@ -23,18 +24,17 @@ fi pip install cmake -rm -rf "$ROOT_DIR/build" -mkdir -p "$ROOT_DIR/build" +# Build Tokenizer +rm -rf build +mkdir build +cd build cmake \ - -S "$ROOT_DIR" \ - -B "$ROOT_DIR/build" \ -DLIB_ONLY=ON \ - -DBUILD_SHARED_LIBS=ON \ -DICU_ROOT="$ICU_ROOT" \ -DCMAKE_INSTALL_PREFIX="$ROOT_DIR/build/install" \ - -DCMAKE_INSTALL_RPATH="$ICU_ROOT/lib" \ - $CMAKE_EXTRA_ARGS + $CMAKE_EXTRA_ARGS \ + .. -cmake --build "$ROOT_DIR/build" --target install -j2 -export DYLD_LIBRARY_PATH="$ROOT_DIR/build/install/lib:$DYLD_LIBRARY_PATH" +VERBOSE=1 make -j2 install +cd "$ROOT_DIR"