Skip to content

rust_crate

Resolved third-party Cargo package lowered into a Rust library target.

Description

Represents a sourced package from a resolved Cargo lockfile as a normal Once graph target. rust_crate compiles to an rlib and emits the same rust_crate provider shape consumed by rust_library and rust_binary deps.

Attributes

AttributeTypeRequiredDefaultDescription
package_namestringyesOriginal Cargo package name
versionstringyesResolved Cargo package version
crate_namestringnotarget nameRust crate name passed to rustc; - and . are rewritten as _ when omitted
crate_rootstringnosrc/lib.rsPackage-relative library root
editionstringno2021Rust edition passed to rustc
featureslist<string>no[]Cargo feature names lowered to --cfg=feature=... flags
crate_featureslist<string>no[]Bazel-compatible alias for features
targetstringnohost targetRust target triple passed to rustc --target
envmap<string, string>no{}Environment variables for rustc, matching Buck2's env attribute
rustc_envmap<string, string>no{}Bazel-compatible rustc environment variables
rustc_env_fileslist<string>no[]Files with NAME=value entries merged into the rustc environment before env and rustc_env
rustc_flagslist<string>no[]Additional rustc flags appended after Once-managed flags
cap_lintsstringnoemptyOptional rustc lint cap passed as --cap-lints; generated Cargo dependencies use allow
linkerstringnoemptyOptional linker path passed as -C linker=...; defaults to cc for host Unix binary-like targets and to the Android NDK clang wrapper for Android targets when available
linker_flagslist<string>no[]Additional linker flags lowered to -C link-arg=...
native_linkoptslist<string>no[]Shared Rust compatibility attribute for native-producing Rust target kinds
exported_linker_flagslist<string>no[]Buck-compatible alias for native linker flags propagated to downstream native consumers
exported_post_linker_flagslist<string>no[]Buck-compatible propagated linker flags appended after normal exported linker flags
linker_scriptstringnoemptyPackage-relative linker script passed to the linker and included in the compile action inputs
android_abistringnoinferredAndroid ABI directory for dynamic library outputs, such as arm64-v8a
android_apiintno23Android API level used to select the NDK clang wrapper for Android targets
android_ndkstringnoANDROID_NDK_HOMEAndroid NDK root used to find clang wrapper linkers
datalist<string>no[]Runtime data file globs propagated to downstream Rust binaries and tests
compile_datalist<string>no[]Bazel-compatible compile-time data file globs included in the rustc action inputs
crate_aliasesmap<string, string>no{}Map dependency label, package name, or crate name to the local extern crate name
aliasesmap<string, string>no{}Bazel-compatible alias map from dependency label or crate name to local extern crate name
named_depsmap<string, string>no{}Buck-compatible alias map from local extern crate name to dependency label or crate name
cargo_packagestringnoemptyCargo package name used to select direct external deps from a cargo_dependencies dependency set. Defaults to CARGO_PKG_NAME when present
build_scriptstringnoemptyPackage-relative Cargo build script path run before rustc; common cargo:rustc-* stdout directives are consumed, dependency cargo:rustc-link-search outputs are replayed downstream, and direct dependency links metadata is consumed
sourcestringnoCargo source identifier
checksumstringnoCargo.lock checksum for registry packages

Accepted but unsupported attributes: default_deps, doc_deps, doc_env, doc_link_style, doc_linker_flags, doc_named_deps, link_deps, link_style, mapped_srcs, proc_macro_deps, rpath, runtime_dependency_handling, and rustdoc_flags. Non-empty values fail validation.

Dependency Edges

EdgeAcceptsDescription
depsrust_crate, rust_proc_macro, rust_dependency_setResolved Cargo package dependencies

Providers

The target emits rust_crate.

Capabilities

CapabilityOutput groups
buildrlib

Outputs

OutputLocation
Rust library.once/out/<target>/lib<crate_name>-<metadata>.rlib

Example

toml
[[target]]
name = "itoa-1.0.14"
kind = "rust_crate"
srcs = ["vendor/itoa-1.0.14/src/**/*.rs"]

[target.attrs]
package_name = "itoa"
crate_name = "itoa"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "..."
crate_root = "vendor/itoa-1.0.14/src/lib.rs"
edition = "2021"

Released under an open-source license.