Skip to content
Merged
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
30 changes: 30 additions & 0 deletions .github/workflows/sqlite3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: sqlite3
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/matrix*.json'
- '.github/workflows/_matrix.yml'
- '.github/workflows/sqlite3.yml'
- 'patches/sqlite3/**'
- 'modules/sqlite3.py'
pull_request:
branches:
- main
paths:
- '.github/matrix*.json'
- '.github/workflows/_matrix.yml'
- '.github/workflows/sqlite3.yml'
- 'patches/sqlite3/**'
- 'modules/sqlite3.py'

jobs:
build:
# if: ${{ false }}
secrets: inherit
uses: ./.github/workflows/_matrix.yml
with:
disable_static: true
select_platforms: "macosx, linux, android"
41 changes: 41 additions & 0 deletions build_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
x.loge('Required Python Interpreter ≥ 3.8') # pyright: ignore[reportUnreachable]
# ----------------------------

import http.client
import os
import runpy
import shutil
import time
import urllib.request

from dataclasses import dataclass
from typing import Callable, Literal, TypedDict, cast
Expand Down Expand Up @@ -134,6 +136,45 @@ def fetch_source_from_git(self,
'PKG_ZIPNAME': f'{self.args.module}_{self.args.target_plat}_{self.args.target_archinfo}_{ver}_{x.feature("PKG_TYPE")}',
})

def fetch_source_from_http(self,
version: "str", url: "str", *,
archive_format: "Literal['zip']",
archive_prefix: "str | None" = None,
extracted_file: "list[str] | None" = None,
):
self._subproj_src.mkdir(parents=True, exist_ok=True)
if not any(self._subproj_src.iterdir()):
archive = (self._subproj_src.parent / f'{self._subproj_src.name}.{archive_format}')
x.logv(f'fetch source from "{url}" > "{archive.as_posix()}"')
if not archive.exists():
with cast(http.client.HTTPResponse,
urllib.request.urlopen(
urllib.request.Request(url)
)
) as resp:
if resp.status != 200:
x.loge(f"respcode: {resp.status}, respbody: ->\n{resp.read().decode(errors='ignore')}")
with archive.open('wb') as dst:
shutil.copyfileobj(resp, dst)

if False:
pass # pyright: ignore[reportUnreachable]
elif archive_format == 'zip':
archive_prefix = (archive_prefix or '')

files: list[str] = []
for src in (extracted_file or []):
files.append(f'{archive_prefix}{src}')
x.unzip_with_softlink(archive, extract_dir=self._subproj_src.as_posix(), files=files)


_ = self._subproj_ver.write_text(version)

x.gha_append_env({
'PKG_VERSION': version,
'PKG_ZIPNAME': f'{self.args.module}_{self.args.target_plat}_{self.args.target_archinfo}_{version}_{x.feature("PKG_TYPE")}',
})

def subproj_src_dir(self, *subdir: "str | Path") -> Path:
if not subdir:
return self._subproj_src
Expand Down
133 changes: 133 additions & 0 deletions modules/sqlite3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# fmt: off

import sys
from pathlib import Path

sys.dont_write_bytecode = True

_this_file = (Path(__file__).absolute().resolve())
sys.path.append(
(_this_file.parents[1]).as_posix()
); import x_utils as x

if __name__ == "__main__": x.loge_usage()
# ----------------------------
from typing import Callable, cast
from build_v2 import BuildCtx
ctx = cast(BuildCtx, globals()["ctx"])
# ----------------------------
def build_steps() -> "list[Callable[[], None]]":
return [
_fetch_source,
_build_step_0,
]
# ----------------------------
def get_build_env() -> "dict[str, str]":
env = x.ENVIRON
if ctx.args.target_plat == 'win-msvc':
env.update(ctx.args.win32_msvc_env_target)
env['CFLAGS'] = '/utf-8'
env['CXXFLAGS'] = env['CFLAGS']
return env
# ----------------------------
archive_prefix = 'sqlite-amalgamation-3530300'
# ----------------------------
def _fetch_source():
ctx.fetch_source_from_http(version='v3.53.3',
url=f'https://sqlite.org/2026/{archive_prefix}.zip',
archive_format='zip',
archive_prefix=f'{archive_prefix}/',
extracted_file=['sqlite3.c', 'sqlite3.h'],
)
def _build_step_0():
import shutil

args = ctx.args.cc + ctx.args.ldflags + [
'-DHAVE_FDATASYNC=1',
'-DSQLITE_DQS=0',
'-DSQLITE_THREADSAFE=1',
'-DSQLITE_DEFAULT_AUTOMATIC_INDEX=1',
'-DSQLITE_DEFAULT_AUTOVACUUM=0',
'-DSQLITE_DEFAULT_FOREIGN_KEYS=0',
'-DSQLITE_DEFAULT_MMAP_SIZE=0',
'-DSQLITE_DEFAULT_MEMSTATUS=0',
'-DSQLITE_DEFAULT_SYNCHRONOUS=3',
'-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=3',
'-DSQLITE_JSON_MAX_DEPTH=64',
'-DSQLITE_LIKE_DOESNT_MATCH_BLOBS',
'-DSQLITE_TEMP_STORE=3',
'-DSQLITE_MAX_EXPR_DEPTH=0',
'-DSQLITE_OMIT_AUTORESET',
'-DSQLITE_OMIT_AUTOINIT',
'-DSQLITE_OMIT_DECLTYPE',
'-DSQLITE_OMIT_DEPRECATED',
'-DSQLITE_OMIT_LOAD_EXTENSION',
'-DSQLITE_OMIT_PROGRESS_CALLBACK',
'-DSQLITE_OMIT_SHARED_CACHE',
'-DSQLITE_OMIT_UTF16',
'-DSQLITE_STRICT_SUBTYPE=1',
] + [
'-std=c11', '-fPIC', '-Wall', '-Wextra',
'-shared', '-v', '-O3', '-DNDEBUG',
'-ffunction-sections', '-fdata-sections',
'-pthread',
]

output = (Path(ctx.args.pkg_inst_dir))
if ctx.args.target_plat in {'linux', 'android'}:
output = (output / 'lib' / 'libsqlite3.so'); \
output.parent.mkdir(parents=True, exist_ok=True)
args.extend([
'-Wl,--gc-sections', '-Wl,--build-id',
'-Wl,--icf=safe', '-Wl,-rpath,$ORIGIN',
'-o', output.as_posix(), f'-Wl,--soname={output.name}', '-lm',
])
elif ctx.args.target_plat == 'win-mingw':
pass
else: # apple platform
output = (output / 'lib' / 'libsqlite3.dylib'); \
output.parent.mkdir(parents=True, exist_ok=True)
args.extend([
'-Wl,-dead_strip',
'-o', output.as_posix(), '-install_name', output.name,
])
args.extend([
f'-I{ctx.subproj_src_dir(archive_prefix).as_posix()}',
ctx.subproj_src_dir(archive_prefix, 'sqlite3.c').as_posix(),
])
x.run_as_subprocess(env=get_build_env(), args=args)


src_dst_mapping: list[dict[Path, Path]] = [
{
(ctx.subproj_src_dir(archive_prefix, 'sqlite3.h')):
(Path(ctx.args.pkg_inst_dir) / 'include' / 'sqlite3.h'),
},
]
for map in src_dst_mapping:
for src, dst in map.items():
if src.is_file():
dst.unlink(missing_ok=True)
dst.parent.mkdir(parents=True, exist_ok=True)
_ = shutil.copy2(src, dst)
if src.is_dir():
shutil.rmtree(dst, ignore_errors=True)
_ = src.rename(dst)

_pkgconf_content = '''\
prefix=${pcfiledir}/../..
includedir=${prefix}/include
libdir=${prefix}/lib

Name: SQLite
Description: SQL database engine
Version: @PKGCONFIG_VERSION@
Requires:
Cflags: -I${includedir}
Libs: -L${libdir} -lsqlite3
'''
_pkgconf_content = _pkgconf_content.replace('@PKGCONFIG_VERSION@', ctx.subproj_src_ver())

_pkgconf = (Path(ctx.args.pkg_inst_dir) / 'lib' / 'pkgconfig' / 'sqlite3.pc'); \
_pkgconf.parent.mkdir(parents=True, exist_ok=True)
_ = _pkgconf.write_text(_pkgconf_content)
6 changes: 4 additions & 2 deletions x_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ def runpy_pip(pkgs: "list[str]"):
args.extend(['pip', *pkgs])
runpy(args=args)
# ----------------------------
def unzip_with_softlink(zipfile: Path, extract_dir: "str | None" = None, is_msys64: bool = False):
def unzip_with_softlink(zipfile: Path, *,
extract_dir: "str | None" = None, files: "list[str] | None" = None, is_msys64: bool = False
):
if not extract_dir:
extract_dir = zipfile.parent.as_posix()
cmd = ['unzip', '-o', zipfile.as_posix(), '-d', extract_dir]
cmd = ['unzip', '-o', zipfile.as_posix(), '-d', extract_dir] + (files or [])
if (NATIVE_PLAT == 'windows') and (is_msys64):
cmd = ['C:/msys64/usr/bin/bash.exe', '-c', ' '.join(cmd)]
run_as_subprocess(args=cmd)
Expand Down
Loading