
This stabilizes the doctest-xcompile feature by unconditionally enabling it. Closes https://github.com/rust-lang/cargo/issues/7040 Closes https://github.com/rust-lang/cargo/issues/12118 ## What is being stabilized? This changes it so that cargo will run doctests when using the `--target` flag for a target that is not the host. Previously, cargo would ignore doctests (and show a note if passing `--verbose`). A wrapper for running the doctest can be specified with the [`target.*.runner`](https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner) configuration option (which is powered by the `--test-runtool` rustdoc flag). This would typically be something like qemu to run under emulation. It is my understanding that this should work just like running other kinds of tests. Additionally, the [`target.*.linker`](https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker) config option is honored for using a custom linker. Already stabilized in rustdoc is the ability to [ignore tests per-target](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/documentation-tests.html#ignoring-targets). ## Motivation The lack of doctest cross-compile support has always been simply due to the lack of functionality in rustdoc to support this. Rustdoc gained the ability to cross-compile doctests some time ago, but there were additional flags like the test runner that were not stabilized until just recently. This is intended to ensure that projects have full test coverage even when doing cross-compilation. It can be [surprising](https://github.com/rust-lang/cargo/issues/12118) to some that this was not happening, particularly since cargo is silent about it. ## Risks The cargo team had several conversations about how to roll out this feature. Ultimately we decided to enable it unconditionally with the understanding that most projects will probably want to have their doctests covered, and that any breakage will be a local concern that can be resolved by either fixing the test or ignoring the target. Tests in rust-lang/rust run into this issue, [particularly on android](https://github.com/rust-lang/rust/pull/119147#issuecomment-1863712897), and those will need to be fixed before this reaches beta. This is something I am looking into. Some cross-compiling scenarios may need codegen flags that are not supported. It's not clear how common this will be, or if ignoring will be a solution, or how difficult it would be to update rustdoc and cargo to support these. Additionally, the split between RUSTFLAGS and RUSTDOCFLAGS can be cumbersome. ## Implementation history - https://github.com/rust-lang/rust/pull/60387 -- Support added to rustdoc to support the `--target` flag and runtool and per-target-ignores. - https://github.com/rust-lang/cargo/pull/6892 -- Initial support in cargo. - https://github.com/rust-lang/cargo/pull/7391 -- Added unstable documentation. - https://github.com/rust-lang/cargo/pull/8094 -- Fix target for doc test cross compilation - https://github.com/rust-lang/cargo/pull/8358 -- Fixed regression with `--target=HOST` not working on stable. - https://github.com/rust-lang/cargo/pull/10132 -- Added note about doctests not running (under `--verbose`). - https://github.com/rust-lang/rust/pull/112751 -- Fixed `--test-run-directory` interaction with `--test-runtool`. - https://github.com/rust-lang/rust/pull/137096 -- Stabilization (and rename) of the rustdoc `--test-runtool` and `--test-runtool-arg` CLI args, and drops `--enable-per-target-ignores` unconditionally enabling it. ## Test coverage Cargo tests: - [artifact_dep::cross_doctests_works_with_artifacts](56c08f84e2/tests/testsuite/artifact_dep.rs (L1248-L1326)
) -- Checks that doctest has access to the artifact dependencies. - [build_script::duplicate_script_with_extra_env](56c08f84e2/tests/testsuite/build_script.rs (L5514-L5614)
) -- Checks that build-script env and cfg values are correctly handled on host versus target when cross running doctests. - [cross_compile::cross_tests](56c08f84e2/tests/testsuite/cross_compile.rs (L416-L502)
) -- Basic test that cross-compiled tests work. - [cross_compile::doctest_xcompile_linker](56c08f84e2/tests/testsuite/cross_compile.rs (L1139-L1182)
) -- Checks that the linker config argument works. - [custom_target::custom_target_minimal](56c08f84e2/tests/testsuite/custom_target.rs (L39-L71)
) -- Checks that `.json` targets work with rustdoc cross tests. - [test::cargo_test_doctest_xcompile_ignores](56c08f84e2/tests/testsuite/test.rs (L4743-L4777)
) -- Checks the `ignore-*` syntax works. - [test::cargo_test_doctest_xcompile_runner](2603268cda/tests/testsuite/test.rs (L4783-L4863)
) -- Checks runner with cross doctests. - [test::cargo_test_doctest_xcompile_no_runner](2603268cda/tests/testsuite/test.rs (L4869-L4907)
) -- Checks cross doctests without a runner. Rustdoc tests: - [run-make/doctest-runtool](25cdf1f674/tests/run-make/doctests-runtool
) -- Tests behavior of `--test-run-directory` with relative paths of the runner. - [rustdoc/doctest/doctest-runtool](25cdf1f674/tests/rustdoc/doctest/doctest-runtool.rs
) -- Tests for `--test-runtool` and `--test-runtool-arg`. ## Future concerns There have been some discussions (https://github.com/rust-lang/testing-devex-team/issues/5) about changing how doctests are driven. My understanding is that stabilizing this should not affect those plans, since if cargo becomes the driver, it will simply need to build things with `--target` and use the appropriate runner. ## Change notes This PR changed tests a little: - artifact_dep::no_cross_doctests_works_with_artifacts was changed now that doctests actually work. - cross_compile::cross_tests was changed to properly check doctests. - cross_compile::no_cross_doctests dropped since it is no longer relevant. - standard_lib::doctest didn't need `-Zdoctest-xcompile` since `-Zbuild-std` no longer uses a target. - test::cargo_test_doctest_xcompile was removed since it is a duplicate of cross_compile::cross_tests I think this should probably wait until the next release cutoff, moving this to 1.89 (will update the PR accordingly if that happens).
Cargo
Cargo downloads your Rust project’s dependencies and compiles your project.
To start using Cargo, learn more at The Cargo Book.
To start developing Cargo itself, read the Cargo Contributor Guide.
The Cargo binary distributed through with Rust is maintained by the Cargo team for use by the wider ecosystem. For all other uses of this crate (as a binary or library) this is maintained by the Cargo team, primarily for use by Cargo and not intended for external use (except as a transitive dependency). This crate may make major changes to its APIs.
Code Status
Code documentation: https://doc.rust-lang.org/nightly/nightly-rustc/cargo/
Compiling from Source
Requirements
Cargo requires the following tools and packages to build:
cargo
andrustc
- A C compiler for your platform
git
(to clone this repository)
Other requirements:
The following are optional based on your platform and needs.
-
pkg-config
— This is used to help locate system packages, such aslibssl
headers/libraries. This may not be required in all cases, such as using vendored OpenSSL, or on Windows. -
OpenSSL — Only needed on Unix-like systems and only if the
vendored-openssl
Cargo feature is not used.This requires the development headers, which can be obtained from the
libssl-dev
package on Ubuntu oropenssl-devel
with apk or yum or theopenssl
package from Homebrew on macOS.If using the
vendored-openssl
Cargo feature, then a static copy of OpenSSL will be built from source instead of using the system OpenSSL. This may require additional tools such asperl
andmake
.On macOS, common installation directories from Homebrew, MacPorts, or pkgsrc will be checked. Otherwise it will fall back to
pkg-config
.On Windows, the system-provided Schannel will be used instead.
LibreSSL is also supported.
Optional system libraries:
The build will automatically use vendored versions of the following libraries. However, if they are provided by the system and can be found with pkg-config
, then the system libraries will be used instead:
libcurl
— Used for network transfers.libgit2
— Used for fetching git dependencies.libssh2
— Used for SSH access to git repositories.libz
(AKA zlib) — Used by the above C libraries for data compression. (Rust code useszlib-rs
instead.)
It is recommended to use the vendored versions as they are the versions that are tested to work with Cargo.
Compiling
First, you'll want to check out this repository
git clone https://github.com/rust-lang/cargo.git
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 the changelog.
Reporting issues
Found a bug? We'd love to know about it!
Please report all issues on the GitHub issue tracker.
Contributing
See the Cargo Contributor Guide for a complete introduction to contributing to Cargo.
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.