
Rework rustc output file tracking. This is some cleanup around how Cargo computes the outputs from rustc, and changes how `cargo clean -p` works. This also includes some minor observable differences detailed below. **clean -p changes** Previously `cargo clean -p` would build the unit graph and attempt to guess what all the filename hashes are. This has several drawbacks. It incorrectly guesses the hashes in many cases (such as different features). It also tends to cause bugs because it passes every permutation of every setting into Cargo's internals, which may not be prepared to accept unsupported combinations like "test a build-script". This new implementation uses a strategy of querying rustc for the filename prefix/suffix, and then deletes the files using globs. `cargo clean -p` should now be more complete in deleting a package's artifacts, for example: - Now deletes incremental files. - Deletes dep-info files (both rustc and cargo). - Handles changes in profiles, features, (anything in the hash). - Covers a few more files (for example, dSYM in some cases, etc.). Should delete almost all files for most targets. **Internal changes** There are a bunch of internal changes to make Cargo do a better job of tracking the outputs from rustc, and to make the code easier to understand: - The list of output files is now solely computed in `TargetInfo`. The files which are uplifted are solely computed in `CompilationFiles::uplift_to`. Previously both responsibilities were awkwardly spread in both locations. - Whether or not a file should have a hyphen or underscore is now determined in one place (`FileType::should_replace_hyphens`). - Added `CrateType` to replace `LibKind`, to avoid usage of strings, and to use the same structure for all of the target kinds. - Added `FileFlavor::Rmeta` to be more explicit as to which output files are ".rmeta". (Previously the `Linkable{rmeta}` flag was specific for pipelining, and rmeta was `false` for things like `cargo check`, which was a bit hard to deal with.) - Removed hyphen/underscore renaming in `rustc`. This was mostly unused, because it did not consider hashes in the filename, so it only applied to binaries without hashes, which is essentially just wasm32 and msvc. This hyphen/underscore translation still happens during "uplift". - Changed it so that `Metadata` is always computed for every unit. The logic of whether or not something should use it is moved to `should_use_metadata`. I didn't realize that multiple units were sharing the same fingerprint directory (when they don't have a hash), which caused some bugs (like bad output caching). **Behavioral changes** Cargo now does more complete tracking of the files generated by rustc (and the linker). This means that some files will now be uplifted that previously weren't. It also means they will show up in the artifact JSON notifications. The newly tracked files are: - `.exp` export files for Windows MSVC dynamic libraries. I don't know if these are actually useful (nobody has asked for them AFAIK). Presumably the linker creates them for some reason. Note that lld *doesn't* generate these files, this is only link.exe. - Proc-macros on Windows track import/export files. - All targets (like tests, etc.) that generate separate debug files (pdb/dSYM) are tracked. - Added `.map` files for wasm32-unknown-emscripten. Some other subtle changes: - A binary example with a hyphen on Windows MSVC will now show up as `examples/foo_bar.exe` and `examples/foo-bar.exe`. Previously Cargo would just rename it to contain the hyphen. This is a consequence of simplifying the code, and I was reluctant to add a special case for this very narrow situation. - Example libs now follow the same rules for hyphen/underscore translation as normal libs (they will now use underscores). - Fingerprint changes: - Fingerprint files no longer have a hash in them. Their parent directory already contained the hash. - The fingerprint filename now uses hyphens instead of converting to underscores. - The fingerprint directory is now separated even if the unit doesn't use Metadata, to fix a caching bug. - macOS: dSYM is uplifted for all dynamic libraries (dylib/cdylib/proc-macro) and for build-script-build (in case someone wants to debug a build script?). **Notes** - I suspect that the implementation of `clean -p` may change again in the future. If and when Cargo implements some kind of on-disk database that tracks artifacts (for the purpose of garbage collection), then `cargo clean -p` can be rewritten to use that mechanism if appropriate. - The `build_script_build` incremental directory isn't deleted because Cargo doesn't know which one belongs to which package. I'm uncertain if that's reasonably fixable. The only option I've thought of is to place each package's incremental output in a separate directory. - Should Cargo use `globset` to handle non-utf-8 filenames? I suspect that Cargo's support for non-utf-8 names is pretty poor, so I'm uncertain how important that is. Closes #8149 Closes #6937 Closes #5788 Closes #5375 Closes #3530
Cargo
Cargo downloads your Rust project’s dependencies and compiles your project.
Learn more at https://doc.rust-lang.org/cargo/
Code Status
Code documentation: https://docs.rs/cargo/
Installing Cargo
Cargo is distributed by default with Rust, so if you've got rustc
installed
locally you probably also have cargo
installed locally.
Compiling from Source
Cargo requires the following tools and packages to build:
git
curl
(on Unix)pkg-config
(on Unix, used to figure out thelibssl
headers/libraries)- OpenSSL headers (only for Unix, this is the
libssl-dev
package on ubuntu) cargo
andrustc
First, you'll want to check out this repository
git clone https://github.com/rust-lang/cargo
cd cargo
With cargo
already installed, you can simply run:
cargo build --release
Adding new subcommands to Cargo
Cargo is designed to be extensible with new subcommands without having to modify Cargo itself. See the Wiki page for more details and a list of known community-developed subcommands.
Releases
Cargo releases coincide with Rust releases. High level release notes are available as part of Rust's release notes. Detailed release notes are available in this repo at CHANGELOG.md.
Reporting issues
Found a bug? We'd love to know about it!
Please report all issues on the GitHub issue tracker.
Contributing
See CONTRIBUTING.md. You may also find the architecture documentation useful (ARCHITECTURE.md).
License
Cargo is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.
Third party software
This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (https://www.openssl.org/).
In binary form, this product includes software that is licensed under the terms of the GNU General Public License, version 2, with a linking exception, which can be obtained from the upstream repository.
See LICENSE-THIRD-PARTY for details.