This release is a pre-release and may not be stable for production use.
pants-backend-cargo
A Pants backend for Rust that wraps Cargo rather than replacing it: Cargo keeps its package model, its lockfiles and its workspaces, and Pants adds target addresses, caching, a hermetic toolchain and the usual goals on top.
This release targets Pants 2.32.x. Install it with pants-backend-cargo==0.1.0rc0 in
[GLOBAL].plugins in pants.toml, and enable pants_backend_cargo in
[GLOBAL].backend_packages.
Status: alpha. No stability guarantees until it nears feature completeness.
Targets
-
cargo_workspace: the root of a Cargo workspace:Cargo.toml,Cargo.lock,rust-toolchain.tomland.cargo/config.toml. Members are found through the manifest'smembers(globs one path segment at a time, lessexclude) and depend on it. Test executables and clippy run once per workspace. Members cannot inherit from the workspace (version.workspace = true,b = { workspace = true }): a package's targets are generated from its own manifest alone. -
cargo_package: a package.cargo metadataon its manifest generatespath:name#package(cargo_package_impl): the sources and cargo dependencies, whatfmtandlintact on;path:name#library(cargo_library), onecargo_binaryper[[bin]]named after it, onecargo_testper[[test]]: whattestruns, and for binaries whatpackageandrunbuild.
dependenciesaddsfiles/resourcestargets the build reads (include_str!, build script inputs) and packageable targets of other backends whosepackageoutput the build needs: they are built and staged in the sandbox at their package path forpackage,run,testandlint(not forfmtandgenerate-lockfiles). Their own dependencies are their backend's inputs and are not staged.envsetsKEY=VALUEentries for every cargo process whose sandbox holds the package (its own, those of packages depending on it, and the per-workspacetestbuild,fmtandlint), and for the test executables andrunbinaries those build;{chroot}is the sandbox root, soenv=["MYLIB_DIR={chroot}/build"]points a build script at a staged library.PATH,CARGO,CARGO_HOME,CARGO_TARGET_DIR,CARGO_INCREMENTAL,RUSTUP_HOME,RUSTUP_TOOLCHAIN,RUSTC_WRAPPER,RUSTFLAGS,KACHE_*and the toolchain'sCARGO_TARGET_<TRIPLE>_LINKER,CC_<triple>,CXX_<triple>andAR_<triple>are the backend's and rejected.skip_testsas usual;output_pathis the directory underdist/(defaultpath.to.target/), the file keeps the binary's name. A target withtest = falseinCargo.tomlgetsskip_tests. A[[bin]]or[[test]]namedpackageorlibrary, or a bin and a test of the same name, is an error: rename it.
path dependencies between packages are inferred. pants tailor adds both target types.
Pants reads nothing .gitignore ignores, so a workspace's .cargo/config.toml must not be
(!/.cargo/ after a .cargo rule).
Toolchain
Nothing from the host's ~/.rustup or ~/.cargo is used. [rustup] pins rustup-init, which
installs the toolchain into a named cache shared by every sandbox. The version is
[rustup].rust_version or, unset, the channel of the rust-toolchain.toml at the build
root, and must be exact: it is part of every cache key. The components the file lists are
installed with it; fmt and lint add rustfmt and clippy.
Every cargo process runs in a fresh sandbox with its own target/, so cargo's own incremental
state never carries over. Instead, [kache] puts kache
in front of rustc: compiled crates are keyed by their inputs and kept in a named cache, and
unchanged crates are restored rather than rebuilt, across sandboxes and across packages of a
workspace. Local only, no daemon. --remap-path-prefix maps the sandbox root to a fixed
prefix so rustc's output does not depend on the sandbox path; this sets RUSTFLAGS, so a
build.rustflags in .cargo/config.toml is not read. Its [target.<triple>] linker is only
for plain cargo: under Pants the platform's cc_toolchain links (see Platforms).
Platforms
The backend builds for the platform targets of
pants-backend-platforms. A cargo_package's
platforms field lists what its binaries can be built for, the host alone when unset; pants package builds those that are the host or in [platforms].enabled, the host's binary at its
usual path and every other under dist/<platform>/, with .exe for Windows.
platform(name="windows-x86_64", os="windows", arch="x86_64") # builds as x86_64-pc-windows-gnu
cargo_package(platforms=["linux-x86_64", "windows-x86_64"])
- A
platformbuilds as itsrust_target, by default the triple of itsosandarch(x86_64-unknown-linux-gnu,aarch64-unknown-linux-gnu,x86_64-pc-windows-gnu,aarch64-apple-darwin,x86_64-apple-darwin). Every enabled platform's target is installed with the toolchain. Another platform's build passes--target; the host's does not. - The platform's
cc_toolchain(pants-backend-cc) links the binary and is cc-rs's compiler for that triple, host included; a cross build also gets the host's for its build scripts and proc macros. - A packageable dependency of another backend that builds for platforms (a
cmake_target) is built for the same platform, and must list it in its ownplatforms. Cargo packages that a binary depends on need noplatformsof their own. run,test,fmt,lintandgenerate-lockfilesbuild for the host only;testandlintdo not pass--target, even for a host whoserust_targetis not the machine's.
Goals
package:cargo build --locked --bin <name>(--releasewith[rust].release), the binary atdist/<path.to.target>/<name>or underoutput_path.run: the packaged binary, with thefiles,resourcesand staged packages of its closure, but not its cargo sources.test: onecargo test --no-run --workspaceper workspace (or per package outside any), then one process per test executable, so eachcargo_library,cargo_binaryandcargo_testis its own cached test result. Doctests are not run. The executables run from the package directory with the sources at hand andCARGO_MANIFEST_DIRset to it, ascargo testdoes, but a path compiled in throughenv!("CARGO_MANIFEST_DIR")orenv!("CARGO_BIN_EXE_<name>")names the build sandbox, which is gone when the test runs: readCARGO_MANIFEST_DIRwithstd::env::varinstead. A target cargo builds no executable for (itsrequired-featuresare off) is skipped with a warning.fmt/lint:cargo fmt([rust].skip) and, withpants_backend_cargo.backends.clippy,cargo clippy([clippy].args,[clippy].skip), once per workspace.generate-lockfiles:cargo update, never cached across runs; the resolve names are the workspace and package addresses (pants generate-lockfiles --resolve=path:name#package), and a member's name updates its workspace'sCargo.lock.
Setup
Install pants-backend-cargo in [GLOBAL].plugins in pants.toml, and enable it:
[GLOBAL]
backend_packages = [
"pants_backend_cargo",
"pants_backend_cargo.backends.clippy",
]
[rustup]
rust_version = "1.97.0" # or a rust-toolchain.toml at the build root
[clippy]
args = ["--", "-Dwarnings"]
[kache]
enabled = true # the default; false runs rustc bare
Linux and macOS. With no cc_toolchain targets, the host's gcc, g++ and ar link.
Declaring platform and cc_toolchain targets needs pants_backend_platforms and
pants_backend_cc in backend_packages as well; pants-backend-cargo installs both.
License
MIT (LICENSE-MIT.txt).
Metadata
Release files for pants-backend-cargo 0.1.0rc0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pants_backend_cargo-0.1.0rc0.tar.gz | 32.1 kB | Without provenance | Details for pants_backend_cargo-0.1.0rc0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pants_backend_cargo-0.1.0rc0-py3-none-any.whl | Python 3 | none | any | Details for pants_backend_cargo-0.1.0rc0-py3-none-any.whl |
Total release size: 74.3 kB
Release files / pants_backend_cargo-0.1.0rc0.tar.gz
| Download URL | pants_backend_cargo-0.1.0rc0.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8eae5afc123f1214c73f7eb413e9afb3e53160af921c60b9e7d2f83e698cd170
|
|
BLAKE2b-256 checksum How to use checksums |
2fa479035fbceafea1353551e8296548dac820e0e912ff805a5c5a29926a6fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / pants_backend_cargo-0.1.0rc0-py3-none-any.whl
| Download URL | pants_backend_cargo-0.1.0rc0-py3-none-any.whl |
|---|---|
| Size | 42.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96096ca0cfa235f18dac8cebfa8d6491e6f2dd8d5425bb091ace2337a59e4157
|
|
BLAKE2b-256 checksum How to use checksums |
3c344f4972e4507e5d1c7e5a8bb950b0b97d5c81f3b13f0c3d99ccfac2ed4113
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for pants-backend-cargo 0.1.0rc0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.