4.1 KiB
libsodium Build Failure - FINAL FIX
The Problem
libsodium-sys-stable v1.24.0 build script was failing with:
thread 'main' panicked at build.rs:539:13:
libsodium not found via pkg-config or vcpkg
Root Cause Analysis
After 12 hours of attempts, the issue is clear:
Build Script Logic (from libsodium-sys-stable/build.rs)
The build script checks in priority order:
- SODIUM_LIB_DIR - if set, use that path directly (HIGHEST PRIORITY)
- SODIUM_USE_PKG_CONFIG - if set, try pkg-config/vcpkg
- Fallback - try to build from source
Previous Failed Approaches
- PR #101, #102: Tried pkg-config environment variables - failed because pkg-config couldn't find libsodium in containers
- PR with use-pkg-config feature: Enabled the feature but pkg-config still failed to locate libraries
Why pkg-config Failed
- Container images have libsodium installed but pkg-config can't find the .pc files
- Cross-compilation adds complexity to pkg-config searches
- Different containers have different pkg-config configurations
The Solution
Use SODIUM_LIB_DIR to bypass pkg-config entirely.
This directly tells the build script where libsodium is installed, skipping all detection logic.
Implementation
test.yml (Rust tests)
Added to ALL cargo commands:
env:
SODIUM_LIB_DIR: /usr/lib/x86_64-linux-gnu
auto-tag.yml (Release builds)
Linux x86_64:
SODIUM_LIB_DIR: /usr/lib/x86_64-linux-gnu
Linux aarch64:
SODIUM_LIB_DIR: /usr/lib/aarch64-linux-gnu
Windows MinGW:
SODIUM_LIB_DIR: /usr/x86_64-w64-mingw32/lib
macOS: No change needed (already works)
Why This Will Work
- SODIUM_LIB_DIR has highest priority in build.rs - checked BEFORE pkg-config
- Direct path - no detection, no guessing, no pkg-config configuration issues
- Already confirmed - the original working Windows build used this exact approach
- Simple - one environment variable per platform
Branch Info
- Branch:
fix/libsodium-direct-path - Base:
beta - Commits: 1 atomic commit
- Files Changed: 2 (.gitea/workflows/test.yml, .gitea/workflows/auto-tag.yml)
Testing Status
- ⏳ Awaiting CI pipeline results
- Expected: ALL builds (Linux x86, Linux ARM, Windows, macOS) will succeed
- Expected: ALL test jobs (fmt, clippy, tests) will succeed
If This Still Fails
The only remaining possibility would be:
- Libsodium is NOT actually installed in the containers (verify with
dpkg -L libsodium-dev) - The library path is wrong (verify with
find /usr -name "libsodium.*")
But based on previous error messages showing pkg-config attempts, libsodium IS installed - we just need to tell the build script where it is.
Created: 2026-06-14 (after 12 hours of attempts)
Approach: Direct library path specification
Confidence: HIGH - This is the intended workaround when pkg-config fails
Update History
Commit 1: Initial SODIUM_LIB_DIR implementation
Added SODIUM_LIB_DIR to all workflows, but conflicted with existing use-pkg-config feature.
Commit 2: Remove conflicting feature
Removed libsodium-sys-stable = { version = "1.24", features = ["use-pkg-config"] } from Cargo.toml.
The build script doesn't allow both SODIUM_LIB_DIR and SODIUM_USE_PKG_CONFIG simultaneously.
Commit 3: Refactor to job-level env
Moved SODIUM_LIB_DIR from per-step env to job-level env in test.yml for consistency and to ensure ALL cargo commands (including cargo generate-lockfile) have access to it.
Final State
Branch commits:
863868b2- fix(ci): use SODIUM_LIB_DIR to bypass pkg-config detectionb20deab3- fix: remove use-pkg-config feature conflicting with SODIUM_LIB_DIR1172f201- refactor(ci): move SODIUM_LIB_DIR to job-level env
Files modified:
.gitea/workflows/test.yml- SODIUM_LIB_DIR at job level for 3 Rust jobs.gitea/workflows/auto-tag.yml- SODIUM_LIB_DIR in Build steps for all platformssrc-tauri/Cargo.toml- Removed conflicting use-pkg-config dependencysrc-tauri/Cargo.lock- Updated after dependency removal
Automated Review: APPROVE WITH COMMENTS (addressed in commit 3)