Files
SpotiFLAC-Mobile/scripts/build_rust_backend_windows.ps1
T
zarzet 83b5ca96f7 build(rust): trim bundled SQLite and hide C symbols
The build scripts compile the bundled SQLite without the subsystems
the backend never calls (FTS3, R-Tree, math functions, extension
loading, UTF-16, shared cache, deprecated entry points) on every
platform. FTS5 with the trigram tokenizer, JSON, WAL and triggers
stay. C code builds with hidden visibility, libusb included, and for
size on Android.

SQLite stays bundled on Apple platforms as well: rusqlite 0.43 calls
sqlite3_set_clientdata (SQLite 3.44), which the system library of
iOS 16 and macOS 12 does not have.

build_rust_backend.sh builds a single macOS architecture with
MORNYE_MACOS_ARCH and strips local symbols from the desktop libraries.
2026-11-22 00:21:30 +07:00

64 lines
2.4 KiB
PowerShell

# Build the Rust desktop backend (mornye_desktop.dll) on Windows and stage it
# in rust_backend\target\desktop\windows\<arch>\, where windows\CMakeLists.txt
# installs it next to mornye.exe. This is the Windows counterpart of
# `bash scripts/build_rust_backend.sh desktop`.
#
# Requirements: rustup (the toolchain is pinned by rust_backend\rust-toolchain.toml)
# and the MSVC build tools. LLVM is not needed: rquickjs uses its prebuilt
# Windows MSVC bindings.
#
# Usage, from the repository root:
# pwsh scripts\build_rust_backend_windows.ps1
# pwsh scripts\build_rust_backend_windows.ps1 -Target aarch64-pc-windows-msvc
[CmdletBinding()]
param(
[ValidateSet('x86_64-pc-windows-msvc', 'aarch64-pc-windows-msvc')]
[string]$Target = $(if ([Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') {
'aarch64-pc-windows-msvc'
} else {
'x86_64-pc-windows-msvc'
})
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$projectDir = Split-Path -Parent $PSScriptRoot
$rustBackendDir = Join-Path $projectDir 'rust_backend'
$targetDir = Join-Path $rustBackendDir 'target'
Push-Location $rustBackendDir
try {
$env:CARGO_TARGET_DIR = $targetDir
$env:CFLAGS = (($env:CFLAGS, '/Gy', '/Gw') | Where-Object { $_ }) -join ' '
$env:LIBSQLITE3_FLAGS = (($env:LIBSQLITE3_FLAGS,
'-USQLITE_ENABLE_FTS3',
'-USQLITE_ENABLE_FTS3_PARENTHESIS',
'-USQLITE_ENABLE_RTREE',
'-USQLITE_ENABLE_MATH_FUNCTIONS',
'-DSQLITE_OMIT_LOAD_EXTENSION',
'-DSQLITE_OMIT_DEPRECATED',
'-DSQLITE_OMIT_UTF16',
'-DSQLITE_OMIT_GET_TABLE',
'-DSQLITE_OMIT_SHARED_CACHE',
'-DSQLITE_OMIT_COMPLETE',
'-DSQLITE_OMIT_TCL_VARIABLE') | Where-Object { $_ }) -join ' '
rustup target add $Target
if ($LASTEXITCODE -ne 0) { throw "rustup target add $Target failed." }
cargo rustc --locked --release -p mornye-desktop --lib --target $Target -- `
-C link-arg=/OPT:REF `
-C link-arg=/OPT:ICF
if ($LASTEXITCODE -ne 0) { throw "Building mornye-desktop for $Target failed." }
$arch = if ($Target -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
$desktopDir = Join-Path $targetDir "desktop\windows\$arch"
New-Item -ItemType Directory -Force $desktopDir | Out-Null
Copy-Item -Force (Join-Path $targetDir "$Target\release\mornye_desktop.dll") $desktopDir
Write-Host "Rust desktop library is staged in $desktopDir."
}
finally {
Pop-Location
}