diff --git a/Makefile b/Makefile index 1c0612a..867a2f3 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,10 @@ .DEFAULT_GOAL := all -CC ?= cc -AR ?= ar -RM ?= rm -f +CC ?= cc +AR ?= ar +RM ?= rm -f +PREFIX ?= /usr/local CFLAGS = -O2 -Wall -Wextra -fPIC LDFLAGS = @@ -21,22 +22,33 @@ HDR = ciph.h UNAME_S := $(shell uname -s) +# ------------------------- +# Platform detection +# ------------------------- + ifeq ($(UNAME_S),Linux) - SHARED = libciph.so + SHARED = libciph.so + LDFLAGS += -shared -Wl,-soname,libciph.so endif ifeq ($(UNAME_S),Darwin) - SHARED = libciph.dylib + SHARED = libciph.dylib LDFLAGS += -dynamiclib endif ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) - SHARED = ciph.dll + SHARED = libciph.dll LDFLAGS += -shared endif STATIC = libciph.a +# ------------------------- +# Targets +# ------------------------- + +all: check shared static + check: @pkg-config --exists libsodium || ( \ echo "libsodium not found."; \ @@ -49,26 +61,44 @@ check: exit 1 \ ) -all: check shared static - shared: $(SHARED) static: $(STATIC) +# ------------------------- +# Build rules +# ------------------------- + $(OBJ): $(SRC) $(HDR) $(CC) $(CFLAGS) -c $(SRC) -o $(OBJ) $(SHARED): $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -shared $(OBJ) -o $(SHARED) $(LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $(SHARED) $(LIBS) $(STATIC): $(OBJ) $(AR) rcs $(STATIC) $(OBJ) +# ------------------------- +# Install / Clean +# ------------------------- + +install: + install -Dm755 $(SHARED) $(PREFIX)/lib/$(SHARED) + install -Dm644 $(HDR) $(PREFIX)/include/ciph.h + clean: $(RM) $(OBJ) $(SHARED) $(STATIC) -install: - install -Dm755 $(SHARED) /usr/local/lib/$(SHARED) - install -Dm644 $(HDR) /usr/local/include/ciph.h +# ------------------------- +# Debug helper +# ------------------------- + +print-config: + @echo "OS : $(UNAME_S)" + @echo "CC : $(CC)" + @echo "CFLAGS : $(CFLAGS)" + @echo "LDFLAGS : $(LDFLAGS)" + @echo "SHARED : $(SHARED)" + @echo "PREFIX : $(PREFIX)" -.PHONY: all check shared static clean install +.PHONY: all check shared static install clean print-config diff --git a/ciph/__init__.py b/ciph/__init__.py index a955fda..bc86c94 100644 --- a/ciph/__init__.py +++ b/ciph/__init__.py @@ -1 +1 @@ -__version__ = "1.2.1" +__version__ = "1.2.2" diff --git a/ciph/_build.c b/ciph/_build.c new file mode 100644 index 0000000..978a513 --- /dev/null +++ b/ciph/_build.c @@ -0,0 +1,4 @@ +/* dummy file to force build_ext */ +int ciph_build_dummy(void) { + return 0; +} diff --git a/pyproject.toml b/pyproject.toml index 078f7e2..746c2de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,43 +4,42 @@ build-backend = "setuptools.build_meta" [project] name = "ciph" -version = "1.2.1" +version = "1.2.2" description = "High-performance streaming encryption engine for large files" readme = "README.md" requires-python = ">=3.8" -license = { text = "Apache License 2.0" } +license = "Apache-2.0" authors = [ - { name = "Ankit Chaubey", email = "m.ankitchaubey@gmail.com" } + { name = "Ankit Chaubey", email = "m.ankitchaubey@gmail.com" } ] dependencies = [ - "tqdm>=4.60.0" + "tqdm>=4.60.0" ] keywords = [ - "encryption", - "cryptography", - "security", - "aes", - "chacha20", - "streaming", - "files", - "privacy", - "libsodium" + "encryption", + "cryptography", + "security", + "aes", + "chacha20", + "streaming", + "files", + "privacy", + "libsodium" ] classifiers = [ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Security :: Cryptography", - "Topic :: System :: Archiving :: Backup", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: C", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Operating System :: POSIX :: Linux", - "Operating System :: Unix" + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Topic :: Security :: Cryptography", + "Topic :: System :: Archiving :: Backup", + "Programming Language :: C", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Operating System :: POSIX :: Linux", + "Operating System :: Unix" ] [project.urls] diff --git a/setup.py b/setup.py index 848cc86..6545862 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,60 @@ -from setuptools import setup, find_packages +from setuptools import setup, find_packages, Extension +from setuptools.command.build_ext import build_ext +import subprocess +import os +import sys +import shutil + + +class BuildCiphExt(build_ext): + def run(self): + root = os.path.abspath(os.path.dirname(__file__)) + + print("\nšŸ”§ Building native libciph") + + # Clean is best-effort + try: + subprocess.check_call(["make", "clean"], cwd=root) + except Exception: + pass + + subprocess.check_call(["make"], cwd=root) + + if sys.platform.startswith("linux"): + libname = "libciph.so" + elif sys.platform == "darwin": + libname = "libciph.dylib" + elif sys.platform.startswith(("win32", "cygwin", "msys")): + libname = "ciph.dll" + else: + raise RuntimeError(f"Unsupported platform: {sys.platform}") + + src = os.path.join(root, libname) + if not os.path.exists(src): + raise RuntimeError(f"Native build failed: {libname} not found") + + dst = os.path.join(root, "ciph", "_native") + os.makedirs(dst, exist_ok=True) + shutil.copy2(src, os.path.join(dst, libname)) + + print(f"āœ” Native library installed → ciph/_native/{libname}\n") + + super().run() + + +# Dummy extension to force build_ext execution +ext_modules = [ + Extension( + "ciph._build", + sources=["ciph/_build.c"], + ) +] setup( - name="ciph", - version="1.2.1", - description="Fast, streaming file encryption for large media files and cloud uploads", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", + packages=find_packages(), include_package_data=True, - entry_points={ - "console_scripts": [ - "ciph=ciph.cli:main", - ] - }, - python_requires=">=3.8", - install_requires=[ - "tqdm>=4.60.0", - ], + + ext_modules=ext_modules, + cmdclass={"build_ext": BuildCiphExt}, )