diff --git a/.github/workflows/address-sanitizer.yml b/.github/workflows/address-sanitizer.yml index 4ed1a49..72f5f8a 100644 --- a/.github/workflows/address-sanitizer.yml +++ b/.github/workflows/address-sanitizer.yml @@ -33,6 +33,8 @@ jobs: pip install setuptools tox tox-gh-actions wheel - name: Test with tox - run: MM_FORCE_EXT_TESTS=1 tox + run: tox env: LD_PRELOAD: libasan.so.6 + MAXMINDDB_REQUIRE_EXTENSION: 1 + MM_FORCE_EXT_TESTS: 1 diff --git a/.github/workflows/clang-analyzer.yml b/.github/workflows/clang-analyzer.yml index 16b7adb..2483c2d 100644 --- a/.github/workflows/clang-analyzer.yml +++ b/.github/workflows/clang-analyzer.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: true - name: Install libmaxminddb run: sudo apt install clang-tools libmaxminddb-dev @@ -28,4 +30,7 @@ jobs: pip install setuptools wheel - name: Build and run analyzer - run: CFLAGS="-Werror -Wall -Wextra" scan-build --status-bugs python setup.py build + run: scan-build --status-bugs python setup.py build + env: + CFLAGS: "-Werror -Wall -Wextra" + MAXMINDDB_REQUIRE_EXTENSION: 1 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ef3027e..8b32e9b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -20,6 +20,7 @@ jobs: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 + submodules: true # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. @@ -47,6 +48,8 @@ jobs: pip install setuptools wheel - run: python setup.py build + env: + MAXMINDDB_REQUIRE_EXTENSION: 1 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/create-wheels.yml b/.github/workflows/create-wheels.yml index 115b439..bb62042 100644 --- a/.github/workflows/create-wheels.yml +++ b/.github/workflows/create-wheels.yml @@ -14,9 +14,13 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: true - name: Build wheels uses: pypa/cibuildwheel@v2.16.2 + env: + MAXMINDDB_REQUIRE_EXTENSION: 1 - uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6a92e4..7a7ceea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,7 +44,13 @@ jobs: pip install setuptools tox tox-gh-actions wheel - name: Build with Werror and Wall - run: CFLAGS="-Werror -Wall -Wextra" python setup.py build + run: python setup.py build + env: + CFLAGS: "-Werror -Wall -Wextra" + MAXMINDDB_REQUIRE_EXTENSION: 1 - name: Test with tox run: MM_FORCE_EXT_TESTS=1 tox + env: + MAXMINDDB_REQUIRE_EXTENSION: 1 + MM_FORCE_EXT_TESTS: 1 diff --git a/.gitmodules b/.gitmodules index e8246ba..c2a1c59 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "tests/data"] path = tests/data url = https://github.com/maxmind/MaxMind-DB +[submodule "extension/libmaxminddb"] + path = extension/libmaxminddb + url = git@github.com:maxmind/libmaxminddb.git diff --git a/MANIFEST.in b/MANIFEST.in index b34a8af..74ea8ba 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include HISTORY.rst README.rst LICENSE maxminddb/py.typed maxminddb/extension.pyi -recursive-include tests/ *.mmdb *.py *.raw +recursive-include tests/ *.c *.h *.mmdb *.py *.raw graft docs/html diff --git a/extension/libmaxminddb b/extension/libmaxminddb new file mode 160000 index 0000000..ac4d0d2 --- /dev/null +++ b/extension/libmaxminddb @@ -0,0 +1 @@ +Subproject commit ac4d0d2480032a8664e251588e57d7b306ca630c diff --git a/extension/maxminddb.c b/extension/maxminddb.c index 2d5be90..afa7477 100644 --- a/extension/maxminddb.c +++ b/extension/maxminddb.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include #include -#include +#include "libmaxminddb/include/maxminddb.h" #include #include #include diff --git a/pyproject.toml b/pyproject.toml index ceecdcc..d080d8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,9 +42,3 @@ Documentation = "https://maxminddb.readthedocs.org/" # src is showing up in our GitHub linting builds. It seems to # contain deps. extend-exclude = '^/src/' - -[tool.cibuildwheel.linux] -before-all = "apt install libmaxminddb-dev" - -[tool.cibuildwheel.macos] -before-all = "brew install libmaxminddb" diff --git a/setup.py b/setup.py index 226d889..b05a977 100644 --- a/setup.py +++ b/setup.py @@ -21,13 +21,25 @@ PYPY = hasattr(sys, "pypy_version_info") JYTHON = sys.platform.startswith("java") -compile_args = ["-Wall", "-Wextra"] +compile_args = ["-Wall", "-Wextra", "-Wno-unknown-pragmas"] ext_module = [ Extension( "maxminddb.extension", - libraries=["maxminddb"], - sources=["extension/maxminddb.c"], + sources=[ + "extension/maxminddb.c", + "extension/libmaxminddb/src/data-pool.c", + "extension/libmaxminddb/src/maxminddb.c", + ], + define_macros=[ + # XXX - maybe we should get this from python somehow + ("MMDB_LITTLE_ENDIAN", 1), + ("PACKAGE_VERSION", '"maxminddb-python"'), + ], + include_dirs=[ + "extension/libmaxminddb/include", + "extension/libmaxminddb/src", + ], extra_compile_args=compile_args, ) ] @@ -116,6 +128,8 @@ def run_setup(with_cext): try: run_setup(True) except BuildFailed as exc: + if os.getenv('MAXMINDDB_REQUIRE_EXTENSION'): + raise exc status_msgs( exc.cause, "WARNING: The C extension could not be compiled, "