Linux command
cargo-package 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create package archive
cargo package
Package without verification
cargo package --no-verify
List files in package
cargo package --list
Allow uncommitted changes
cargo package --allow-dirty
Package specific workspace member
cargo package -p [crate_name]
说明
cargo package creates a distributable `.crate` archive from the source code. The archive is placed in `target/package/` and contains the source files, a normalized Cargo.toml, and optionally the Cargo.lock file. By default, the package is verified by extracting and building it in a temporary directory. During packaging, the Cargo.toml manifest is normalized: workspace inheritance is resolved, `patch`, `replace`, and `workspace` sections are removed, and path dependencies must include a version key. The `include` and `exclude` fields in Cargo.toml control which files are packaged. This command is equivalent to `cargo publish --dry-run` and is useful for inspecting what would be uploaded to a registry.
参数
- -l, --list
- List files that would be included
- --no-verify
- Skip extraction and build verification
- --allow-dirty
- Allow uncommitted VCS changes
- --no-metadata
- Ignore warnings about missing metadata
- --exclude-lockfile
- Don't include Cargo.lock
- --target _triple_
- Build for target platform (verification)
- -p, --package _spec_
- Package specific workspace member
- --workspace
- Package all workspace members
- -v, --verbose
- Verbose output
FAQ
What is the cargo-package command used for?
cargo package creates a distributable `.crate` archive from the source code. The archive is placed in `target/package/` and contains the source files, a normalized Cargo.toml, and optionally the Cargo.lock file. By default, the package is verified by extracting and building it in a temporary directory. During packaging, the Cargo.toml manifest is normalized: workspace inheritance is resolved, `patch`, `replace`, and `workspace` sections are removed, and path dependencies must include a version key. The `include` and `exclude` fields in Cargo.toml control which files are packaged. This command is equivalent to `cargo publish --dry-run` and is useful for inspecting what would be uploaded to a registry.
How do I run a basic cargo-package example?
Run `cargo package` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -l, --list do in cargo-package?
List files that would be included