Skip to content

Commit

Permalink
build: fix unsupported platform tag 'linux_*' for wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
WSH032 committed Dec 18, 2023
1 parent c537102 commit a06da31
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
31 changes: 18 additions & 13 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -42,39 +43,43 @@ 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"),
)


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)
Expand All @@ -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)}
"""
)
Expand Down

0 comments on commit a06da31

Please sign in to comment.