Skip to content

Commit

Permalink
python310Packages.aiohttp: unvendor llhttp
Browse files Browse the repository at this point in the history
  • Loading branch information
dotlambda committed Nov 21, 2023
1 parent e8c572f commit 2ff6c90
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pkgs/development/python-modules/aiohttp/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{ lib
, stdenv
, buildPythonPackage
, fetchPypi
, pythonOlder
, fetchFromGitHub
, substituteAll
, llhttp
# build_requires
, cython
, setuptools
# install_requires
, attrs
Expand Down Expand Up @@ -31,19 +34,38 @@ buildPythonPackage rec {

disabled = pythonOlder "3.8";

src = fetchPypi {
inherit pname version;
hash = "sha256-CfIyktKRNQJeGej/Twpo3weP5O4BO8oBBbLoA5id6S0=";
src = fetchFromGitHub {
owner = "aio-libs";
repo = "aiohttp";
rev = "refs/tags/v${version}";
hash = "sha256-lCeB7uSXkcCCBv1UiwL4AmXpYNJCt4F7a3OKP88ALZU=";
};

patches = [
(substituteAll {
src = ./unvendor-llhttp.patch;
llhttpDev = lib.getDev llhttp;
llhttpLib = lib.getLib llhttp;
})
];

postPatch = ''
sed -i '/--cov/d' setup.cfg
rm -r vendor
patchShebangs tools
touch .git # tools/gen.py uses .git to find the project root
'';

nativeBuildInputs = [
cython
setuptools
];

preBuild = ''
make cythonize
'';

propagatedBuildInputs = [
attrs
multidict
Expand Down Expand Up @@ -100,6 +122,7 @@ buildPythonPackage rec {
# aiohttp in current folder shadows installed version
preCheck = ''
rm -r aiohttp
touch tests/data.unknown_mime_type # has to be modified after 1 Jan 1990
'' + lib.optionalString stdenv.isDarwin ''
# Work around "OSError: AF_UNIX path too long"
export TMPDIR="/tmp"
Expand Down
60 changes: 60 additions & 0 deletions pkgs/development/python-modules/aiohttp/unvendor-llhttp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/Makefile b/Makefile
index 5769d2a1..f505dd81 100644
--- a/Makefile
+++ b/Makefile
@@ -71,7 +71,7 @@ vendor/llhttp/node_modules: vendor/llhttp/package.json
generate-llhttp: .llhttp-gen

.PHONY: cythonize
-cythonize: .install-cython $(PYXS:.pyx=.c)
+cythonize: $(PYXS:.pyx=.c)

.install-deps: .install-cython $(PYXS:.pyx=.c) $(call to-hash,$(CYS) $(REQS))
@python -m pip install -r requirements/dev.txt -c requirements/constraints.txt
diff --git a/aiohttp/_cparser.pxd b/aiohttp/_cparser.pxd
index 165dd61d..bc6bf86d 100644
--- a/aiohttp/_cparser.pxd
+++ b/aiohttp/_cparser.pxd
@@ -10,7 +10,7 @@ from libc.stdint cimport (
)


-cdef extern from "../vendor/llhttp/build/llhttp.h":
+cdef extern from "@llhttpDev@/include/llhttp.h":

struct llhttp__internal_s:
int32_t _index
diff --git a/setup.py b/setup.py
index 4d59a022..d87d5b69 100644
--- a/setup.py
+++ b/setup.py
@@ -17,13 +17,6 @@ if sys.implementation.name != "cpython":
NO_EXTENSIONS = True


-if IS_GIT_REPO and not (HERE / "vendor/llhttp/README.md").exists():
- print("Install submodules when building from git clone", file=sys.stderr)
- print("Hint:", file=sys.stderr)
- print(" git submodule update --init", file=sys.stderr)
- sys.exit(2)
-
-
# NOTE: makefile cythonizes all Cython modules

extensions = [
@@ -33,12 +26,11 @@ extensions = [
[
"aiohttp/_http_parser.c",
"aiohttp/_find_header.c",
- "vendor/llhttp/build/c/llhttp.c",
- "vendor/llhttp/src/native/api.c",
- "vendor/llhttp/src/native/http.c",
],
define_macros=[("LLHTTP_STRICT_MODE", 0)],
- include_dirs=["vendor/llhttp/build"],
+ include_dirs=["@llhttpDev@/include"],
+ library_dirs=["@llhttpLib@/lib"],
+ libraries=["llhttp"],
),
Extension("aiohttp._helpers", ["aiohttp/_helpers.c"]),
Extension("aiohttp._http_writer", ["aiohttp/_http_writer.c"]),

0 comments on commit 2ff6c90

Please sign in to comment.