toys/fastapi-rs/build.ps1

29 lines
714 B
PowerShell

#!/usr/bin/env pwsh
#
# Build the executable with minimal size optimization
#
# Author: donkey <anjingyu_ws@foxmail.com>
# NOTE: please check the options in Cargo.toml
# [profile.release]
# strip = true
# opt-level = "z" # Optimize for size
# lto = true
# codegen-units = 1
Push-Location $PSScriptRoot
cargo build --release
if ($?) {
# Do compression via UPX
if (Get-Command -Name upx -ErrorAction SilentlyContinue) {
mv target/release/fastapi.exe ./
upx --best --lzma ./fastapi.exe
} else {
Write-Host "Please install UPX for smaller size: scoop install upx" -Foreground Red
}
} else {
Write-Host "Failed to build the rust project" -Foreground Yellow
}
Pop-Location