Include zig build in the build process.
This commit is contained in:
+9
-2
@@ -1,6 +1,13 @@
|
|||||||
include pyaegis/aegis_cdef.h
|
include pyaegis/aegis_cdef.h
|
||||||
include setup.py
|
include setup.py
|
||||||
|
include build_backend.py
|
||||||
include BUILD.md
|
include BUILD.md
|
||||||
include README.md
|
include README.md
|
||||||
recursive-include libaegis/src/include *.h
|
recursive-include libaegis *.c *.h *.zig *.zon
|
||||||
include libaegis/zig-out/lib/libaegis.a
|
include libaegis/CMakeLists.txt
|
||||||
|
include libaegis/LICENSE
|
||||||
|
include libaegis/README.md
|
||||||
|
recursive-include libaegis/cmake *.cmake *.cmake.in
|
||||||
|
graft libaegis/src
|
||||||
|
include libaegis/build.zig
|
||||||
|
include libaegis/build.zig.zon
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
"""Custom build backend that builds libaegis with Zig before building the Python package."""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from setuptools import build_meta as _orig
|
||||||
|
|
||||||
|
|
||||||
|
def _build_libaegis():
|
||||||
|
"""Build libaegis static library with Zig."""
|
||||||
|
libaegis_dir = Path(__file__).parent / "libaegis"
|
||||||
|
if not libaegis_dir.exists():
|
||||||
|
raise FileNotFoundError(
|
||||||
|
f"libaegis directory not found at {libaegis_dir}. "
|
||||||
|
"Cannot build static library."
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Building libaegis static library with Zig...")
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
["zig", "build", "-Drelease"],
|
||||||
|
cwd=libaegis_dir,
|
||||||
|
check=True,
|
||||||
|
capture_output=False,
|
||||||
|
)
|
||||||
|
print("Successfully built libaegis static library")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error building libaegis: {e}", file=sys.stderr)
|
||||||
|
raise
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(
|
||||||
|
"Error: 'zig' command not found. Please install Zig to build libaegis.",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
# Expose all the standard build backend hooks
|
||||||
|
get_requires_for_build_wheel = _orig.get_requires_for_build_wheel
|
||||||
|
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist
|
||||||
|
prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
|
||||||
|
build_sdist = _orig.build_sdist
|
||||||
|
|
||||||
|
|
||||||
|
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
|
||||||
|
"""Build wheel with libaegis built first."""
|
||||||
|
_build_libaegis()
|
||||||
|
return _orig.build_wheel(wheel_directory, config_settings, metadata_directory)
|
||||||
|
|
||||||
|
|
||||||
|
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
|
||||||
|
"""Build editable install with libaegis built first."""
|
||||||
|
_build_libaegis()
|
||||||
|
return _orig.build_editable(wheel_directory, config_settings, metadata_directory)
|
||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools>=61.0", "cffi>=2.0.0"]
|
requires = ["setuptools>=61.0", "cffi>=2.0.0"]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "build_backend"
|
||||||
|
backend-path = ["."]
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "pyaegis"
|
name = "pyaegis"
|
||||||
@@ -25,6 +26,7 @@ Homepage = "https://github.com/aegis-aead/libaegis"
|
|||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = [
|
dev = [
|
||||||
"pytest>=8.4.2",
|
"pytest>=8.4.2",
|
||||||
|
"setuptools>=80.9.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools]
|
[tool.setuptools]
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from pathlib import Path
|
|||||||
from cffi import FFI
|
from cffi import FFI
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
# Read the CDEF header
|
|
||||||
cdef_path = Path(__file__).parent / "pyaegis" / "aegis_cdef.h"
|
cdef_path = Path(__file__).parent / "pyaegis" / "aegis_cdef.h"
|
||||||
cdef_content = cdef_path.read_text(encoding="utf-8")
|
cdef_content = cdef_path.read_text(encoding="utf-8")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -25,4 +25,4 @@ def random_split_bytes(data: bytes) -> list[bytes]:
|
|||||||
for stop in (*cut_points, len(data)):
|
for stop in (*cut_points, len(data)):
|
||||||
parts.append(data[start:stop])
|
parts.append(data[start:stop])
|
||||||
start = stop
|
start = stop
|
||||||
return parts
|
return parts
|
||||||
|
|||||||
+1
-3
@@ -39,9 +39,7 @@ def clean_declaration(text: str) -> str:
|
|||||||
if "CRYPTO_ALIGN" in text and "typedef struct" in text:
|
if "CRYPTO_ALIGN" in text and "typedef struct" in text:
|
||||||
# Replace "CRYPTO_ALIGN(N) uint8_t opaque[SIZE];" with "...;"
|
# Replace "CRYPTO_ALIGN(N) uint8_t opaque[SIZE];" with "...;"
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
r"CRYPTO_ALIGN\s*\(\s*\d+\s*\)\s+uint8_t\s+opaque\[\d+\];",
|
r"CRYPTO_ALIGN\s*\(\s*\d+\s*\)\s+uint8_t\s+opaque\[\d+\];", "...;", text
|
||||||
"...;",
|
|
||||||
text
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# For non-struct declarations, just remove CRYPTO_ALIGN
|
# For non-struct declarations, just remove CRYPTO_ALIGN
|
||||||
|
|||||||
Reference in New Issue
Block a user