From a06da31dca60442d83b10999fdf73dc2c178fc43 Mon Sep 17 00:00:00 2001 From: WSH032 <614337162@qq.com> Date: Tue, 19 Dec 2023 01:58:07 +0800 Subject: [PATCH] build: fix unsupported platform tag 'linux_*' for wheels --- .github/workflows/publish.yml | 16 +++++++++------- README.md | 12 +++++++----- hatch_build.py | 31 ++++++++++++++++++------------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 821704f..5dcf6a8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,14 +24,16 @@ jobs: strategy: fail-fast: false matrix: - # keep `cross_host` consistent with `tag_4_build_enum` in `hatch_build.py` - cross_host: - - x86_64-linux-musl - - aarch64-linux-musl - - x86_64-w64-mingw32 - - i686-w64-mingw32 + # keep `whl_platform` consistent with `tag_4_build_enum` in `hatch_build.py` + whl_platform: + - manylinux_2_17_x86_64 + - musllinux_1_1_x86_64 + - manylinux_2_17_aarch64 + - musllinux_1_1_aarch64 + - win_amd64 + - win32 env: - CROSS_HOST: ${{ matrix.cross_host }} + WHL_PLATFORM: ${{ matrix.whl_platform }} steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/README.md b/README.md index bdbef3c..f0d2e6b 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,12 @@ So I build this python wheel to binding aria2 static build. You can install it b Now, we support: -- [x] Windows 32bit -- [x] Windows 64bit -- [x] Linux x86_64 -- [x] Linux aarch64 +- [x] manylinux_2_17_x86_64 +- [x] musllinux_1_1_x86_64 +- [x] manylinux_2_17_aarch64 +- [x] musllinux_1_1_aarch64 +- [x] win_amd64 +- [x] win32 ## Features @@ -54,7 +56,7 @@ You can completely uninstall it by running `pip uninstall aria2`. - The bound aria2 executable file directly comes from `aria2-static-build` project, and `aria2-wheel` assumes no responsibility for your use. - The license of `aria2-wheel` project is consistent with `aria2-static-build` project. -check `hatch_build.py` to know how we build the wheel. +check `hatch_build.py` and `.github/workflows/publish.yml` to know how we build the wheel. ## Install diff --git a/hatch_build.py b/hatch_build.py index fc75dfe..2a85b5c 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -30,8 +30,9 @@ """需要使用 `.format(BUILD='x86_64-w64-mingw32')` 来生成最终的URL""" -ARIA2_BUILD_ENV_VAR = "CROSS_HOST" -"""Ref: https://github.com/abcfy2/aria2-static-build#build-locally-yourself""" +# keep this consistent with name of var `env` in `.github\workflows\publish.yml` +BUILD_TAG_ENV_VAR_NAME = "WHL_PLATFORM" + # keep posix path style # NOTE: keep the `bin dir` consistent with the one in `src/aria2c/__init__.py` @@ -42,20 +43,24 @@ class Tag4Build(NamedTuple): """用于描述构建平台的tag. Attributes: - aria2_build: aria2c的构建平台, 如x86_64-linux-musl. + aria2_build: aria2c的构建平台, 如x86_64-linux-musl . Ref: https://github.com/abcfy2/aria2-static-build - whl_platform: 最终生成的whl包的平台, 如linux_x86_64. + whl_platform: 最终生成的whl包的平台, 如manylinux_2_17_x86_64 . Ref: https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/#platform-tag + https://github.com/deltachat/deltachat-core-rust/pull/4832 + https://github.com/pypi/warehouse/blob/92856ad31fd5d28892d9072dd1633a0b31976708/warehouse/forklift/legacy.py#L166-L182 """ aria2_build: str whl_platform: str -# keep all of `Tag4Build().aria2_build` consistent with `matrix.cross_host` in `.github\workflows\publish.yml` +# keep all of `Tag4Build().whl_platform` consistent with `matrix.whl_platform` in `.github\workflows\publish.yml` tag_4_build_enum = ( - Tag4Build("x86_64-linux-musl", "linux_x86_64"), - Tag4Build("aarch64-linux-musl", "linux_aarch64"), + Tag4Build("x86_64-linux-musl", "manylinux_2_17_x86_64"), + Tag4Build("x86_64-linux-musl", "musllinux_1_1_x86_64"), + Tag4Build("aarch64-linux-musl", "manylinux_2_17_aarch64"), + Tag4Build("aarch64-linux-musl", "musllinux_1_1_aarch64"), Tag4Build("x86_64-w64-mingw32", "win_amd64"), Tag4Build("i686-w64-mingw32", "win32"), ) @@ -63,18 +68,18 @@ class Tag4Build(NamedTuple): def _get_tag_4_build_by_env() -> Union[Tag4Build, None]: """从环境变量中获取构建平台的tag.""" - aria2_build = os.getenv(ARIA2_BUILD_ENV_VAR) - if aria2_build is None: + build_tag = os.getenv(BUILD_TAG_ENV_VAR_NAME) + if build_tag is None: return None for tag in tag_4_build_enum: - if tag.aria2_build == aria2_build: + if tag.whl_platform == build_tag: return tag else: msg = dedent( f"""\ - Invalid '{ARIA2_BUILD_ENV_VAR}' env var: {aria2_build} - Only support: {', '.join(tag.aria2_build for tag in tag_4_build_enum)} + Invalid '{BUILD_TAG_ENV_VAR_NAME}' env var: {build_tag} + Only support: {', '.join(tag.whl_platform for tag in tag_4_build_enum)} """ ) raise RuntimeError(msg) @@ -98,7 +103,7 @@ def get_tag_4_build() -> Tag4Build: msg = dedent( f"""\ Can't find tag for build. - Please set '{ARIA2_BUILD_ENV_VAR}' env var or run this building on supported platform. + Please set '{BUILD_TAG_ENV_VAR_NAME}' env var or run this building on supported platform. supported platform: {', '.join(tag.whl_platform for tag in tag_4_build_enum)} """ )