Skip to content

Fix macOS arm64 and universal2 wheels #33

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 1 commit into from
Sep 12, 2023
Merged

Conversation

y3ti
Copy link
Contributor

@y3ti y3ti commented Sep 12, 2023

If we install ada_url on macOS M1 then we will get this error:

$ pip3 install ada_url==1.3.0
...

$ python3 -c "import ada_url"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../python/3.11.3/lib/python3.11/site-packages/ada_url/__init__.py", line 1, in <module>
    from ada_url.ada_adapter import (
  File ".../installs/python/3.11.3/lib/python3.11/site-packages/ada_url/ada_adapter.py", line 4, in <module>
    from ada_url._ada_wrapper import ffi, lib
ImportError: dlopen(.../installs/python/3.11.3/lib/python3.11/site-packages/ada_url/_ada_wrapper.abi3.so, 0x0002): symbol not found in flat namespace '_ada_can_parse'

GitHub Actions doesn’t support macOS arm64 (M1/Apple Silicon) managed runners, so we need to do cross-compilation on macOS. cibuildwheel sets ARCHFLAGS variable we can use with CXX compiler to set the correct target.

I decided to move before-all to [tool.cibuildwheel.linux] and add before-build to [tool.cibuildwheel.macos] for optimizing CI build time execution purposes.

We can’t use before-all in [tool.cibuildwheel] section because it will be running only once per platform (linux/macos), and we need to run it before all builds for all architectures for macOS (x86_64, arm64, universal2) because we will have different values for the ARCHFLAGS environment variable.

If we add before-build to [tool.cibuildwheel] then it will be executed many times for linux platform because builds are executed inside different docker containers and because we use QEMU then the compilation process is slow (GitHub Action Workflow execution time: 25 minutes vs 48 minutes).

If we install ada_url on macOS M1 then we will get this error:

```
$ pip3 install ada_url==1.3.0
...

$ python3 -c "import ada_url"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../python/3.11.3/lib/python3.11/site-packages/ada_url/__init__.py", line 1, in <module>
    from ada_url.ada_adapter import (
  File ".../installs/python/3.11.3/lib/python3.11/site-packages/ada_url/ada_adapter.py", line 4, in <module>
    from ada_url._ada_wrapper import ffi, lib
ImportError: dlopen(.../installs/python/3.11.3/lib/python3.11/site-packages/ada_url/_ada_wrapper.abi3.so, 0x0002): symbol not found in flat namespace '_ada_can_parse'
```

GitHub Actions doesn’t support macOS arm64 (M1/Apple Silicon) managed
runners, so we need to do cross-compilation on macOS. `cibuildwheel` sets
`ARCHFLAGS` variable we can use with `CXX` compiler to set the correct
target.

I decided to move `before-all` to `[tool.cibuildwheel.linux]` and add
`before-build` to `[tool.cibuildwheel.macos]` for optimizing CI build time
execution purposes.

We can’t use `before-all` in `[tool.cibuildwheel]` section because it will
be running only once per platform (`linux`/`macos`), and we need to run it
before all builds for all architectures for macOS (`x86_64`, `arm64`,
`universal2`) because we will have different values for the `ARCHFLAGS`
environment variable.

If we add `before-build` to `[tool.cibuildwheel]` then it will be executed
many times for linux platform because builds are executed inside different
docker containers and because we use QEMU then the compilation process
is slow (GitHub Action Workflow execution time: 25 minutes vs 48 minutes).
@bbayles
Copy link
Collaborator

bbayles commented Sep 12, 2023

Many thanks for this writeup and PR. I will merge it soon!

@bbayles bbayles merged commit d1c78b1 into ada-url:main Sep 12, 2023
@y3ti y3ti deleted the fix/macos-arm64 branch September 12, 2023 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants