diff --git a/.github/workflows/wheels.yaml b/.github/workflows/wheels.yaml index e65312c..08016cd 100644 --- a/.github/workflows/wheels.yaml +++ b/.github/workflows/wheels.yaml @@ -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 diff --git a/build_mdbx.py b/build_mdbx.py index 38c6be8..5aae3b6 100644 --- a/build_mdbx.py +++ b/build_mdbx.py @@ -6,6 +6,8 @@ import multiprocessing import shutil import platform +import json +import re SO_FILE = { "linux": "libmdbx.so", @@ -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 @@ -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({}) \ No newline at end of file + build({}) diff --git a/libmdbx b/libmdbx index 4d58857..91b9800 160000 --- a/libmdbx +++ b/libmdbx @@ -1 +1 @@ -Subproject commit 4d58857f8fd0aba400706610ba05ba4dd869f04e +Subproject commit 91b9800acfcaa368582d0ca6190a4589f99494c2 diff --git a/platform_enums.c b/platform_enums.c new file mode 100644 index 0000000..446f284 --- /dev/null +++ b/platform_enums.c @@ -0,0 +1,20 @@ +#include "libmdbx/mdbx.h" +#include + +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; +} diff --git a/pyproject.toml b/pyproject.toml index f59c714..cba970c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"