Skip to content
Merged
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
94 changes: 94 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,107 @@ jobs:
name: cibw-macos-${{ matrix.macos }}-${{ matrix.cpy }}-macosx_${{ matrix.arch }}
path: ./wheelhouse/*.whl

windows:
name: Windows wheels (${{ matrix.cpy }}-${{ matrix.cibw_build_suffix }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
arch:
- "AMD64"
- "ARM64"
- "x86"
cpy:
- "cp310"
- "cp311"
- "cp312"
- "cp313"
- "cp314"
- "cp314t"
include:
- arch: "AMD64"
runner: "windows-latest"
cibw_build_suffix: "win_amd64"
icu_plat: "Win64-MSVC2022"
icu_lib_suffix: "64"
- arch: "ARM64"
runner: "windows-11-arm"
cibw_build_suffix: "win_arm64"
icu_plat: "WinARM64-MSVC2022"
icu_lib_suffix: "ARM64"
- arch: "x86"
runner: "windows-latest"
cibw_build_suffix: "win32"
icu_plat: "Win32-MSVC2022"
icu_lib_suffix: ""

env:
_LIBICU_DIR: "C:\\icu"

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Hatch
run: pip install --upgrade hatch

- name: Cache pyicu
id: cache-pyicu
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/pyicu
key: ${{ runner.os }}-pyicu-${{ env.PYICU_VERSION }}

- name: Fetch pyicu source
if: steps.cache-pyicu.outputs.cache-hit != 'true'
run: hatch run pyicu:clone

- name: Copy src and tests
run: |
hatch run pyicu:src
hatch run pyicu:tests

- name: Cache libicu
id: cache-libicu
uses: actions/cache@v4
with:
path: C:\icu
key: libicu-windows-${{ matrix.arch }}-${{ env.LIBICU_VERSION }}

- name: Install libicu
if: steps.cache-libicu.outputs.cache-hit != 'true'
run: powershell -File scripts/install-libicu.ps1
env:
ICU_PLAT: ${{ matrix.icu_plat }}
ICU_LIB_SUFFIX: ${{ matrix.icu_lib_suffix }}

- name: Copy ICU DLLs to package
run: Copy-Item -Path "$env:_LIBICU_DIR\bin\icu*.dll" -Destination "src\icu\" -Force
shell: pwsh

- name: Build wheels
uses: pypa/cibuildwheel@v3.2.0
env:
CIBW_BUILD: ${{ matrix.cpy }}-${{ matrix.cibw_build_suffix }}
CIBW_ARCHS_WINDOWS: ${{ matrix.arch }}

- uses: actions/upload-artifact@v4
with:
name: cibw-windows-${{ matrix.cpy }}-${{ matrix.cibw_build_suffix }}
path: ./wheelhouse/*.whl

publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
name: Publish wheels
runs-on: ubuntu-latest
needs:
- linux
- macos
- windows
environment:
name: release
url: https://pypi.org/project/pyicu-wheels
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ skip-install = true

[tool.hatch.envs.pyicu.scripts]
clone = "git clone --branch=v{env:PYICU_VERSION} --depth=1 {env:PYICU_URL}"
src = "cp {root:real}/pyicu/py/icu/* {root:real}/src/icu/"
tests = "cp {root:real}/pyicu/test/* {root:real}/tests/"
src = "python scripts/copy-files.py {root:real}/pyicu/py/icu {root:real}/src/icu"
tests = "python scripts/copy-files.py {root:real}/pyicu/test {root:real}/tests"


[tool.hatch.envs.compile]
Expand Down Expand Up @@ -92,6 +92,9 @@ musllinux-aarch64-image = "musllinux_1_2"
musllinux-ppc64le-image = "musllinux_1_2"
# repair-wheel-command = "auditwheel repair -w {dest_dir} {wheel}"

[tool.cibuildwheel.windows]
archs = ["AMD64", "ARM64", "x86"]


[tool.hatch.build.targets.wheel]
packages = ["src/icu"]
Expand Down
16 changes: 16 additions & 0 deletions scripts/copy-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Cross-platform file copy utility for hatch scripts."""

import pathlib
import shutil
import sys


def main() -> None:
src = pathlib.Path(sys.argv[1])
dst = pathlib.Path(sys.argv[2])

shutil.copytree(src=src, dst=dst, dirs_exist_ok=True)


if __name__ == "__main__":
main()
24 changes: 24 additions & 0 deletions scripts/install-libicu.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$ErrorActionPreference = "Stop"

$ICU_PLAT = $env:ICU_PLAT
$ICU_LIB_SUFFIX = $env:ICU_LIB_SUFFIX
$ICU_URL = "https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-${ICU_PLAT}.zip"
$TMP_DIR = Join-Path $env:TEMP "icu-download"
$ICU_ZIP = Join-Path $TMP_DIR "icu.zip"

New-Item -ItemType Directory -Force -Path $TMP_DIR | Out-Null

Write-Host "Downloading ICU from $ICU_URL"
Invoke-WebRequest -Uri $ICU_URL -OutFile $ICU_ZIP

Write-Host "Extracting ICU"
Expand-Archive -Path $ICU_ZIP -DestinationPath $TMP_DIR -Force

New-Item -ItemType Directory -Force -Path $env:_LIBICU_DIR | Out-Null
Copy-Item -Path (Join-Path $TMP_DIR "include") -Destination $env:_LIBICU_DIR -Recurse -Force
Copy-Item -Path (Join-Path $TMP_DIR "lib${ICU_LIB_SUFFIX}") -Destination (Join-Path $env:_LIBICU_DIR "lib") -Recurse -Force
Copy-Item -Path (Join-Path $TMP_DIR "bin${ICU_LIB_SUFFIX}") -Destination (Join-Path $env:_LIBICU_DIR "bin") -Recurse -Force

Remove-Item -Recurse -Force $TMP_DIR

Write-Host "ICU installed to $env:_LIBICU_DIR"
24 changes: 11 additions & 13 deletions src/resolvers/libicu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os
import pathlib
import sys
import typing as t
from hatch_buildext import Macro


_IS_WINDOWS = sys.platform == "win32"


def _get_libicu_dir() -> pathlib.Path:
return pathlib.Path(os.environ["_LIBICU_DIR"])

Expand Down Expand Up @@ -36,22 +40,16 @@ def get_library_dirs(root: str, /) -> t.Sequence[str]:


def get_libraries(root: str, /) -> t.Sequence[str]:
# NOTE: manylinux
return [
"icudata",
"icui18n",
"icuuc",
]
# TODO: fix for other platforms?
return [
"libicudata",
"libicui18n",
"libicuuc",
]
if _IS_WINDOWS:
return ["icudt", "icuin", "icuuc"]

return ["icudata", "icui18n", "icuuc"]


def get_extra_compile_args(root: str, /) -> t.Sequence[str]:
# NOTE: required by pyicu
if _IS_WINDOWS:
return ["/std:c++17", "/EHsc"]

return ["-std=c++17"]


Expand Down
Loading