Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
- name: Build SDist
run: |
sudo apt update && sudo apt install ninja-build git build-essential -y
cd libmdbx && git fetch --tags && make V=1 dist && cd ..
cd libmdbx && git fetch --tags && make V=1 && cd ..
python3 -m pip install -U pip build
python3 -m build --sdist

Expand Down
40 changes: 37 additions & 3 deletions build_mdbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import multiprocessing
import shutil
import platform
import json
import re

SO_FILE = {
"linux": "libmdbx.so",
Expand All @@ -29,13 +31,15 @@ def build(setup_kws: dict):
debug = "DEBUG" in os.environ
pwd = Path(__file__).parent.resolve()
out_lib = pwd / "mdbx" / "lib"
mdbx_py = pwd / "mdbx"/ "mdbx.py"
libmdbx_source = pwd / "libmdbx"
dist_folder = libmdbx_source / "dist"
platform_enums = pwd / "platform_enums.c"

# If there is already dist
if not dist_folder.exists():
if sys.platform in ["linux", "linux2"]:
subprocess.check_call(["make", "dist"], cwd=libmdbx_source)
subprocess.check_call(["make"], cwd=libmdbx_source)

if have_git() and (libmdbx_source / ".git").exists():
source_folder = libmdbx_source
Expand Down Expand Up @@ -103,6 +107,36 @@ def build(setup_kws: dict):
cwd=tmpdir_path
)
shutil.copy(tmpdir_path / conf / SO_FILE, out_lib)


enum_exe = tmpdir_path / "platform_enums"
if sys.platform == "win32":
enum_exe = enum_exe.with_suffix(".exe")
plat = 'Win32' if platform.architecture()[0] == '32bit' else 'x64'
conf = 'Debug' if debug else 'Release'
# Compile with MSVC
subprocess.check_call([
"cl", str(platform_enums),
f"/Fe{enum_exe}"
], cwd=tmpdir_path)
else:
# Compile with GCC/Clang
subprocess.check_call([
"gcc", str(platform_enums), "-o", str(enum_exe)
], cwd=tmpdir_path)

output = subprocess.check_output([str(enum_exe)], text=True)
mdbx_errors = json.loads(output)

content = mdbx_py.read_text()

for key, value in mdbx_errors.items():
pattern = re.compile(rf"{key}\s*=\s*.*$", re.MULTILINE)
replacement = f"{key} = {value}"
content, n = pattern.subn(replacement, content)
if n == 0:
print(f"Warning: {key} not found in {mdbx_py}")

mdbx_py.write_text(content)

if __name__ == "__main__":
build({})
build({})
2 changes: 1 addition & 1 deletion libmdbx
Submodule libmdbx updated 186 files
20 changes: 20 additions & 0 deletions platform_enums.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "libmdbx/mdbx.h"
#include <stdio.h>

int main(void) {
printf("{\n");
printf(" \"MDBX_SUCCESS\": %d,\n", MDBX_SUCCESS);
printf(" \"MDBX_ENODATA\": %d,\n", MDBX_ENODATA);
printf(" \"MDBX_EINVAL\": %d,\n", MDBX_EINVAL);
printf(" \"MDBX_EACCES\": %d,\n", MDBX_EACCESS);
printf(" \"MDBX_ENOMEM\": %d,\n", MDBX_ENOMEM);
printf(" \"MDBX_EROFS\": %d,\n", MDBX_EROFS);
printf(" \"MDBX_ENOSYS\": %d,\n", MDBX_ENOSYS);
printf(" \"MDBX_EIO\": %d,\n", MDBX_EIO);
printf(" \"MDBX_EPERM\": %d,\n", MDBX_EPERM);
printf(" \"MDBX_EINTR\": %d,\n", MDBX_EINTR);
printf(" \"MDBX_ENOFILE\": %d,\n", MDBX_ENOFILE);
printf(" \"MDBX_EREMOTE\": %d\n", MDBX_EREMOTE);
printf("}\n");
return 0;
}
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ packages = [
{include = "mdbx"}
]
include = [
{ path = "libmdbx/dist/*", format = "sdist"},
{ path = "libmdbx/*", format = "sdist"},
{ path = "mdbx/lib/*", format = "wheel" },
]

exclude = [
{ path = "libmdbx/dist/build", format = "sdist"},
]

[tool.poetry.build]
generate-setup-file = false
script = "build_mdbx.py"
Expand Down
Loading