Build debian package for SQLCipher4
This commit is contained in:
parent
2f68084bdd
commit
d1aa5762bc
28 changed files with 285904 additions and 168 deletions
76
setup.py
76
setup.py
|
|
@ -26,6 +26,7 @@ sources = glob("src/*.c") + ["src/sqlcipher/sqlite3.c"]
|
|||
library_dirs = []
|
||||
include_dirs = ["./src"]
|
||||
|
||||
|
||||
def get_native_arch() -> str:
|
||||
for k, v in CONAN_ARCHS.items():
|
||||
if platform.machine().lower() in v:
|
||||
|
|
@ -36,7 +37,7 @@ def get_native_arch() -> str:
|
|||
|
||||
|
||||
def get_arch() -> str:
|
||||
arch_env = os.getenv("SQLCIPHER3_COMPILE_TARGET")
|
||||
arch_env = os.getenv("SQLCIPHER4_COMPILE_TARGET")
|
||||
if isinstance(arch_env, str):
|
||||
arch = arch_env
|
||||
else:
|
||||
|
|
@ -46,8 +47,7 @@ def get_arch() -> str:
|
|||
|
||||
|
||||
def install_openssl(arch: str) -> "dict[Any, Any]":
|
||||
"""Install openssl using Conan.
|
||||
"""
|
||||
"""Install openssl using Conan."""
|
||||
settings: list[str] = []
|
||||
options: list[str] = []
|
||||
|
||||
|
|
@ -67,29 +67,41 @@ def install_openssl(arch: str) -> "dict[Any, Any]":
|
|||
options.append("openssl/*:no_zlib=True")
|
||||
|
||||
build = ["missing"]
|
||||
if os.path.isdir("/lib") and any(e.startswith("libc.musl") for e in os.listdir("/lib")):
|
||||
if os.path.isdir("/lib") and any(
|
||||
e.startswith("libc.musl") for e in os.listdir("/lib")
|
||||
):
|
||||
# Need to compile openssl if musllinux
|
||||
build.append("openssl*")
|
||||
|
||||
subprocess.run(["conan", "profile", "detect", "-f"])
|
||||
# Latest openssl need center2.conan.io instead of center.conan.io
|
||||
subprocess.run(["conan", "remote", "update", "conancenter", "--url=https://center2.conan.io"])
|
||||
subprocess.run(
|
||||
["conan", "remote", "update", "conancenter", "--url=https://center2.conan.io"]
|
||||
)
|
||||
|
||||
conan_output = os.path.join("conan_output", arch)
|
||||
result = subprocess.run([
|
||||
"conan", "install",
|
||||
*[x for s in settings for x in ("-s", s)],
|
||||
*[x for b in build for x in ("-b", b)],
|
||||
*[x for o in options for x in ("-o", o)],
|
||||
"-of", conan_output, "--deployer=direct_deploy", "--format=json", "."
|
||||
], stdout=subprocess.PIPE).stdout.decode()
|
||||
result = subprocess.run(
|
||||
[
|
||||
"conan",
|
||||
"install",
|
||||
*[x for s in settings for x in ("-s", s)],
|
||||
*[x for b in build for x in ("-b", b)],
|
||||
*[x for o in options for x in ("-o", o)],
|
||||
"-of",
|
||||
conan_output,
|
||||
"--deployer=direct_deploy",
|
||||
"--format=json",
|
||||
".",
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
).stdout.decode()
|
||||
conan_info = json.loads(result)
|
||||
|
||||
return conan_info
|
||||
|
||||
|
||||
def add_deps(conan_info: "dict[Any, Any]") -> "tuple[list[str], list[str]]":
|
||||
"""Find directories of dependencies.
|
||||
"""
|
||||
"""Find directories of dependencies."""
|
||||
library_dirs: list[str] = []
|
||||
include_dirs: list[str] = []
|
||||
for dep in conan_info["graph"]["nodes"].values():
|
||||
|
|
@ -99,9 +111,10 @@ def add_deps(conan_info: "dict[Any, Any]") -> "tuple[list[str], list[str]]":
|
|||
|
||||
library_dirs.append(os.path.join(package_folder, "lib"))
|
||||
include_dirs.append(os.path.join(package_folder, "include"))
|
||||
|
||||
|
||||
return library_dirs, include_dirs
|
||||
|
||||
|
||||
def quote_argument(arg: str) -> str:
|
||||
is_cibuildwheel = os.environ.get("CIBUILDWHEEL", "0") == "1"
|
||||
|
||||
|
|
@ -115,9 +128,10 @@ def quote_argument(arg: str) -> str:
|
|||
|
||||
return q + arg + q
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
define_macros: "list[tuple[str, Optional[str]]]" = [
|
||||
("MODULE_NAME", quote_argument("sqlcipher3.dbapi2")),
|
||||
("MODULE_NAME", quote_argument("sqlcipher4.dbapi2")),
|
||||
("SQLITE_ENABLE_FTS3", "1"),
|
||||
("SQLITE_ENABLE_FTS3_PARENTHESIS", "1"),
|
||||
("SQLITE_ENABLE_FTS4", "1"),
|
||||
|
|
@ -144,14 +158,24 @@ if __name__ == "__main__":
|
|||
("inline", "__inline"),
|
||||
]
|
||||
|
||||
# Debian builds (and similar) should be able to use system OpenSSL
|
||||
# instead of downloading OpenSSL via Conan.
|
||||
use_system_openssl = os.environ.get("BOUQUIN_SYSTEM_OPENSSL", "0") == "1"
|
||||
if use_system_openssl and sys.platform == "win32":
|
||||
raise RuntimeError("BOUQUIN_SYSTEM_OPENSSL=1 is not supported on Windows")
|
||||
|
||||
# Configure the compiler
|
||||
arch = get_arch()
|
||||
if arch == "universal2":
|
||||
if (not use_system_openssl) and arch == "universal2":
|
||||
conan_info_x64 = install_openssl("x86_64")
|
||||
conan_build_folder_x64: str = conan_info_x64["graph"]["nodes"]["0"]["build_folder"]
|
||||
conan_build_folder_x64: str = conan_info_x64["graph"]["nodes"]["0"][
|
||||
"build_folder"
|
||||
]
|
||||
library_dirs_x64, include_dirs_x64 = add_deps(conan_info_x64)
|
||||
conan_info_arm = install_openssl("armv8")
|
||||
conan_build_folder_arm: str = conan_info_arm["graph"]["nodes"]["0"]["build_folder"]
|
||||
conan_build_folder_arm: str = conan_info_arm["graph"]["nodes"]["0"][
|
||||
"build_folder"
|
||||
]
|
||||
library_dirs_arm, include_dirs_arm = add_deps(conan_info_arm)
|
||||
|
||||
if get_native_arch() == "x86_64":
|
||||
|
|
@ -183,11 +207,13 @@ if __name__ == "__main__":
|
|||
|
||||
shutil.rmtree(lipo_dir_merge_src)
|
||||
shutil.move(lipo_dir_merge_result, lipo_dir_merge_src)
|
||||
else:
|
||||
elif not use_system_openssl:
|
||||
conan_info = install_openssl(arch)
|
||||
library_dirs, include_dirs = add_deps(conan_info)
|
||||
|
||||
extra_compile_args: "list[str]" = ["-Qunused-arguments"] if sys.platform == "darwin" else []
|
||||
extra_compile_args: "list[str]" = (
|
||||
["-Qunused-arguments"] if sys.platform == "darwin" else []
|
||||
)
|
||||
|
||||
# Configure the linker
|
||||
extra_link_args: "list[str]" = []
|
||||
|
|
@ -204,7 +230,7 @@ if __name__ == "__main__":
|
|||
extra_link_args.extend(["-lm", "-lcrypto"])
|
||||
|
||||
module = Extension(
|
||||
name="sqlcipher3._sqlite3",
|
||||
name="sqlcipher4._sqlite3",
|
||||
sources=sources,
|
||||
define_macros=define_macros,
|
||||
library_dirs=library_dirs,
|
||||
|
|
@ -217,9 +243,9 @@ if __name__ == "__main__":
|
|||
setup(
|
||||
# With pyproject.toml, all are not necessary except ext_modules
|
||||
# However, they are kept for building python 3.6 wheels
|
||||
name="sqlcipher3-wheels",
|
||||
name="sqlcipher4",
|
||||
version="0.5.6",
|
||||
package_dir={"sqlcipher3": "sqlcipher3"},
|
||||
packages=["sqlcipher3"],
|
||||
package_dir={"sqlcipher4": "sqlcipher4"},
|
||||
packages=["sqlcipher4"],
|
||||
ext_modules=[module],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue