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
2 changes: 1 addition & 1 deletion .github/workflows/sqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
uses: ./.github/workflows/_matrix.yml
with:
disable_static: true
select_platforms: "macosx, linux, android"
select_platforms: "macosx, linux, android, win-msvc"
23 changes: 22 additions & 1 deletion build_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def __init__(self,
# - API Level 35: android.media.MediaCodec#PARAMETER_KEY_QP_OFFSET_MAP
self.android_api_level: "int" = 28

self.win32_sdk_version: "str" = ''
self.win32_compat_vers: "str" = '19.00' # -D_MSC_VER=1900
self.win32_msvc_env_native: "dict[str, str]" = {}
self.win32_msvc_env_target: "dict[str, str]" = {}

Expand Down Expand Up @@ -507,13 +509,32 @@ def _setctx_win32_msvc(

msvc_dir, msvc_devshell = x.win32_msvc_detect()
state.win32_msvc_env_native = x.win32_msvc_dump_env(msvc_dir, msvc_devshell, x.NATIVE_ARCH)
state.win32_msvc_env_target = x.win32_msvc_dump_env(msvc_dir, msvc_devshell, state.target_arch)
state.win32_msvc_env_target = x.win32_msvc_dump_env(msvc_dir, msvc_devshell, state.target_arch, state.win32_sdk_version)

state.llvm_triple = {
'arm64': f'aarch64-pc-windows-msvc',
'amd64': f'x86_64-pc-windows-msvc',
}[state.target_arch]

state.cc.extend([
f'clang', f'--driver-mode=cl',
f'--target={state.llvm_triple}',
f'-fms-compatibility-version={state.win32_compat_vers}',
])
if state.win32_sdk_version:
state.cc.extend([
f'/winsdkversion', state.win32_sdk_version,
])
if state.target_arch == 'amd64':
state.cc.extend(['-march=x86-64-v2'])
if state.target_arch == 'arm64':
state.cc.extend(['-march=armv8-a'])
state.ar.extend(['llvm-ar'])
state.ar.extend(['llvm-nm'])
state.ldflags.extend(['/clang:-fuse-ld=lld'])
state.objcopy.extend(['llvm-objcopy'])
state.objcopy.extend(['llvm-windres'])

# cmake toolchain file
state.extra_cmake.extend([
'-G', 'Ninja',
Expand Down
27 changes: 22 additions & 5 deletions modules/sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ def _build_step_0():
'-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',
]
if ctx.args.target_plat != 'win-msvc':
args.extend([
'-std=c11', '-fPIC', '-Wall', '-Wextra',
'-shared', '-v', '-O3', '-DNDEBUG',
'-ffunction-sections', '-fdata-sections',
'-pthread',
])
else:
args.extend([
'/std:c11', '-DNDEBUG', '/W4', '/Gw', '/Gy', '/MT', '/LD',
'/clang:-v', '/clang:-O3',
])

output = (Path(ctx.args.pkg_inst_dir))
if ctx.args.target_plat in {'linux', 'android'}:
Expand All @@ -83,6 +90,16 @@ def _build_step_0():
'-Wl,--icf=safe', '-Wl,-rpath,$ORIGIN',
'-o', output.as_posix(), f'-Wl,--soname={output.name}', '-lm',
])
elif ctx.args.target_plat == 'win-msvc':
output = (output / 'lib' / 'libsqlite3.dll'); \
output.parent.mkdir(parents=True, exist_ok=True)
args.extend([
'-Xlinker', '/OPT:REF',
'-Xlinker', '/OPT:ICF',
'-Xlinker', '/WX',
'-Xlinker', '/Brepro',
'-o', output.as_posix(),
])
elif ctx.args.target_plat == 'win-mingw':
pass
else: # apple platform
Expand Down
6 changes: 3 additions & 3 deletions x_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def win32_msvc_detect() -> "tuple[Path, Path]":
logv(f'load msvc devshell: "{msvc_devshell.as_posix()}"')
return (msvc_dir, msvc_devshell)

def win32_msvc_dump_env(msvc_dir: Path, msvc_devshell: Path, target_arch: str) -> "dict[str, str]":
def win32_msvc_dump_env(msvc_dir: Path, msvc_devshell: Path, target_arch: str, winsdk_version: "str | None" = None) -> "dict[str, str]":
if NATIVE_PLAT != 'windows':
loge(f'only works on windows, host os: {NATIVE_PLAT}')

Expand All @@ -267,15 +267,15 @@ def win32_msvc_dump_env(msvc_dir: Path, msvc_devshell: Path, target_arch: str) -

# Only supports access to the VS DevShell from PowerShell
# - https://learn.microsoft.com/visualstudio/ide/reference/command-prompt-powershell#developer-powershell
vs_devshell_arg = f'-host_arch={NATIVE_ARCH} -arch={target_arch}'
vs_devshell_arg = f'-host_arch={NATIVE_ARCH} -arch={target_arch} -no_logo'
if winsdk_version: vs_devshell_arg += f' -winsdk={winsdk_version}'

pwsh_script_blk = f'Import-Module "{msvc_devshell}"; '
pwsh_script_blk += f'Enter-VsDevShell -VsInstallPath "{msvc_dir}" -SkipAutomaticLocation -DevCmdArguments "{vs_devshell_arg}"; '
pwsh_script_blk += f'Get-ChildItem Env: | Select-Object -Property Name,Value | ConvertTo-Json -Depth 1 1>{msvc_env_json.as_posix()}; '
run_as_subprocess(['pwsh',
'-WorkingDirectory', PROJ_ROOT,
'-NonInteractive',
'-NoProfileLoadTime',
'-ExecutionPolicy', 'Bypass',
'-Command', pwsh_script_blk
])
Expand Down
Loading