|
| 1 | +# Reproduction: why `cargo pgrx install --config` is needed (issue #2135) |
| 2 | + |
| 3 | +A self-contained, Docker-based reproduction of the real-world scenario PR #2343 |
| 4 | +fixes: a pgrx extension that depends on an **internal crate from a private |
| 5 | +registry**, in a monorepo where the registry is declared only in the |
| 6 | +extension's own `.cargo/config.toml`. |
| 7 | + |
| 8 | +## Why it's real |
| 9 | + |
| 10 | +Companies run a **private registry** (Artifactory, ktra, a crates.io mirror, …) |
| 11 | +for internal crates, declared per-repo in `.cargo/config.toml`. A pgrx extension |
| 12 | +lives as one submodule/subfolder of a larger monorepo. Cargo resolves |
| 13 | +`.cargo/config.toml` **from the current directory upward**, so building the |
| 14 | +extension from the monorepo root inherits the *parent* config — which does not |
| 15 | +know the private registry — and `cargo pgrx install` dies at its first step, |
| 16 | +`cargo metadata`. `cargo build` lets you fix this with `--config`; this PR gives |
| 17 | +`cargo pgrx install` the same. |
| 18 | + |
| 19 | +## Layout (everything is a real file — nothing is generated inside the script) |
| 20 | + |
| 21 | +``` |
| 22 | +repro/install-config-2135/ |
| 23 | +├── repro.sh # thin orchestrator (build/run/publish/before/after) |
| 24 | +├── registry/ |
| 25 | +│ └── Dockerfile # the private registry image (cargo-http-registry) |
| 26 | +└── files/ |
| 27 | + ├── acme-internal/ # the internal crate, published to the registry |
| 28 | + │ ├── Cargo.toml |
| 29 | + │ ├── src/lib.rs # pub fn secret() -> i32 { 42 } |
| 30 | + │ └── .cargo/config.toml # registry def, for `cargo publish` |
| 31 | + └── monorepo/ |
| 32 | + ├── .cargo/config.toml # PARENT config — does NOT define `acme` |
| 33 | + └── childext/ # the pgrx extension |
| 34 | + ├── Cargo.toml # depends on acme-internal { registry = "acme" } |
| 35 | + ├── childext.control |
| 36 | + ├── src/lib.rs # #[pg_extern] fn acme_secret() -> acme_internal::secret() |
| 37 | + └── .cargo/config.toml # CHILD config — the ONLY place `acme` is defined |
| 38 | +``` |
| 39 | + |
| 40 | +`repro.sh` copies `files/` into a scratch dir (`/tmp/acme-demo`) to build, so the |
| 41 | +nested crates never interfere with the pgrx workspace. |
| 42 | + |
| 43 | +## Run |
| 44 | + |
| 45 | +```bash |
| 46 | +CARGO_PGRX=target/debug/cargo-pgrx \ # the PR build of cargo-pgrx |
| 47 | +PG_CONFIG=$HOME/.pgrx/18.4/pgrx-install/bin/pg_config \ |
| 48 | +PG_PORT=5449 \ # pgrx base_port + major (5431 + 18) |
| 49 | +PGRX_SRC=$PWD \ # your pgrx checkout |
| 50 | +repro/install-config-2135/repro.sh |
| 51 | +``` |
| 52 | + |
| 53 | +Expected: |
| 54 | + |
| 55 | +- **BEFORE** (no `--config`): |
| 56 | + `cargo metadata ... registry index was not found in any configuration: 'acme'` |
| 57 | +- **AFTER** (`--config childext/.cargo/config.toml`): builds + installs. |
| 58 | +- **SQL proof**: `SELECT acme_secret();` → `42`. |
| 59 | + |
| 60 | +Teardown: `docker rm -f acme-registry && rm -rf /tmp/acme-demo` |
| 61 | + |
| 62 | +## Notes / honest caveats |
| 63 | + |
| 64 | +- **`PGRX_BUILD_FLAGS` can't fix this** — it only reaches the build step, never |
| 65 | + the `cargo metadata` call that runs first (and fails first). The PR forwards |
| 66 | + `--config` to every cargo invocation install makes (metadata, rustc, the |
| 67 | + `get_version` metadata, and the schema `cargo run`). |
| 68 | +- **Registry index over `file://`** — `cargo-http-registry`'s HTTP git-index does |
| 69 | + not serve cleanly in every environment (cargo can get HTTP 500), so the index |
| 70 | + is read from the registry's git repo on the shared Docker volume, while publish |
| 71 | + + crate downloads still go over HTTP to the container. What's being demonstrated |
| 72 | + (config resolution / `--config`) is unaffected. |
| 73 | +- **`CARGO_TARGET_DIR` is set** by `repro.sh`: `pgrx-pg-config::get_target_dir()` |
| 74 | + runs its own `cargo metadata --no-deps`, which an undefined registry also breaks |
| 75 | + and which does not yet receive `--config` (gap #4). Setting `CARGO_TARGET_DIR` |
| 76 | + makes it return early, as pgrx/CI usually do. Forwarding `--config` there too is |
| 77 | + a possible follow-up. |
0 commit comments