mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
![Alex Crichton](/assets/img/avatar_default.png)
This commit starts to lay the groundwork for #6660 where Cargo will invoke rustc in a "pipelined" fashion. The goal here is to execute one command to produce both an `*.rmeta` file as well as an `*.rlib` file for candidate compilations. In that case if another rlib depends on that compilation, then it can start as soon as the `*.rmeta` is ready and not have to wait for the `*.rlib` compilation. Initially attempted in #6864 with a pretty invasive refactoring this iteration is much more lightweight and fits much more cleanly into Cargo's backend. The approach taken here is to update the `DependencyQueue` structure to carry a piece of data on each dependency edge. This edge information represents the artifact that one node requires from another, and then we a node has no outgoing edges it's ready to build. A dependency on a metadata file is modeled as just that, a dependency on just the metadata and not the full build itself. Most of cargo's backend doesn't really need to know about this edge information so it's basically just calculated as we insert nodes into the `DependencyQueue`. Once that's all in place it's just a few pieces here and there to identify compilations that *can* be pipelined and then they're wired up to depend on the rmeta file instead of the rlib file.
64 lines
1.6 KiB
Rust
64 lines
1.6 KiB
Rust
use crate::support::{basic_bin_manifest, basic_manifest, project};
|
|
|
|
#[test]
|
|
fn build_lib_only() {
|
|
let p = project()
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file("src/lib.rs", r#" "#)
|
|
.build();
|
|
|
|
p.cargo("build --lib -v")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
[RUNNING] `rustc --crate-name foo src/lib.rs --color never --crate-type lib \
|
|
--emit=[..]link -C debuginfo=2 \
|
|
-C metadata=[..] \
|
|
--out-dir [..] \
|
|
-L dependency=[CWD]/target/debug/deps`
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
|
|
)
|
|
.run();
|
|
}
|
|
|
|
#[test]
|
|
fn build_with_no_lib() {
|
|
let p = project()
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
.file("src/main.rs", "fn main() {}")
|
|
.build();
|
|
|
|
p.cargo("build --lib")
|
|
.with_status(101)
|
|
.with_stderr("[ERROR] no library targets found in package `foo`")
|
|
.run();
|
|
}
|
|
|
|
#[test]
|
|
fn build_with_relative_cargo_home_path() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
authors = ["wycats@example.com"]
|
|
|
|
[dependencies]
|
|
|
|
"test-dependency" = { path = "src/test_dependency" }
|
|
"#,
|
|
)
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file("src/test_dependency/src/lib.rs", r#" "#)
|
|
.file(
|
|
"src/test_dependency/Cargo.toml",
|
|
&basic_manifest("test-dependency", "0.0.1"),
|
|
)
|
|
.build();
|
|
|
|
p.cargo("build").env("CARGO_HOME", "./cargo_home/").run();
|
|
}
|