--- name: rust-cargo-package-verification description: "Use when a Rust crate builds in its checkout but cargo package fails, compile-time assets are missing, or a release must verify the actual crate archive." category: development risk: critical source: self source_type: self date_added: "2026-12-02" author: ShianMike tags: [rust, cargo, packaging, crates, include-str, release-verification] --- # Rust Cargo Package Verification ## When to Use - `cargo check` succeeds while `cargo package` fails during verification. - A crate embeds a file with `include_str!` or `include_bytes!`, or a build script reads a file in the source tree. - A workspace crate relies on local paths, generated files, or manifest settings and needs a packaging check before release. ## Prerequisites - Record the Cargo and rustc versions, package name, target, and release feature selection. - Identify the crate's manifest, embedded assets, build inputs, and files needed for downstream use. - Prepare a scratch directory for the fixture. The fixture has no registry dependencies. ## 1. Compare checkout inputs with archive contents 1. Inspect `[package].include` and `[package].exclude`, along with files generated or ignored locally. When `include` is set, check the allowlist for each asset the crate consumes. 2. Resolve macro inputs relative to the source file that calls the macro. For `include_str!("../assets/label.txt")` in `src/lib.rs`, verify that `assets/label.txt` is present at the crate root in the archive. 3. Use `cargo package --list` for a quick membership check. For an actual `.crate`, inspect archive members and the bytes of required files. Check that local-only files stayed out of the package. ## 2. Verify the unpacked package 1. Run `cargo package` with verification enabled. Cargo creates the archive, unpacks it, and verifies a build there. `--list` only previews membership. 2. Inspect the normalized `Cargo.toml` in the archive if the crate depends on workspace inheritance, local patches, or path dependencies. Test what a consumer receives using the flags and target used for release. 3. If package verification fails, record the compiler or build-script failure and inspect the actual archive. An archive created with `--no-verify` can support diagnosis. Run package verification normally after fixing the cause. ```powershell cargo package --list --locked cargo package --locked ``` ## 3. Fix the missing input at its source 1. Add the narrowly required file or directory to the packaging rules, or move the build input inside the crate when its current path cannot be shipped. 2. Check patterns on a clean checkout so generated assets are reproduced by the documented build or included deliberately. Review large files, licenses, local configuration, and private data before broadening any pattern. 3. Rebuild, inspect, and test from the unpacked package. Report filename membership, verification status, and the actual consumer or test command. ## Example Run the [offline missing-asset fixture](references/missing-compile-time-asset.md). It shows an ordinary build passing, the archive verification failing, and the packaged crate building and testing after one allowlist change. ## Limitations - The fixture tests a single small crate with no dependencies. Multi-crate publishing order, registry permissions, cross-compilation, and downstream feature combinations require separate validation. - Package verification builds the unpacked package. Use additional commands to exercise runtime behavior or consumer tests as needed. ## Safety and Side Effects - The fixture writes a temporary crate, local archives, and build output. It packages and verifies offline. - A packaging rule can expose generated or local-only files. Inspect the final member list and use the normal release process for any publication. ## Related Skills and Documentation - For workspace layout, see [Systems Programming Rust Project](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/systems-programming-rust-project/SKILL.md). - For parity when porting code to Rust, see [Rust Migration](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/rust-migration/SKILL.md). - See [cargo package](https://doc.rust-lang.org/cargo/commands/cargo-package.html), [manifest include and exclude rules](https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields), and [include_str!](https://doc.rust-lang.org/std/macro.include_str.html).