Skip to content

Commit

Permalink
Vendor libmaxminddb
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Nov 1, 2023
1 parent c37a359 commit 91e60fa
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/address-sanitizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion .github/workflows/clang-analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions .github/workflows/create-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Build wheels
uses: pypa/[email protected]
env:
MAXMINDDB_REQUIRE_EXTENSION: 1

- uses: actions/upload-artifact@v2
with:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tests/data"]
path = tests/data
url = https://github.com/maxmind/MaxMind-DB
[submodule "extension/libmaxminddb"]
path = extension/libmaxminddb
url = [email protected]:maxmind/libmaxminddb.git
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions extension/libmaxminddb
Submodule libmaxminddb added at ac4d0d
2 changes: 1 addition & 1 deletion extension/maxminddb.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <arpa/inet.h>
#include <maxminddb.h>
#include "libmaxminddb/include/maxminddb.h"
#include <netinet/in.h>
#include <structmember.h>
#include <sys/socket.h>
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 17 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
]
Expand Down Expand Up @@ -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, "
Expand Down

0 comments on commit 91e60fa

Please sign in to comment.