How to compile native libraries for all platforms
Rust must be installed via rustup (not via Homebrew):
# Check if rustup is installed
rustup --version
# If not installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shZig is used as the cross-compilation toolchain:
# macOS
brew install zig
# Linux (Ubuntu/Debian)
sudo apt install zig
# Verify installation
zig versionTool that integrates Zig with Cargo for cross-compilation:
cargo install cargo-zigbuild
# Verify installation
cargo zigbuild --versionAdd compilation targets for each platform:
rustup target add aarch64-apple-darwin # macOS ARM64
rustup target add x86_64-apple-darwin # macOS x64
rustup target add x86_64-unknown-linux-gnu # Linux x64
rustup target add x86_64-pc-windows-gnu # Windows x64Use the script to verify all dependencies are installed:
./scripts/build_native.sh --checkExpected output:
═══════════════════════════════════════════
Checking Dependencies
═══════════════════════════════════════════
✓ rustup: rustup 1.29.0
✓ cargo: cargo 1.94.1
✓ zig: 0.15.2
✓ cargo-zigbuild: cargo-zigbuild 0.22.1
ℹ Checking Rust targets...
✓ aarch64-apple-darwin
✓ x86_64-apple-darwin
✓ x86_64-unknown-linux-gnu
✓ x86_64-pc-windows-gnu
✓ All dependencies are installed!
To compile only for the current platform:
# A specific driver
./scripts/build_native.sh sqlite --local
# All drivers
./scripts/build_native.sh all --localTo compile for all platforms (requires zig + cargo-zigbuild):
# A specific driver
./scripts/build_native.sh sqlite
# All drivers
./scripts/build_native.sh allTo prepare a complete release:
./scripts/build_release.shThis script:
- Verifies all dependencies
- Compiles all drivers for all platforms
- Verifies all binaries were generated
- Shows a summary with sizes
| Driver | Feature Flag | Rust Crate |
|---|---|---|
sqlite |
--features sqlite |
sqlx |
postgres |
--features postgres |
sqlx |
mysql |
--features mysql |
sqlx |
mssql |
--features mssql |
tiberius |
| Platform | Target | Extension |
|---|---|---|
| macOS ARM64 | aarch64-apple-darwin |
.dylib |
| macOS x64 | x86_64-apple-darwin |
.dylib |
| Linux x64 | x86_64-unknown-linux-gnu |
.so |
| Windows x64 | x86_64-pc-windows-gnu |
.dll |
Binaries are copied to packages/anaki_<driver>/native_libs/:
packages/
├── anaki_sqlite/native_libs/
│ ├── libanaki_sqlite-darwin-arm64.dylib
│ ├── libanaki_sqlite-darwin-x64.dylib
│ ├── libanaki_sqlite-linux-x64.so
│ └── anaki_sqlite-windows-x64.dll
├── anaki_postgres/native_libs/
│ └── ...
├── anaki_mysql/native_libs/
│ └── ...
└── anaki_mssql/native_libs/
└── ...
Rust was installed via Homebrew, not via rustup:
# Uninstall from Homebrew
brew uninstall rust
# Install via rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Restart terminalZig is not installed or not in PATH:
brew install zigMissing target in rustup:
rustup target add x86_64-unknown-linux-gnuThe Windows target uses GNU toolchain. If there are problems:
# Check if target is installed
rustup target list --installed | grep windows
# Reinstall if necessary
rustup target remove x86_64-pc-windows-gnu
rustup target add x86_64-pc-windows-gnuThe Rust crate is called anaki_native, so the output is libanaki_native.{ext}. The script renames it to libanaki_<driver>-<platform>.{ext}.
If the binary is not found, check:
ls -la rust/target/*/release/*.{dylib,so,dll} 2>/dev/nullAfter compiling all binaries:
# 1. Verify all binaries exist
./scripts/build_release.sh
# 2. Update version in pubspec.yaml files
# packages/anaki_orm/pubspec.yaml
# packages/anaki_sqlite/pubspec.yaml
# etc.
# 3. Dry-run to verify
cd packages/anaki_sqlite
dart pub publish --dry-run
# 4. Publish
dart pub publishPublishing order:
anaki_orm(core, no native dependencies)anaki_sqliteanaki_postgresanaki_mysqlanaki_mssql