2026-06-14 08:15:50 +00:00
# libsodium pkg-config Detection Fix
2026-06-14 08:04:08 +00:00
2026-06-14 09:02:10 +00:00
> **Scope:** This document describes **only the changes in this PR**. For historical context including prior related work, see `LIBSODIUM_BUILD_HISTORY.md`.
2026-06-14 07:07:38 +00:00
## Description
2026-06-14 09:02:10 +00:00
This PR fixes libsodium build failures by adding explicit `SODIUM_USE_PKG_CONFIG` environment variables to CI workflows. The Docker images already have libsodium packages installed, but the build script wasn't being told **how** to find them.
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
**Build failures observed:**
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
1. **Linux amd64/arm64** : `libsodium not found via pkg-config or vcpkg` (despite `libsodium-dev` + `pkg-config` being installed in Docker images)
2026-06-14 08:15:50 +00:00
2. **Windows cross-build** : `SODIUM_LIB_DIR is incompatible with SODIUM_USE_PKG_CONFIG` (conflicting detection methods)
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
## Root Cause
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
The `libsodium-sys-stable` crate's `build.rs` checks environment variables in this precedence:
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
1. If `SODIUM_LIB_DIR` is set → use explicit path (incompatible with `SODIUM_USE_PKG_CONFIG` mode)
2. If `SODIUM_USE_PKG_CONFIG` ≠ `"no"` (string equality) → try pkg-config detection
3. Fall back to vcpkg or fail with error
2026-06-14 08:04:08 +00:00
2026-06-14 08:15:50 +00:00
**Note on string values:** The build script performs string comparison, so `"no"` disables pkg-config while any other value (including `"1"` , `"yes"` , or empty) enables it. YAML quotes preserve these as strings.
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
**What went wrong:**
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
- **Linux**: Had the packages installed but wasn't explicitly told to use pkg-config → fell through to vcpkg → failed
2026-06-14 09:02:10 +00:00
- **Windows**: `SODIUM_LIB_DIR` was already set, but pkg-config was also available → conflicting modes → build script error
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
## Changes in This PR
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
### `.gitea/workflows/auto-tag.yml`
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
#### Linux amd64 build (line ~347)
```yaml
env:
SODIUM_USE_PKG_CONFIG: "1" # NEW: Force pkg-config detection
2026-06-14 07:07:38 +00:00
```
2026-06-14 08:15:50 +00:00
**Why:** Ensures `libsodium-sys-stable` uses the installed `libsodium-dev` package via pkg-config.
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
#### Linux arm64 build (line ~633)
```yaml
env:
SODIUM_USE_PKG_CONFIG: "1" # NEW: Force pkg-config for cross-compile
2026-06-14 07:07:38 +00:00
```
2026-06-14 08:15:50 +00:00
**Why:** Same as amd64 - force pkg-config to find the arm64 libsodium package.
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
#### Windows cross-compile build (line ~448)
```yaml
env:
2026-06-14 09:02:10 +00:00
SODIUM_LIB_DIR: /usr/x86_64-w64-mingw32/lib # Already present (see HISTORY doc)
SODIUM_STATIC: "1" # Already present (see HISTORY doc)
SODIUM_USE_PKG_CONFIG: "no" # NEW in this PR: Disable pkg-config
2026-06-14 08:15:50 +00:00
```
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
**Why:** Prevents conflict between explicit path mode (`SODIUM_LIB_DIR`) and pkg-config detection. Windows uses pre-built libsodium from Dockerfile, not system packages.
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
**Only the `SODIUM_USE_PKG_CONFIG: "no"` line is new in this PR** - the other env vars were already present.
2026-06-14 08:15:50 +00:00
### Documentation
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
**Files changed in this PR:**
- `LIBSODIUM_BUILD_FIX.md` (this file) - Documents env var strategy for pkg-config detection
- `LIBSODIUM_PKG_CONFIG_FIX.md` - Alternative/detailed version of this doc
- `LIBSODIUM_BUILD_HISTORY.md` - Complete fix history across PR #101 and PR #102
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
Explains:
- Platform-specific environment variable strategy
- Build script precedence order
- Rationale for each approach
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
## Strategy Summary
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
| Platform | Method | Env Vars | Reason |
|----------|--------|----------|--------|
| Linux amd64 | pkg-config | `SODIUM_USE_PKG_CONFIG=1` | Has `libsodium-dev` + `pkg-config` installed |
| Linux arm64 | pkg-config | `SODIUM_USE_PKG_CONFIG=1` | Has `libsodium-dev:arm64` + `pkg-config` |
| Windows | explicit path | `SODIUM_LIB_DIR=...` + `SODIUM_USE_PKG_CONFIG=no` | Pre-built lib in known location, disable pkg-config |
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
## Testing
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
This PR only modifies CI workflow environment variables. Testing occurs via CI pipeline:
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
- [ ] Linux amd64 build succeeds with pkg-config detection
- [ ] Linux arm64 build succeeds with cross-compile pkg-config
- [ ] Windows build succeeds with explicit lib path (no pkg-config conflict)
- [ ] All platforms produce valid `.deb` , `.rpm` , `.exe` , `.msi` artifacts
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
## Acceptance Criteria (This PR Only)
2026-06-14 07:07:38 +00:00
2026-06-14 08:15:50 +00:00
- [x] Added `SODIUM_USE_PKG_CONFIG` env vars to all three CI build targets
- [x] Documentation accurately reflects only changes in this PR
- [ ] Linux amd64 CI build succeeds
- [ ] Linux arm64 CI build succeeds
- [ ] Windows CI build succeeds
- [ ] All platforms produce valid artifacts
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
## Files Changed in This PR
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
1. ** `.gitea/workflows/auto-tag.yml` **
- Linux amd64 build: Added `SODIUM_USE_PKG_CONFIG: "1"`
- Linux arm64 build: Added `SODIUM_USE_PKG_CONFIG: "1"`
- Windows build: Added `SODIUM_USE_PKG_CONFIG: "no"`
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
2. **Documentation only**
- `LIBSODIUM_BUILD_FIX.md` (this file)
- `LIBSODIUM_PKG_CONFIG_FIX.md` (detailed version)
- `LIBSODIUM_BUILD_HISTORY.md` (historical context - see for relationship to PR #101 )
2026-06-14 07:07:38 +00:00
2026-06-14 09:02:10 +00:00
**No Dockerfile changes** - Docker images already have libsodium packages from prior work.
**No application code changes** - This PR only adds environment variables to CI workflow.
**No test changes** - libsodium linking is already validated by existing tests.