|
| 1 | +# Cargo Configuration Strategy |
| 2 | + |
| 3 | +This repository uses a dual-configuration approach to support both CI builds and OSS developers. |
| 4 | + |
| 5 | +## For Developers (Default) |
| 6 | + |
| 7 | +The default `.cargo/config.toml` uses **crates.io** directly: |
| 8 | +- No authentication required |
| 9 | +- Works seamlessly for OSS developers |
| 10 | +- No ADO access needed |
| 11 | + |
| 12 | +```bash |
| 13 | +# Just clone and build - works out of the box |
| 14 | +git clone <repo> |
| 15 | +cd mssql-tds |
| 16 | +cargo build |
| 17 | +``` |
| 18 | + |
| 19 | +## For CI/Pipeline |
| 20 | + |
| 21 | +CI builds use `.cargo/config.ci.toml` which configures: |
| 22 | +- **Authenticated Azure Artifacts feeds** (`mssql-rs_Public` and `mssql-rs`) |
| 23 | +- Source replacement: `crates.io` → `mssql-rs_Public` (ADO feed with crates.io as upstream) |
| 24 | +- Authentication via `CargoAuthenticate@0` task (sets `CARGO_REGISTRIES_*_TOKEN` env vars) |
| 25 | + |
| 26 | +### How It Works |
| 27 | + |
| 28 | +1. **Apply CI config**: `.pipeline/scripts/apply-ci-cargo-config.{sh,ps1}` copies `config.ci.toml` → `config.toml` |
| 29 | +2. **Authenticate**: `CargoAuthenticate@0` task sets token environment variables |
| 30 | +3. **Build**: Cargo uses authenticated ADO feeds |
| 31 | + |
| 32 | +### Pipeline Flow |
| 33 | + |
| 34 | +```yaml |
| 35 | +# All build templates include these steps: |
| 36 | +- script: bash .pipeline/scripts/apply-ci-cargo-config.sh |
| 37 | + displayName: Apply CI cargo configuration |
| 38 | + |
| 39 | +- task: CargoAuthenticate@0 |
| 40 | + inputs: |
| 41 | + configFile: '.cargo/config.toml' |
| 42 | + displayName: Authenticate cargo registries |
| 43 | + |
| 44 | +# Now cargo commands use authenticated feeds |
| 45 | +- script: cargo build |
| 46 | +``` |
| 47 | +
|
| 48 | +## Files |
| 49 | +
|
| 50 | +| File | Purpose | |
| 51 | +|------|---------| |
| 52 | +| `.cargo/config.toml` | **Default** - Uses crates.io (for developers) | |
| 53 | +| `.cargo/config.ci.toml` | **CI override** - Uses authenticated ADO feeds | |
| 54 | +| `.pipeline/scripts/apply-ci-cargo-config.sh` | Applies CI config (Linux/Mac) | |
| 55 | +| `.pipeline/scripts/apply-ci-cargo-config.ps1` | Applies CI config (Windows) | |
| 56 | + |
| 57 | +## Benefits |
| 58 | + |
| 59 | +✅ **Zero friction for OSS developers** - Just clone and build |
| 60 | +✅ **Fast CI builds** - Uses ADO artifact cache |
| 61 | +✅ **Secure** - Tokens only exist in CI, not committed to repo |
| 62 | +✅ **Flexible** - Easy to switch between modes |
| 63 | + |
| 64 | +## Troubleshooting |
| 65 | + |
| 66 | +### For Developers |
| 67 | +If you see authentication errors, ensure you're using the default config: |
| 68 | +```bash |
| 69 | +git checkout .cargo/config.toml |
| 70 | +``` |
| 71 | + |
| 72 | +### For CI |
| 73 | +Ensure the apply-ci-cargo-config step runs **before** `CargoAuthenticate@0`: |
| 74 | +```yaml |
| 75 | +- script: bash .pipeline/scripts/apply-ci-cargo-config.sh |
| 76 | +- task: CargoAuthenticate@0 |
| 77 | + inputs: |
| 78 | + configFile: '.cargo/config.toml' |
| 79 | +``` |
0 commit comments