Skip to content

Implement building and publishing Android packages #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
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
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ jobs:
python ci/download-wasmtime.py musl x86_64
python ci/build-rust.py
python setup.py bdist_wheel --plat-name musllinux_1_2_x86_64
- run: |
git clean -fdx wasmtime build
python ci/download-wasmtime.py android x86_64
python ci/build-rust.py
python setup.py bdist_wheel --plat-name android_26_x86_64
- run: |
git clean -fdx wasmtime build
python ci/download-wasmtime.py android aarch64
python ci/build-rust.py
python setup.py bdist_wheel --plat-name android_26_arm64_v8a

# Build an "any" wheel with:
#
Expand Down
4 changes: 4 additions & 0 deletions ci/download-wasmtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def main(platform, arch):
elif platform == 'darwin':
filename = 'wasmtime-{}-{}-macos-c-api.tar.xz'.format(version, arch)
libname = '_libwasmtime.dylib'
elif platform == 'android':
filename = 'wasmtime-{}-{}-android-c-api.tar.xz'.format(version, arch)
libname = '_libwasmtime.so'
dirname = 'android-{}'.format(arch)
else:
raise RuntimeError("unknown platform: " + sys.platform)

Expand Down
20 changes: 13 additions & 7 deletions wasmtime/_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
if sys.maxsize <= 2**32:
raise RuntimeError("wasmtime only works on 64-bit platforms right now")

if sys.platform == 'linux':
sys_platform = sys.platform

# For Python versions <=3.12. 3.13+ supports PEP 738 and uses sys.platform
if hasattr(sys, 'getandroidapilevel'):
sys_platform = 'android'

if sys_platform == 'linux' or sys_platform == 'android':
libname = '_libwasmtime.so'
elif sys.platform == 'win32':
elif sys_platform == 'win32':
libname = '_wasmtime.dll'
elif sys.platform == 'darwin':
elif sys_platform == 'darwin':
libname = '_libwasmtime.dylib'
else:
raise RuntimeError("unsupported platform `{}` for wasmtime".format(sys.platform))
raise RuntimeError("unsupported platform `{}` for wasmtime".format(sys_platform))


machine = platform.machine()
if machine == 'AMD64':
Expand All @@ -25,9 +32,8 @@
if machine != 'x86_64' and machine != 'aarch64':
raise RuntimeError("unsupported architecture for wasmtime: {}".format(machine))

filename = Path(__file__).parent / (sys.platform + '-' + machine) / libname
if not filename.exists():
raise RuntimeError("precompiled wasmtime binary not found at `{}`".format(filename))
filename = Path(__file__).parent / (sys_platform + '-' + machine) / libname

dll = cdll.LoadLibrary(str(filename))

WASM_I32 = c_uint8(0)
Expand Down
Loading