From 4c0ed2e90da6917f2b2e80bf9cd5c5a659530531 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Thu, 5 Sep 2024 12:17:35 -0600 Subject: [PATCH] Fix ada.o object build (#92) --- .github/workflows/build.yml | 5 +++-- .github/workflows/lint.yml | 4 ++-- .github/workflows/unit-tests.yml | 3 ++- MANIFEST.in | 5 +++++ Makefile | 7 +------ ada_url/ada_build.py | 15 +++++++++++++-- docs/index.rst | 1 - pyproject.toml | 11 +++++++---- requirements/base.txt | 2 +- requirements/development.txt | 2 +- setup.py | 25 +++++++++++++++++++++++++ 11 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 MANIFEST.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 298af07..cef6cea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ concurrency: jobs: build_wheels: strategy: + fail-fast: false matrix: os: ["ubuntu-latest", "macos-latest", "windows-latest"] @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 258637a..c09aeda 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 92fdb03..246ccba 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ concurrency: jobs: build_test: strategy: + fail-fast: false matrix: os: ["ubuntu-latest", "macos-latest"] @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6fdaadd --- /dev/null +++ b/MANIFEST.in @@ -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.* diff --git a/Makefile b/Makefile index 996ea1c..7d19fd1 100644 --- a/Makefile +++ b/Makefile @@ -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/* diff --git a/ada_url/ada_build.py b/ada_url/ada_build.py index dea6adf..b85d42b 100644 --- a/ada_url/ada_build.py +++ b/ada_url/ada_build.py @@ -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 = [] diff --git a/docs/index.rst b/docs/index.rst index c25152b..0288d4d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 260817f..3fc9089 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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" } diff --git a/requirements/base.txt b/requirements/base.txt index 2369f27..9555724 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # What we want -cffi==1.17.0 +cffi==1.17.1 # What we need pycparser==2.22 diff --git a/requirements/development.txt b/requirements/development.txt index 4aefedb..662427b 100644 --- a/requirements/development.txt +++ b/requirements/development.txt @@ -1,7 +1,7 @@ build coverage ruff -setuptools<74 +setuptools Sphinx twine urllib3 diff --git a/setup.py b/setup.py index f4484da..df1aff4 100644 --- a/setup.py +++ b/setup.py @@ -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', ],