Skip to content

Fix ada.o object build #92

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 5, 2024
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
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ concurrency:
jobs:
build_wheels:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]

Expand All @@ -35,10 +36,10 @@ jobs:
- run: make requirements
- name: Set up QEMU # Needed to build aarch64 wheels
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: all
- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@v2.20.0
- uses: actions/upload-artifact@v4
with:
path: wheelhouse/*.whl
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install dependencies
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ concurrency:
jobs:
build_test:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]

Expand All @@ -28,7 +29,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install dependencies
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ada_url/*.c
include ada_url/*.cpp
include ada_url/*.h
exclude ada_url/*.o
exclude ada_url/_ada_wrapper.*
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ clean:
$(RM) ada_url/_ada_wrapper.abi3.so
$(RM) ada_url/ada.o

.PHONY: c_lib
c_lib:
$(CXX) -c "ada_url/ada.cpp" -fPIC -std="c++17" -O2 -o "ada_url/ada.o" $(ARCHFLAGS)

.PHONY: package
package: c_lib
package:
python -m build --no-isolation
python ./update_sdist.py
twine check dist/*
15 changes: 13 additions & 2 deletions ada_url/ada_build.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
from cffi import FFI
from os.path import dirname, join
from setuptools.extension import Extension
from sys import platform

file_dir = dirname(__file__)

compile_args = ['/std:c++17'] if platform == 'win32' else ['-std=c++17']

ada_obj = Extension(
'ada',
language="c++",
sources=['ada_url/ada.cpp'],
include_dirs=[file_dir],
extra_compile_args=compile_args,
)

libraries = ['stdc++'] if platform == 'linux' else []

ffi_builder = FFI()
ffi_builder.set_source(
'ada_url._ada_wrapper',
'# include "ada_c.h"',
include_dirs=[file_dir],
libraries=libraries,
extra_objects=[join(file_dir, 'ada.o')],
include_dirs=[file_dir],
extra_objects=[ada_obj],
)

cdef_lines = []
Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ After that, you're ready to build the package:
.. code-block:: sh

python -m pip install -r requirements/development.txt
c++ -c "ada_url/ada.cpp" -fPIC -std="c++17" -O2 -o "ada_url/ada.o"
python -m build --no-isolation

This will create a `.whl` file in the `dist` directory. You can install it in other
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["cffi", "setuptools < 74", "urllib3", "wheel"]
requires = ["cffi>=1.17.1", "setuptools", "urllib3", "wheel"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -73,13 +73,16 @@ build = [

[tool.cibuildwheel.linux]
archs = ["x86_64", "aarch64"]
before-all = "make c_lib"

[tool.cibuildwheel.macos]
archs = ["x86_64", "universal2", "arm64"]
environment = { MACOSX_DEPLOYMENT_TARGET="10.15" }
before-build = "make clean && make c_lib"
before-build = "make clean"

[tool.cibuildwheel.windows]
archs = ["AMD64"]
before-build = '"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat" && cl "ada_url\\ada.cpp" /c /nologo /Fo"ada_url\\ada.o" /O2 /GL /MD /W3 /EHsc /std:c++17'

# https://github.com/pypy/pypy/issues/5027
[[tool.cibuildwheel.overrides]]
select = "pp39-win_amd64"
environment = { SETUPTOOLS_USE_DISTUTILS="stdlib" }
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# What we want
cffi==1.17.0
cffi==1.17.1

# What we need
pycparser==2.22
2 changes: 1 addition & 1 deletion requirements/development.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build
coverage
ruff
setuptools<74
setuptools
Sphinx
twine
urllib3
Expand Down
25 changes: 25 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
from setuptools import setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.extension import Extension


class build_ext(_build_ext):
def build_extension(self, ext):
for i, extra in enumerate(ext.extra_objects):
if isinstance(extra, Extension):
sources = sorted(extra.sources)
extra_args = extra.extra_compile_args or []
macros = extra.define_macros[:]
for undef in extra.undef_macros:
macros.append((undef,))
objects = self.compiler.compile(
sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=extra.include_dirs,
debug=self.debug,
extra_postargs=extra_args,
depends=extra.depends,
)
ext.extra_objects[i] = objects[0]
return super().build_extension(ext)

setup(
cmdclass={'build_ext': build_ext},
cffi_modules=[
'./ada_url/ada_build.py:ffi_builder',
],
Expand Down
Loading