
Tracking issue: https://github.com/rust-lang/cargo/issues/9096
Original PR: https://github.com/rust-lang/cargo/pull/9992
Add 'bindeps' -Z flag for later use
A test to validate artifact dependencies aren't currently parsed.
Parse 'artifact' and 'lib' fields.
Note that this isn't behind a feature toggle so 'unused' messages will
disappear.
Transfer artifact dependencies from toml- into manifest-dependencies
There are a few premises governing the operation.
- if unstable features are not set, warn when 'artifact' or 'lib' is
encountered.
- bail if 'lib' is encountered alone, but warn that this WOULD happen
with nightly.
- artifact parsing checks for all invariants, but some aren't tested.
Assure serialization of 'artifact' and 'lib' fields produces suitable values during publishing
This should be the only place were these fields matter and where a cargo
manifest is actually produced. These are only for internal use, no user
is typically going to see or edit them.
Place all artifact dependency tests inta their own module
This facilitates deduplication later and possibly redistribution into
other modules if there is a better fit.
Represent artifacts that are rust libraries as another ArtifactKind
This is more consistent and probably simpler for later use.
No need to reflect the TOML data structure.
Add tests to assure only 'lib = true' artifact deps are documented
RFC-3028 doesn't talk about documentation, but for lib=true it's clear
what the desired behaviour should be.
If an artifact isn't a library though, then for now, it's transparent,
maybe.
Many more tests, more documentation, mild `Artifact` refactor
The latter seems to be a better fit for what being an artifact
really means within cargo, as it literally turns being a library
on or off, and thus only optionally becoming a normal library.
refactor to prepare for artifact related checks
Don't show a no-lib warning for artifact dependencies (with lib = false)
Tests for more artifact dependency invariants
These are merely a proof of concept to show that we are not in
a position to actually figure out everything about artifacts
right after resolution.
However, the error message looks more like a fatal error and less
like something that can happen with a more elaborate error message
with causes.
This might show that these kind of checks might be better done later
right before trying to use the information for create compile units.
Validate that artifact deps with lib=true still trigger no-lib warnings
This triggers the same warning as before, for now without any
customization to indicate it's an artifact dependency.
Use warnings instead of errors
------------------------------
This avoids the kind of harsh end of compilation in favor of something
that can be recovered from. Since warnings are annoying, users will
probably avoid re-declaring artifact dependencies.
Hook in artifact dependencies into build script runs
Even though we would still have to see what happens if they have a lib
as well. Is it built twice?
Also
----
- fly-by refactor: fix typo; use ? in method returning option
- Propagate artifact information into Units; put artifacts into place
This means artifacts now have their own place in the 'artifact'
directory and uplifts won't happen for them.
- refactor and fix cippy suggestion
- fix build after rebasing onto master
Create directories when executing the job, and not when preparing it.
also: Get CI to work on windows the easy way, for now.
Set directories for artifact dependencies in build script runtimes
Test remaining kinds of build-script runtime environment variables
Also
----
- Fix windows tests, the quick way.
- Try to fix windows assertions, and generalize them
- Fix second test for windows, hopefully
test for available library dependency in build scripts with lib = true
probably generally exclude all artifact dependencies with lib=false.
Pass renamed dep names along with unit deps to allow proper artifact env names
Test for selective bin:<name> syntax, as well as binaries with dashes
Test to assure dependency names are transformed correctly
assure advertised binaries and directories are actually present
This wouldn't be the case if dependencies are not setup correctly,
for instance.
Also
----
- make it easier to see actual values even on failure
This should help figure out why on CI something fails that works
locally no matter what.
Turns out this is a race condition, with my machine being on the good
side of it so it doesn't show in testing. Fortunately it still can be
reproduced and easily tested for.
- refactor test; the race condition is still present though
- Force CI to pass here by avoiding checks triggering race.
- Fix windows build, maybe?
More tolerant is_file() checks to account for delay on CI
This _should_ help CI to test for the presence which is better than
not testing at all.
This appears to be needed as the output file isn't ready/present in time
for some reason.
The root cause of this issue is unknown, but it's definitely a race
as it rarely happens locally. When it happened, the file was always
present after the run.
Now we will learn if it is truly not present, ever, or if it's maybe
something very else.
Validate libs also don't see artifact dependencies as libraries with lib=false
Also
----
- Add prelimiary test for validating build-time artifacts
- Try to fix CI on gnu windows
Which apparently generates paths similar to linux, but with .exe suffix.
The current linux patterns should match that.
- refactor
Help sharing code across modules
allow rustc to use artifact dep environment variables, but…
…it needs some adjustments to actually setup the unit dependency graph
with artifacts as well.
Right now it will only setup dependencies for artifacts that are libs,
but not the artifacts themselves, completely ignoring them when they
are not libs.
Make artifact dependencies available in main loop
This is the commit message #2:
------------------------------
rough cut of support for artifact dependencies at build time…
…which unfortunately already shows that the binary it is supposed to
include is reproducibly not ready in time even though the path is
correct and it's present right after the run.
Could it be related to rmeta?
This is the commit message #3:
------------------------------
Fix test expectations as failure is typical than the warning we had before…
…and add some tolerance to existing test to avoid occasional failures.
This doesn't change the issue that it also doens't work at all for
libraries, which is nicely reproducable and hopefully helps to fix
this issue.
This is the commit message #4:
------------------------------
Probably the fix for the dependency issue in the scheduler
This means that bin() targets are now properly added to the job graph
to cause proper syncing, whereas previously apparently it would
still schedule binaries, but somehow consider them rmeta and thus
start their dependents too early, leading to races.
This is the commit message #5:
------------------------------
Don't accidentally include non-gnu windows tests in gnu windows.
Support cargo doc and cargo check
The major changes here are…
- always compile artifacts in build mode, as we literally want the
build output, always, which the dependent might rely on being present.
- share code between the rather similar looking paths for rustdoc and
rustc.
Make artifact messages appear more in line with cargo by using backticks
Also: Add first test for static lib support in build scripts
build-scripts with support for cdylib and staticlib
- Fix windows msvc build
No need to speculate why the staticlib has hashes in the name even
though nothing else.
staticlib and cdylib support for libraries
test staticlib and cdylibs for rustdoc as well.
Also catch a seemingly untested special case/warning about the lack
of linkable items, which probably shouldn't be an issue for artifacts
as they are not linkable in the traditional sense.
more useful test for 'cargo check'
`cargo check` isn't used very consistently in tests, so when we use it
we should be sure to actually try to use an artifact based feature
to gain some coverage.
verify that multiple versions are allowed for artifact deps as well.
also: remove redundant test
This is the commit message #2:
------------------------------
Properly choose which dependencies take part in artifact handling
Previously it would include them very generously without considering
the compatible dependency types.
This is the commit message #3:
------------------------------
a more complex test which includes dev-dependencies
It also shows that doc-tests don't yet work as rustdoc is run outside of
the system into which we integrate right now.
It should be possible to write our environment variable configuration
in terms of this 'finished compilation' though, hopefully with
most code reused.
This is the commit message #4:
------------------------------
A first stab at storing artifact environment variables for packages…
…however, it seems like the key for this isn't necessarily correct
under all circumstances. Maybe it should be something more specific,
don't know.
This is the commit message #5:
------------------------------
Adjust key for identifying units to Metadata
This one is actually unique and feels much better.
This is the commit message #6:
------------------------------
Attempt to make use of artifact environment information…
…but fail as the metadata won't match as the doctest unit is, of course,
its separate unit. Now I wonder if its possible to find the artifact
units in question that have the metadata.
Properly use metadata to use artifact environment variables in doctests
This is the commit message #2:
------------------------------
Add test for resolver = "2" and build dependencies
Interestingly the 'host-features' flag must be set (as is seemingly
documented in the flags documentation as well), even though I am not
quite sure if this is the 100% correct solution. Should it rather
have an entry with this flag being false in its map? Probably not…
but I am not quite certain.
This is the commit message #3:
------------------------------
set most if not all tests to use resolver = "2"
This allows to keep it working with the most recent version while
allowing to quickly test with "1" as well (which thus far was working
fine).
All tests I could imagine (excluding target and profiles) are working now
Crossplatform tests now run on architecture aarm64 as well.
More stringent negative testing
Fix incorrect handling of dependency directory computation
Previously it would just 'hack' the deps-dir to become something very
different for artifacts.
This could easily be fixed by putting the logic for artifact output
directories into the right spot.
A test for cargo-tree to indicate artifacts aren't handled specifically
Assure build-scripts can't access artifacts at build time
Actual doc-tests with access to artifact env vars
All relevant parsing of `target = [..]`
Next step is to actually take it into consideration.
A failing test for adjusting the target for build script artifacts using --target
Check for unknown artifact target triple in a place that exists for a year
The first test showing that `target="target"` deps seemingly work
For now only tested for build scripts, but it won't be much different
for non-build dependencies.
build scripts accept custom targets unconditionally
Support target setting for non-build dependencies
This is the commit message #2:
------------------------------
Add doc-test cross compile related test
Even though there is no artifact code specific to doc testing, it's
worth to try testing it with different target settings to validate
it still works despite doc tests having some special caseing around
target settings.
This is the commit message #3:
------------------------------
A test to validate profiles work as expected for build-deps and non-build deps
No change is required to make this work and artifact dependencies 'just work'
based on the typical rules of their non-artifact counterarts.
This is the commit message #4:
------------------------------
Adjust `cargo metadata` to deal with artifact dependencies
This commit was squashed and there is probably more that changed.
This is the commit message #5:
------------------------------
Show bin-only artifacts in "resolve" of metadata as well.
This is the commit message #6:
------------------------------
minor refactoring during research for RFC-3176
This will soon need to return multiple extern-name/dep-name pairs.
This is the commit message #7:
------------------------------
See if opt-level 3 works on win-msvc in basic profile test for artifacts
This is the same value as is used in the other test of the same name,
which certainly runs on windows.
This is the commit message #8:
------------------------------
refactor
Assure the type for targets reflect that they cannot be the host target,
which removes a few unreachable!() expressions.
Put `root_unit_compile_kind` into `UnitFor`
Previously that wasn't done because of the unused `all_values()`
method which has now been deleted as its not being used anyomre.
This allows for the root unit compile kind to be passed as originally
intended, instead of working around the previous lack of extendability
of UnitFor due to ::all_values().
This is also the basis for better/correct feature handling once
feature resolution can be depending on the artifact target as well,
resulting in another extension to UnitFor for that matter.
Also
----
- Fix ordering
Previously the re-created target_mode was used due to the reordering
in code, and who knows what kind of effects that might have
(despite the test suite being OK with it).
Let's put it back in place.
- Deactivate test with filename collision on MSVC until RFC-3176 lands
Avoid clashes with binaries called 'artifact' by putting 'artifact/' into './deps/'
This commit addresses review comment https://github.com/rust-lang/cargo/pull/9992#discussion_r772939834
Don't rely on operator precedence for boolean operations
Now it should be clear that no matter what the first term is,
if the unit is an artifact, we should enqueue it.
Replace boolean and `/*artifact*/ <bool>` with `IsArtifact::(Yes/No)`
fix `doc::doc_lib_false()` test
It broke due to major breakage in the way dependencies are calculated.
Now we differentiate between deps computation for docs and for building.
Avoid testing for doctest cross-compilation message
It seems to be present on my machine, but isn't on linux and it's
probably better to leave it out entirely and focus on the portions
of consecutive output that we want to see at least.
A test to validate features are unified across libraries and those in artifact deps in the same target
Allow aarch64 MacOS to crosscompile to an easily executable alternative target
That way more tests can run locally.
Support for feature resolution per target
The implementation is taken directly from RFC-3176 and notably lacks
the 'multidep' part.
Doing this definitely has the benefit of making entirely clear
'what is what' and helps to greatly reduce the scope of RFC-3176
when it's rebuilt based on the latest RF-3028, what we are implementing
right now.
Also
----
- A test which prooves that artifact deps with different target don't have a feature namespace yet
- Add a test to validate features are namespaced by target
Previously it didn't work because it relies on resolver = "2".
- 'cargo metadata' test to see how artifact-deps are presented
- Missed an opportunity for using the newly introduced `PackageFeaturesKey`
- Use a HashMap to store name->value relations for artifact environment variables
This is semantically closer to what's intended.
also: Remove a by now misleading comment
Prevent resolver crash if `target = "target"` is encountered in non-build dependencies
A warning was emitted before, now we also apply a fix.
Previously the test didn't fail as it accidentally used the old
resolver, which now has been removed.
Abort in parsing stage if nightly flag is not set and 'artifact' is used
There is no good reason to delay errors to a later stage when code
tries to use artifacts via environment variables which are not present.
Change wording of warning message into what's expected for an error message
remove unnecessary `Result` in `collect()` call
Improve logic to warn if dependencie are ignored due to missing libraries
The improvement here is to trigger correctly if any dependency of a
crate is potentially a library, without having an actual library target
as part of the package specification.
Due to artifact dependencies it's also possible to have a dependency
to the same crate of the same version, hence the package name
isn't necessarily a unique name anymore. Now the name of the actual
dependency in the toml file is used to alleviate this.
Various small changes for readability and consistency
A failing test to validate artifacts work in published crates as well
Originally this should have been a test to see target acquisition works
but this more pressing issue surfaced instead.
Make artifacts known to the registry data (backwards compatible)
Now artifacts are serialized into the registry on publish (at least
if this code is actually used in the real crates-io registry) which
allows the resolve stage to contain artifact information.
This seems to be in line with the idea to provide cargo with all
information it needs to do package resolution without downloading
the actual manifest.
Pick up all artifact targets into target info once resolve data is available
Even though this works in the test at hand, it clearly shows there
is a cyclic dependency between the resolve and the target data.
In theory, one would have to repeat resolution until it settles
while avoiding cycles.
Maybe there is a better way.
Add `bindeps`/artifact dependencies to `unstsable.md` with examples
Fix tests
Various small improvements
Greatly simplify artifact environment propagation to commands
Remove all adjustments to cargo-metadata, but leave tests
The tests are to record the status quo with the current code
when artifact dependencies are present and assure the information
is not entirely non-sensical.
Revert "Make artifacts known to the registry data (backwards compatible)"
This reverts commit adc5f8ad04840af9fd06c964cfcdffb8c30769b0.
Ideally we are able to make it work without altering the registry
storage format. This could work if information from the package
set is added to the resolve information.
Enrich resolves information with additional information from downloaded manifests
Resolve information comes from the registry, and it's only as rich as
needed to know which packages take part in the build.
Artifacts, however, don't influence dependency resolution, hence it
shouldn't be part of it.
For artifact information being present nonetheless when it matters,
we port it back to the resolve graph where it will be needed later.
Collect 'forced-target' information from non-workspace members as well
This is needed as these targets aren't present in the registry and
thus can't be picked up by traversing non-workspce members.
The mechanism used to pick up artifact targets can also be used
to pick up these targets.
Remove unnecessary adjustment of doc test
refactor `State::deps()` to have filter; re-enable accidentally disabled test
The initial rebasing started out with a separted `deps_filtered()`
method to retain the original capabilities while minimizing the chance
for surprises. It turned out that the all changes combined in this PR
make heavy use of filtering capabilities to the point where
`deps(<without filter>)` was unused. This suggested that it's required
to keep it as is without a way to inline portions of it.
For the original change that triggered this rebase, see
bd45ac81ba062a7daa3b0178dfcb6fd5759a943c
The fix originally made was reapplied by allowing to re-use the
required filter, but without inlining it.
Always error on invalid artifact setup, with or without enabled bindeps feature
Clarify how critical resolver code around artifact is working
Remove workaround in favor of deferring a proper implementation
See https://github.com/rust-lang/cargo/pull/9992#issuecomment-1033394197
for reference and the TODO in the ignored test for more information.
truncate comments at 80-90c; cleanup
- remove unused method
- remove '-Z unstable-options'
- improve error message
- improve the way MSVC special cases are targetted in tests
- improve how executables are found on non MSVC
Avoid depending on output of rustc
There is cyclic dependency between rustc and cargo which makes it
impossible to adjust cargo's expectations on rustc without leaving
broken commits in rustc and cargo.
Add missing documentation
fix incorrect removal of non-artifact libs
This is also the first step towards cleaning up the filtering logic
which is still making some logic harder to understand than needs be.
The goal is to get it to be closer to what's currently on master.
Another test was added to have more safety regarding the overall
library inclusion logic.
inline `build_artifact_requirements_to_units()`
Simplify filtering
This adds a default filter to `state.deps(…)` making it similar to
what's currently in master, while creating another version of it
to allow setting a custom filter. This is needed as the default filter
won't allow build dependencies, which we need in this particular case.
`calc_artifact_deps(…)` now hard-codes the default filter which is
needed due to the use of `any` here:
c0e6abe384/src/cargo/core/compiler/unit_dependencies.rs (L1119)
.
Simplify filtering.
49 KiB
Unstable Features
Experimental Cargo features are only available on the nightly channel. You are encouraged to experiment with these features to see if they meet your needs, and if there are any issues or problems. Check the linked tracking issues listed below for more information on the feature, and click the GitHub subscribe button if you want future updates.
After some period of time, if the feature does not have any major concerns, it can be stabilized, which will make it available on stable once the current nightly release reaches the stable channel (anywhere from 6 to 12 weeks).
There are three different ways that unstable features can be enabled based on how the feature works:
-
New syntax in
Cargo.toml
requires acargo-features
key at the top ofCargo.toml
, before any tables. For example:# This specifies which new Cargo.toml features are enabled. cargo-features = ["test-dummy-unstable"] [package] name = "my-package" version = "0.1.0" im-a-teapot = true # This is a new option enabled by test-dummy-unstable.
-
New command-line flags, options, and subcommands require the
-Z unstable-options
CLI option to also be included. For example, the new--out-dir
option is only available on nightly:cargo +nightly build --out-dir=out -Z unstable-options
-
-Z
command-line flags are used to enable new functionality that may not have an interface, or the interface has not yet been designed, or for more complex features that affect multiple parts of Cargo. For example, the mtime-on-use feature can be enabled with:cargo +nightly build -Z mtime-on-use
Run
cargo -Z help
to see a list of flags available.Anything which can be configured with a
-Z
flag can also be set in the cargo config file (.cargo/config.toml
) in theunstable
table. For example:[unstable] mtime-on-use = true multitarget = true
Each new feature described below should explain how to use it.
List of unstable features
- Unstable-specific features
- -Z allow-features — Provides a way to restrict which unstable features are used.
- Build scripts and linking
- Metabuild — Provides declarative build scripts.
- Resolver and features
- no-index-update — Prevents cargo from updating the index cache.
- avoid-dev-deps — Prevents the resolver from including dev-dependencies during resolution.
- minimal-versions — Forces the resolver to use the lowest compatible version instead of the highest.
- public-dependency — Allows dependencies to be classified as either public or private.
- Output behavior
- out-dir — Adds a directory where artifacts are copied to.
- terminal-width — Tells rustc the width of the terminal so that long diagnostic messages can be truncated to be more readable.
- Different binary name — Assign a name to the built binary that is seperate from the crate name.
- Compile behavior
- mtime-on-use — Updates the last-modified timestamp on every dependency every time it is used, to provide a mechanism to delete unused artifacts.
- doctest-xcompile — Supports running doctests with the
--target
flag. - multitarget — Supports building for multiple targets at the same time.
- build-std — Builds the standard library instead of using pre-built binaries.
- build-std-features — Sets features to use with the standard library.
- binary-dep-depinfo — Causes the dep-info file to track binary dependencies.
- panic-abort-tests — Allows running tests with the "abort" panic strategy.
- crate-type - Supports passing crate types to the compiler.
- rustdoc
doctest-in-workspace
— Fixes workspace-relative paths when running doctests.- rustdoc-map — Provides mappings for documentation to link to external sites like docs.rs.
Cargo.toml
extensions- Profile
strip
option — Forces the removal of debug information and symbols from executables. - Profile
rustflags
option — Passed directly to rustc. - per-package-target — Sets the
--target
to use for each individual package. - artifact dependencies - Allow build artifacts to be included into other build artifacts and build them for different targets.
- Profile
- Information and metadata
- Build-plan — Emits JSON information on which commands will be run.
- unit-graph — Emits JSON for Cargo's internal graph structure.
cargo rustc --print
— Calls rustc with--print
to display information from rustc.
- Configuration
- config-cli — Adds the ability to pass configuration options on the command-line.
- config-include — Adds the ability for config files to include other files.
cargo config
— Adds a new subcommand for viewing config files.
- Registries
- credential-process — Adds support for fetching registry tokens from an external authentication program.
cargo logout
— Adds thelogout
command to remove the currently saved registry token.
allow-features
This permanently-unstable flag makes it so that only a listed set of
unstable features can be used. Specifically, if you pass
-Zallow-features=foo,bar
, you'll continue to be able to pass -Zfoo
and -Zbar
to cargo
, but you will be unable to pass -Zbaz
. You can
pass an empty string (-Zallow-features=
) to disallow all unstable
features.
-Zallow-features
also restricts which unstable features can be passed
to the cargo-features
entry in Cargo.toml
. If, for example, you want
to allow
cargo-features = ["test-dummy-unstable"]
where test-dummy-unstable
is unstable, that features would also be
disallowed by -Zallow-features=
, and allowed with
-Zallow-features=test-dummy-unstable
.
The list of features passed to cargo's -Zallow-features
is also passed
to any Rust tools that cargo ends up calling (like rustc
or
rustdoc
). Thus, if you run cargo -Zallow-features=
, no unstable
Cargo or Rust features can be used.
no-index-update
The -Z no-index-update
flag ensures that Cargo does not attempt to update
the registry index. This is intended for tools such as Crater that issue many
Cargo commands, and you want to avoid the network latency for updating the
index each time.
mtime-on-use
The -Z mtime-on-use
flag is an experiment to have Cargo update the mtime of
used files to make it easier for tools like cargo-sweep to detect which files
are stale. For many workflows this needs to be set on all invocations of cargo.
To make this more practical setting the unstable.mtime_on_use
flag in .cargo/config.toml
or the corresponding ENV variable will apply the -Z mtime-on-use
to all
invocations of nightly cargo. (the config flag is ignored by stable)
avoid-dev-deps
When running commands such as cargo install
or cargo build
, Cargo
currently requires dev-dependencies to be downloaded, even if they are not
used. The -Z avoid-dev-deps
flag allows Cargo to avoid downloading
dev-dependencies if they are not needed. The Cargo.lock
file will not be
generated if dev-dependencies are skipped.
minimal-versions
Note: It is not recommended to use this feature. Because it enforces minimal versions for all transitive dependencies, its usefulness is limited since not all external dependencies declare proper lower version bounds. It is intended that it will be changed in the future to only enforce minimal versions for direct dependencies.
When a Cargo.lock
file is generated, the -Z minimal-versions
flag will
resolve the dependencies to the minimum SemVer version that will satisfy the
requirements (instead of the greatest version).
The intended use-case of this flag is to check, during continuous integration,
that the versions specified in Cargo.toml are a correct reflection of the
minimum versions that you are actually using. That is, if Cargo.toml says
foo = "1.0.0"
that you don't accidentally depend on features added only in
foo 1.5.0
.
out-dir
This feature allows you to specify the directory where artifacts will be
copied to after they are built. Typically artifacts are only written to the
target/release
or target/debug
directories. However, determining the
exact filename can be tricky since you need to parse JSON output. The
--out-dir
flag makes it easier to predictably access the artifacts. Note
that the artifacts are copied, so the originals are still in the target
directory. Example:
cargo +nightly build --out-dir=out -Z unstable-options
This can also be specified in .cargo/config.toml
files.
[build]
out-dir = "out"
doctest-xcompile
This flag changes cargo test
's behavior when handling doctests when
a target is passed. Currently, if a target is passed that is different
from the host cargo will simply skip testing doctests. If this flag is
present, cargo will continue as normal, passing the tests to doctest,
while also passing it a --target
option, as well as enabling
-Zunstable-features --enable-per-target-ignores
and passing along
information from .cargo/config.toml
. See the rustc issue for more information.
cargo test --target foo -Zdoctest-xcompile
multitarget
- Tracking Issue: #8176
This flag allows passing multiple --target
flags to the cargo
subcommand
selected. When multiple --target
flags are passed the selected build targets
will be built for each of the selected architectures.
For example to compile a library for both 32 and 64-bit:
cargo build --target x86_64-unknown-linux-gnu --target i686-unknown-linux-gnu
or running tests for both targets:
cargo test --target x86_64-unknown-linux-gnu --target i686-unknown-linux-gnu
New dir-name
attribute
Some of the paths generated under target/
have resulted in a de-facto "build
protocol", where cargo
is invoked as a part of a larger project build. So, to
preserve the existing behavior, there is also a new attribute dir-name
, which
when left unspecified, defaults to the name of the profile. For example:
[profile.release-lto]
inherits = "release"
dir-name = "lto" # Emits to target/lto instead of target/release-lto
lto = true
Build-plan
- Tracking Issue: #5579
The --build-plan
argument for the build
command will output JSON with
information about which commands would be run without actually executing
anything. This can be useful when integrating with another build tool.
Example:
cargo +nightly build --build-plan -Z unstable-options
Metabuild
- Tracking Issue: rust-lang/rust#49803
- RFC: #2196
Metabuild is a feature to have declarative build scripts. Instead of writing
a build.rs
script, you specify a list of build dependencies in the
metabuild
key in Cargo.toml
. A build script is automatically generated
that runs each build dependency in order. Metabuild packages can then read
metadata from Cargo.toml
to specify their behavior.
Include cargo-features
at the top of Cargo.toml
, a metabuild
key in the
package
, list the dependencies in build-dependencies
, and add any metadata
that the metabuild packages require under package.metadata
. Example:
cargo-features = ["metabuild"]
[package]
name = "mypackage"
version = "0.0.1"
metabuild = ["foo", "bar"]
[build-dependencies]
foo = "1.0"
bar = "1.0"
[package.metadata.foo]
extra-info = "qwerty"
Metabuild packages should have a public function called metabuild
that
performs the same actions as a regular build.rs
script would perform.
public-dependency
- Tracking Issue: #44663
The 'public-dependency' feature allows marking dependencies as 'public' or 'private'. When this feature is enabled, additional information is passed to rustc to allow the 'exported_private_dependencies' lint to function properly.
This requires the appropriate key to be set in cargo-features
:
cargo-features = ["public-dependency"]
[dependencies]
my_dep = { version = "1.2.3", public = true }
private_dep = "2.0.0" # Will be 'private' by default
build-std
- Tracking Repository: https://github.com/rust-lang/wg-cargo-std-aware
The build-std
feature enables Cargo to compile the standard library itself as
part of a crate graph compilation. This feature has also historically been known
as "std-aware Cargo". This feature is still in very early stages of development,
and is also a possible massive feature addition to Cargo. This is a very large
feature to document, even in the minimal form that it exists in today, so if
you're curious to stay up to date you'll want to follow the tracking
repository and its set of
issues.
The functionality implemented today is behind a flag called -Z build-std
. This
flag indicates that Cargo should compile the standard library from source code
using the same profile as the main build itself. Note that for this to work you
need to have the source code for the standard library available, and at this
time the only supported method of doing so is to add the rust-src
rust rustup
component:
$ rustup component add rust-src --toolchain nightly
It is also required today that the -Z build-std
flag is combined with the
--target
flag. Note that you're not forced to do a cross compilation, you're
just forced to pass --target
in one form or another.
Usage looks like:
$ cargo new foo
$ cd foo
$ cargo +nightly run -Z build-std --target x86_64-unknown-linux-gnu
Compiling core v0.0.0 (...)
...
Compiling foo v0.1.0 (...)
Finished dev [unoptimized + debuginfo] target(s) in 21.00s
Running `target/x86_64-unknown-linux-gnu/debug/foo`
Hello, world!
Here we recompiled the standard library in debug mode with debug assertions
(like src/main.rs
is compiled) and everything was linked together at the end.
Using -Z build-std
will implicitly compile the stable crates core
, std
,
alloc
, and proc_macro
. If you're using cargo test
it will also compile the
test
crate. If you're working with an environment which does not support some
of these crates, then you can pass an argument to -Zbuild-std
as well:
$ cargo +nightly build -Z build-std=core,alloc
The value here is a comma-separated list of standard library crates to build.
Requirements
As a summary, a list of requirements today to use -Z build-std
are:
- You must install libstd's source code through
rustup component add rust-src
- You must pass
--target
- You must use both a nightly Cargo and a nightly rustc
- The
-Z build-std
flag must be passed to allcargo
invocations.
Reporting bugs and helping out
The -Z build-std
feature is in the very early stages of development! This
feature for Cargo has an extremely long history and is very large in scope, and
this is just the beginning. If you'd like to report bugs please either report
them to:
- Cargo - https://github.com/rust-lang/cargo/issues/new - for implementation bugs
- The tracking repository - https://github.com/rust-lang/wg-cargo-std-aware/issues/new - for larger design questions.
Also if you'd like to see a feature that's not yet implemented and/or if something doesn't quite work the way you'd like it to, feel free to check out the issue tracker of the tracking repository, and if it's not there please file a new issue!
build-std-features
- Tracking Repository: https://github.com/rust-lang/wg-cargo-std-aware
This flag is a sibling to the -Zbuild-std
feature flag. This will configure
the features enabled for the standard library itself when building the standard
library. The default enabled features, at this time, are backtrace
and
panic_unwind
. This flag expects a comma-separated list and, if provided, will
override the default list of features enabled.
binary-dep-depinfo
- Tracking rustc issue: #63012
The -Z binary-dep-depinfo
flag causes Cargo to forward the same flag to
rustc
which will then cause rustc
to include the paths of all binary
dependencies in the "dep info" file (with the .d
extension). Cargo then uses
that information for change-detection (if any binary dependency changes, then
the crate will be rebuilt). The primary use case is for building the compiler
itself, which has implicit dependencies on the standard library that would
otherwise be untracked for change-detection.
panic-abort-tests
The -Z panic-abort-tests
flag will enable nightly support to compile test
harness crates with -Cpanic=abort
. Without this flag Cargo will compile tests,
and everything they depend on, with -Cpanic=unwind
because it's the only way
test
-the-crate knows how to operate. As of rust-lang/rust#64158, however,
the test
crate supports -C panic=abort
with a test-per-process, and can help
avoid compiling crate graphs multiple times.
It's currently unclear how this feature will be stabilized in Cargo, but we'd like to stabilize it somehow!
crate-type
cargo rustc --crate-type=lib,cdylib
forwards the --crate-type
flag to rustc
.
This runs rustc
with the corresponding
--crate-type
flag, and compiling.
When using it, it requires the -Z unstable-options
command-line option:
cargo rustc --crate-type lib,cdylib -Z unstable-options
config-cli
- Tracking Issue: #7722
The --config
CLI option allows arbitrary config values to be passed
in via the command-line. The argument should be in TOML syntax of KEY=VALUE:
cargo +nightly -Zunstable-options --config net.git-fetch-with-cli=true fetch
The --config
option may be specified multiple times, in which case the
values are merged in left-to-right order, using the same merging logic that
multiple config files use. CLI values take precedence over environment
variables, which take precedence over config files.
Some examples of what it looks like using Bourne shell syntax:
# Most shells will require escaping.
cargo --config http.proxy=\"http://example.com\" …
# Spaces may be used.
cargo --config "net.git-fetch-with-cli = true" …
# TOML array example. Single quotes make it easier to read and write.
cargo --config 'build.rustdocflags = ["--html-in-header", "header.html"]' …
# Example of a complex TOML key.
cargo --config "target.'cfg(all(target_arch = \"arm\", target_os = \"none\"))'.runner = 'my-runner'" …
# Example of overriding a profile setting.
cargo --config profile.dev.package.image.opt-level=3 …
config-include
- Tracking Issue: #7723
The include
key in a config file can be used to load another config file. It
takes a string for a path to another file relative to the config file, or a
list of strings. It requires the -Zconfig-include
command-line option.
# .cargo/config
include = '../../some-common-config.toml'
The config values are first loaded from the include path, and then the config file's own values are merged on top of it.
This can be paired with config-cli to specify a file to load
from the command-line. Pass a path to a config file as the argument to
--config
:
cargo +nightly -Zunstable-options -Zconfig-include --config somefile.toml build
CLI paths are relative to the current working directory.
target-applies-to-host
The target-applies-to-host
key in a config file can be used set the desired
behavior for passing target config flags to build scripts.
It requires the -Ztarget-applies-to-host
command-line option.
The current default for target-applies-to-host
is true
, which will be
changed to false
in the future, if -Zhost-config
is used the new false
default will be set for target-applies-to-host
.
# config.toml
target-applies-to-host = false
cargo +nightly -Ztarget-applies-to-host build --target x86_64-unknown-linux-gnu
host-config
The host
key in a config file can be used pass flags to host build targets
such as build scripts that must run on the host system instead of the target
system when cross compiling. It supports both generic and host arch specific
tables. Matching host arch tables take precedence over generic host tables.
It requires the -Zhost-config
and -Ztarget-applies-to-host
command-line
options to be set.
# config.toml
[host]
linker = "/path/to/host/linker"
[host.x86_64-unknown-linux-gnu]
linker = "/path/to/host/arch/linker"
[target.x86_64-unknown-linux-gnu]
linker = "/path/to/target/linker"
The generic host
table above will be entirely ignored when building on a
x86_64-unknown-linux-gnu
host as the host.x86_64-unknown-linux-gnu
table
takes precedence.
Setting -Zhost-config
changes the default for target-applies-to-host
to
false
from true
.
cargo +nightly -Ztarget-applies-to-host -Zhost-config build --target x86_64-unknown-linux-gnu
unit-graph
- Tracking Issue: #8002
The --unit-graph
flag can be passed to any build command (build
, check
,
run
, test
, bench
, doc
, etc.) to emit a JSON object to stdout which
represents Cargo's internal unit graph. Nothing is actually built, and the
command returns immediately after printing. Each "unit" corresponds to an
execution of the compiler. These objects also include which unit each unit
depends on.
cargo +nightly build --unit-graph -Z unstable-options
This structure provides a more complete view of the dependency relationship as
Cargo sees it. In particular, the "features" field supports the new feature
resolver where a dependency can be built multiple times with different
features. cargo metadata
fundamentally cannot represent the relationship of
features between different dependency kinds, and features now depend on which
command is run and which packages and targets are selected. Additionally it
can provide details about intra-package dependencies like build scripts or
tests.
The following is a description of the JSON structure:
{
/* Version of the JSON output structure. If any backwards incompatible
changes are made, this value will be increased.
*/
"version": 1,
/* Array of all build units. */
"units": [
{
/* An opaque string which indicates the package.
Information about the package can be obtained from `cargo metadata`.
*/
"pkg_id": "my-package 0.1.0 (path+file:///path/to/my-package)",
/* The Cargo target. See the `cargo metadata` documentation for more
information about these fields.
https://doc.rust-lang.org/cargo/commands/cargo-metadata.html
*/
"target": {
"kind": ["lib"],
"crate_types": ["lib"],
"name": "my-package",
"src_path": "/path/to/my-package/src/lib.rs",
"edition": "2018",
"test": true,
"doctest": true
},
/* The profile settings for this unit.
These values may not match the profile defined in the manifest.
Units can use modified profile settings. For example, the "panic"
setting can be overridden for tests to force it to "unwind".
*/
"profile": {
/* The profile name these settings are derived from. */
"name": "dev",
/* The optimization level as a string. */
"opt_level": "0",
/* The LTO setting as a string. */
"lto": "false",
/* The codegen units as an integer.
`null` if it should use the compiler's default.
*/
"codegen_units": null,
/* The debug information level as an integer.
`null` if it should use the compiler's default (0).
*/
"debuginfo": 2,
/* Whether or not debug-assertions are enabled. */
"debug_assertions": true,
/* Whether or not overflow-checks are enabled. */
"overflow_checks": true,
/* Whether or not rpath is enabled. */
"rpath": false,
/* Whether or not incremental is enabled. */
"incremental": true,
/* The panic strategy, "unwind" or "abort". */
"panic": "unwind"
},
/* Which platform this target is being built for.
A value of `null` indicates it is for the host.
Otherwise it is a string of the target triple (such as
"x86_64-unknown-linux-gnu").
*/
"platform": null,
/* The "mode" for this unit. Valid values:
* "test" — Build using `rustc` as a test.
* "build" — Build using `rustc`.
* "check" — Build using `rustc` in "check" mode.
* "doc" — Build using `rustdoc`.
* "doctest" — Test using `rustdoc`.
* "run-custom-build" — Represents the execution of a build script.
*/
"mode": "build",
/* Array of features enabled on this unit as strings. */
"features": ["somefeat"],
/* Whether or not this is a standard-library unit,
part of the unstable build-std feature.
If not set, treat as `false`.
*/
"is_std": false,
/* Array of dependencies of this unit. */
"dependencies": [
{
/* Index in the "units" array for the dependency. */
"index": 1,
/* The name that this dependency will be referred as. */
"extern_crate_name": "unicode_xid",
/* Whether or not this dependency is "public",
part of the unstable public-dependency feature.
If not set, the public-dependency feature is not enabled.
*/
"public": false,
/* Whether or not this dependency is injected into the prelude,
currently used by the build-std feature.
If not set, treat as `false`.
*/
"noprelude": false
}
]
},
// ...
],
/* Array of indices in the "units" array that are the "roots" of the
dependency graph.
*/
"roots": [0],
}
Profile rustflags
option
- Original Issue: rust-lang/cargo#7878
- Tracking Issue: rust-lang/cargo#10271
This feature provides a new option in the [profile]
section to specify flags
that are passed directly to rustc.
This can be enabled like so:
cargo-features = ["profile-rustflags"]
[package]
# ...
[profile.release]
rustflags = [ "-C", "..." ]
rustdoc-map
- Tracking Issue: #8296
This feature adds configuration settings that are passed to rustdoc
so that
it can generate links to dependencies whose documentation is hosted elsewhere
when the dependency is not documented. First, add this to .cargo/config
:
[doc.extern-map.registries]
crates-io = "https://docs.rs/"
Then, when building documentation, use the following flags to cause links to dependencies to link to docs.rs:
cargo +nightly doc --no-deps -Zrustdoc-map
The registries
table contains a mapping of registry name to the URL to link
to. The URL may have the markers {pkg_name}
and {version}
which will get
replaced with the corresponding values. If neither are specified, then Cargo
defaults to appending {pkg_name}/{version}/
to the end of the URL.
Another config setting is available to redirect standard library links. By
default, rustdoc creates links to https://doc.rust-lang.org/nightly/. To
change this behavior, use the doc.extern-map.std
setting:
[doc.extern-map]
std = "local"
A value of "local"
means to link to the documentation found in the rustc
sysroot. If you are using rustup, this documentation can be installed with
rustup component add rust-docs
.
The default value is "remote"
.
The value may also take a URL for a custom location.
terminal-width
- Tracking Issue: #84673
This feature provides a new flag, -Z terminal-width
, which is used to pass
a terminal width to rustc
so that error messages containing long lines
can be intelligently truncated.
For example, passing -Z terminal-width=20
(an arbitrarily low value) might
produce the following error:
error[E0308]: mismatched types
--> src/main.rs:2:17
|
2 | ..._: () = 42;
| -- ^^ expected `()`, found integer
| |
| expected due to this
error: aborting due to previous error
In contrast, without -Z terminal-width
, the error would look as shown below:
error[E0308]: mismatched types
--> src/main.rs:2:17
|
2 | let _: () = 42;
| -- ^^ expected `()`, found integer
| |
| expected due to this
error: aborting due to previous error
per-package-target
The per-package-target
feature adds two keys to the manifest:
package.default-target
and package.forced-target
. The first makes
the package be compiled by default (ie. when no --target
argument is
passed) for some target. The second one makes the package always be
compiled for the target.
Example:
[package]
forced-target = "wasm32-unknown-unknown"
In this example, the crate is always built for
wasm32-unknown-unknown
, for instance because it is going to be used
as a plugin for a main program that runs on the host (or provided on
the command line) target.
artifact-dependencies
Allow Cargo packages to depend on bin
, cdylib
, and staticlib
crates,
and use the artifacts built by those crates at compile time.
Run cargo
with -Z bindeps
to enable this functionality.
Example: use cdylib artifact in build script
The Cargo.toml
in the consuming package, building the bar
library as cdylib
for a specific build target…
[build-dependencies]
bar = { artifact = "cdylib", version = "1.0", target = "wasm32-unknown-unknown" }
…along with the build script in build.rs
.
fn main() {
wasm::run_file(env!("CARGO_CDYLIB_FILE_BAR"));
}
Example: use binary artifact and its library in a binary
The Cargo.toml
in the consuming package, building the bar
binary for inclusion
as artifact while making it available as library as well…
[dependencies]
bar = { artifact = "bin", version = "1.0", lib = true }
…along with the executable using main.rs
.
fn main() {
bar::init();
command::run(env!("CARGO_BIN_FILE_BAR"));
}
credential-process
The credential-process
feature adds a config setting to fetch registry
authentication tokens by calling an external process.
Token authentication is used by the cargo login
, cargo publish
,
cargo owner
, and cargo yank
commands. Additionally, this feature adds
a new cargo logout
command.
To use this feature, you must pass the -Z credential-process
flag on the
command-line. Additionally, you must remove any current tokens currently saved
in the credentials
file (which can be done with the new logout
command).
credential-process
Configuration
To configure which process to run to fetch the token, specify the process in
the registry
table in a config file:
[registry]
credential-process = "/usr/bin/cargo-creds"
If you want to use a different process for a specific registry, it can be
specified in the registries
table:
[registries.my-registry]
credential-process = "/usr/bin/cargo-creds"
The value can be a string with spaces separating arguments or it can be a TOML array of strings.
Command-line arguments allow special placeholders which will be replaced with the corresponding value:
{name}
— The name of the registry.{api_url}
— The base URL of the registry API endpoints.{action}
— The authentication action (described below).
Process names with the prefix cargo:
are loaded from the libexec
directory
next to cargo. Several experimental credential wrappers are included with
Cargo, and this provides convenient access to them:
[registry]
credential-process = "cargo:macos-keychain"
The current wrappers are:
cargo:macos-keychain
: Uses the macOS Keychain to store the token.cargo:wincred
: Uses the Windows Credential Manager to store the token.cargo:1password
: Uses the 1passwordop
CLI to store the token. You must install theop
CLI from the 1password website. You must runop signin
at least once with the appropriate arguments (such asop signin my.1password.com user@example.com
), unless you provide the sign-in-address and email arguments. The master password will be required on each request unless the appropriateOP_SESSION
environment variable is set. It supports the following command-line arguments:--account
: The account shorthand name to use.--vault
: The vault name to use.--sign-in-address
: The sign-in-address, which is a web address such asmy.1password.com
.--email
: The email address to sign in with.
A wrapper is available for GNOME
libsecret to store tokens on
Linux systems. Due to build limitations, this wrapper is not available as a
pre-compiled binary. This can be built and installed manually. First, install
libsecret using your system package manager (for example, sudo apt install libsecret-1-dev
). Then build and install the wrapper with cargo install cargo-credential-gnome-secret
.
In the config, use a path to the binary like this:
[registry]
credential-process = "cargo-credential-gnome-secret {action}"
credential-process
Interface
There are two different kinds of token processes that Cargo supports. The
simple "basic" kind will only be called by Cargo when it needs a token. This
is intended for simple and easy integration with password managers, that can
often use pre-existing tooling. The more advanced "Cargo" kind supports
different actions passed as a command-line argument. This is intended for more
pleasant integration experience, at the expense of requiring a Cargo-specific
process to glue to the password manager. Cargo will determine which kind is
supported by the credential-process
definition. If it contains the
{action}
argument, then it uses the advanced style, otherwise it assumes it
only supports the "basic" kind.
Basic authenticator
A basic authenticator is a process that returns a token on stdout. Newlines will be trimmed. The process inherits the user's stdin and stderr. It should exit 0 on success, and nonzero on error.
With this form, cargo login
and cargo logout
are not supported and
return an error if used.
Cargo authenticator
The protocol between the Cargo and the process is very basic, intended to
ensure the credential process is kept as simple as possible. Cargo will
execute the process with the {action}
argument indicating which action to
perform:
store
— Store the given token in secure storage.get
— Get a token from storage.erase
— Remove a token from storage.
The cargo login
command uses store
to save a token. Commands that require
authentication, like cargo publish
, uses get
to retrieve a token. cargo logout
uses the erase
command to remove a token.
The process inherits the user's stderr, so the process can display messages. Some values are passed in via environment variables (see below). The expected interactions are:
-
store
— The token is sent to the process's stdin, terminated by a newline. The process should store the token keyed off the registry name. If the process fails, it should exit with a nonzero exit status. -
get
— The process should send the token to its stdout (trailing newline will be trimmed). The process inherits the user's stdin, should it need to receive input.If the process is unable to fulfill the request, it should exit with a nonzero exit code.
-
erase
— The process should remove the token associated with the registry name. If the token is not found, the process should exit with a 0 exit status.
Environment
The following environment variables will be provided to the executed command:
CARGO
— Path to thecargo
binary executing the command.CARGO_REGISTRY_NAME
— Name of the registry the authentication token is for.CARGO_REGISTRY_API_URL
— The URL of the registry API.
cargo logout
A new cargo logout
command has been added to make it easier to remove a
token from storage. This supports both credentials
file tokens and
credential-process
tokens.
When used with credentials
file tokens, it needs the -Z unstable-options
command-line option:
cargo logout -Z unstable-options
When used with the credential-process
config, use the -Z credential-process
command-line option:
cargo logout -Z credential-process
cargo config
The cargo config
subcommand provides a way to display the configuration
files that cargo loads. It currently includes the get
subcommand which
can take an optional config value to display.
cargo +nightly -Zunstable-options config get build.rustflags
If no config value is included, it will display all config values. See the
--help
output for more options available.
doctest-in-workspace
- Tracking Issue: #9427
The -Z doctest-in-workspace
flag changes the behavior of the current working
directory used when running doctests. Historically, Cargo has run rustdoc --test
relative to the root of the package, with paths relative from that
root. However, this is inconsistent with how rustc
and rustdoc
are
normally run in a workspace, where they are run relative to the workspace
root. This inconsistency causes problems in various ways, such as when passing
RUSTDOCFLAGS with relative paths, or dealing with diagnostic output.
The -Z doctest-in-workspace
flag causes cargo to switch to running rustdoc
from the root of the workspace. It also passes the --test-run-directory
to
rustdoc
so that when running the tests, they are run from the root of the
package. This preserves backwards compatibility and is consistent with how
normal unittests are run.
rustc --print
- Tracking Issue: #9357
cargo rustc --print=VAL
forwards the --print
flag to rustc
in order to
extract information from rustc
. This runs rustc
with the corresponding
--print
flag, and then immediately exits without compiling. Exposing this as a cargo
flag allows cargo to inject the correct target and RUSTFLAGS based on the
current configuration.
The primary use case is to run cargo rustc --print=cfg
to get config values
for the appropriate target and influenced by any other RUSTFLAGS.
Different binary name
The different-binary-name
feature allows setting the filename of the binary without having to obey the
restrictions placed on crate names. For example, the crate name must use only alphanumeric
characters
or -
or _
, and cannot be empty.
The filename
parameter should not include the binary extension, cargo
will figure out the appropriate
extension and use that for the binary on its own.
The filename
parameter is only available in the [[bin]]
section of the manifest.
cargo-features = ["different-binary-name"]
[project]
name = "foo"
version = "0.0.1"
[[bin]]
name = "foo"
filename = "007bar"
path = "src/main.rs"
scrape-examples
The -Z rustdoc-scrape-examples
argument tells Rustdoc to search crates in the current workspace
for calls to functions. Those call-sites are then included as documentation. The flag can take an
argument of all
or examples
which configures which crate in the workspace to analyze for examples.
For instance:
cargo doc -Z unstable-options -Z rustdoc-scrape-examples=examples
Stabilized and removed features
Compile progress
The compile-progress feature has been stabilized in the 1.30 release.
Progress bars are now enabled by default.
See term.progress
for more information about
controlling this feature.
Edition
Specifying the edition
in Cargo.toml
has been stabilized in the 1.31 release.
See the edition field for more information
about specifying this field.
rename-dependency
Specifying renamed dependencies in Cargo.toml
has been stabilized in the 1.31 release.
See renaming dependencies
for more information about renaming dependencies.
Alternate Registries
Support for alternate registries has been stabilized in the 1.34 release. See the Registries chapter for more information about alternate registries.
Offline Mode
The offline feature has been stabilized in the 1.36 release.
See the --offline
flag for
more information on using the offline mode.
publish-lockfile
The publish-lockfile
feature has been removed in the 1.37 release.
The Cargo.lock
file is always included when a package is published if the
package contains a binary target. cargo install
requires the --locked
flag
to use the Cargo.lock
file.
See cargo package
and
cargo install
for more information.
default-run
The default-run
feature has been stabilized in the 1.37 release.
See the default-run
field for more
information about specifying the default target to run.
cache-messages
Compiler message caching has been stabilized in the 1.40 release. Compiler warnings are now cached by default and will be replayed automatically when re-running Cargo.
install-upgrade
The install-upgrade
feature has been stabilized in the 1.41 release.
cargo install
will now automatically upgrade packages if they appear to be
out-of-date. See the cargo install
documentation for more information.
Profile Overrides
Profile overrides have been stabilized in the 1.41 release. See Profile Overrides for more information on using overrides.
Config Profiles
Specifying profiles in Cargo config files and environment variables has been
stabilized in the 1.43 release.
See the config [profile]
table for more information
about specifying profiles in config files.
crate-versions
The -Z crate-versions
flag has been stabilized in the 1.47 release.
The crate version is now automatically included in the
cargo doc
documentation sidebar.
Features
The -Z features
flag has been stabilized in the 1.51 release.
See feature resolver version 2
for more information on using the new feature resolver.
package-features
The -Z package-features
flag has been stabilized in the 1.51 release.
See the resolver version 2 command-line flags
for more information on using the features CLI options.
Resolver
The resolver
feature in Cargo.toml
has been stabilized in the 1.51 release.
See the resolver versions for more
information about specifying resolvers.
extra-link-arg
The extra-link-arg
feature to specify additional linker arguments in build
scripts has been stabilized in the 1.56 release. See the build script
documentation for more
information on specifying extra linker arguments.
configurable-env
The configurable-env
feature to specify environment variables in Cargo
configuration has been stabilized in the 1.56 release. See the config
documentation for more information about configuring
environment variables.
rust-version
The rust-version
field in Cargo.toml
has been stabilized in the 1.56 release.
See the rust-version field for more
information on using the rust-version
field and the --ignore-rust-version
option.
codegen-backend
The codegen-backend
feature makes it possible to select the codegen backend used by rustc using a
profile.
Example:
[package]
name = "foo"
[dependencies]
serde = "1.0.117"
[profile.dev.package.foo]
codegen-backend = "cranelift"
patch-in-config
The -Z patch-in-config
flag, and the corresponding support for
[patch]
section in Cargo configuration files has been stabilized in
the 1.56 release. See the patch field for more
information.
edition 2021
The 2021 edition has been stabilized in the 1.56 release.
See the edition
field for more information on setting the edition.
See cargo fix --edition
and The Edition Guide for more information on migrating existing projects.
Custom named profiles
Custom named profiles have been stabilized in the 1.57 release. See the profiles chapter for more information.
Profile strip
option
The profile strip
option has been stabilized in the 1.59 release. See the
profiles chapter for more information.
Future incompat report
Support for generating a future-incompat report has been stabilized in the 1.59 release. See the future incompat report chapter for more information.
Namespaced features
Namespaced features has been stabilized in the 1.60 release. See the Features chapter for more information.
Weak dependency features
Weak dependency features has been stabilized in the 1.60 release. See the Features chapter for more information.
timings
The -Ztimings
option has been stabilized as --timings
in the 1.60 release.
(--timings=html
and the machine-readable --timings=json
output remain
unstable and require -Zunstable-options
.)