Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::path::Path;
use std::cell::RefCell;

use serde::ser;

use util::{CargoResult, CargoResultExt, Config, RustfixDiagnosticServer};

/// Configuration information for a rustc build.
Expand Down Expand Up @@ -136,6 +138,24 @@ pub enum CompileMode {
RunCustomBuild,
}

impl ser::Serialize for CompileMode {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
use self::CompileMode::*;
match *self {
Test => "test".serialize(s),
Build => "build".serialize(s),
Check { .. } => "check".serialize(s),
Bench => "bench".serialize(s),
Doc { .. } => "doc".serialize(s),
Doctest => "doctest".serialize(s),
RunCustomBuild => "run-custom-build".serialize(s),
}
}
}

impl CompileMode {
/// Returns true if the unit is being checked.
pub fn is_check(self) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/core/compiler/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::collections::BTreeMap;

use core::TargetKind;
use super::{Context, Kind, Unit};
use super::{CompileMode, Context, Kind, Unit};
use super::context::OutputFile;
use util::{internal, CargoResult, ProcessBuilder};
use std::path::PathBuf;
Expand All @@ -22,6 +22,7 @@ struct Invocation {
package_version: semver::Version,
target_kind: TargetKind,
kind: Kind,
compile_mode: CompileMode,
deps: Vec<usize>,
outputs: Vec<PathBuf>,
links: BTreeMap<PathBuf, PathBuf>,
Expand Down Expand Up @@ -51,6 +52,7 @@ impl Invocation {
package_version: id.version().clone(),
kind: unit.kind,
target_kind: unit.target.kind().clone(),
compile_mode: unit.mode,
deps,
outputs: Vec::new(),
links: BTreeMap::new(),
Expand Down
18 changes: 12 additions & 6 deletions tests/testsuite/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ fn cargo_build_plan_simple() {
"package_name": "foo",
"package_version": "0.5.0",
"program": "rustc",
"target_kind": ["bin"]
"target_kind": ["bin"],
"compile_mode": "build"
}
]
}
Expand Down Expand Up @@ -86,7 +87,8 @@ fn cargo_build_plan_single_dep() {
"package_name": "bar",
"package_version": "0.0.1",
"program": "rustc",
"target_kind": ["lib"]
"target_kind": ["lib"],
"compile_mode": "build"
},
{
"args": "{...}",
Expand All @@ -101,7 +103,8 @@ fn cargo_build_plan_single_dep() {
"package_name": "foo",
"package_version": "0.5.0",
"program": "rustc",
"target_kind": ["lib"]
"target_kind": ["lib"],
"compile_mode": "build"
}
]
}
Expand Down Expand Up @@ -148,7 +151,8 @@ fn cargo_build_plan_build_script() {
"package_name": "foo",
"package_version": "0.5.0",
"program": "rustc",
"target_kind": ["custom-build"]
"target_kind": ["custom-build"],
"compile_mode": "build"
},
{
"args": "{...}",
Expand All @@ -161,7 +165,8 @@ fn cargo_build_plan_build_script() {
"package_name": "foo",
"package_version": "0.5.0",
"program": "[..]/build-script-build",
"target_kind": ["custom-build"]
"target_kind": ["custom-build"],
"compile_mode": "run-custom-build"
},
{
"args": "{...}",
Expand All @@ -174,7 +179,8 @@ fn cargo_build_plan_build_script() {
"package_name": "foo",
"package_version": "0.5.0",
"program": "rustc",
"target_kind": ["bin"]
"target_kind": ["bin"],
"compile_mode": "build"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ fn metabuild_build_plan() {
"package_name": "mb",
"package_version": "0.5.0",
"target_kind": ["lib"],
"compile_mode": "build",
"kind": "Host",
"deps": [],
"outputs": ["[..]/target/debug/deps/libmb-[..].rlib"],
Expand All @@ -446,6 +447,7 @@ fn metabuild_build_plan() {
"package_name": "mb-other",
"package_version": "0.0.1",
"target_kind": ["lib"],
"compile_mode": "build",
"kind": "Host",
"deps": [],
"outputs": ["[..]/target/debug/deps/libmb_other-[..].rlib"],
Expand All @@ -459,6 +461,7 @@ fn metabuild_build_plan() {
"package_name": "foo",
"package_version": "0.0.1",
"target_kind": ["custom-build"],
"compile_mode": "build",
"kind": "Host",
"deps": [0, 1],
"outputs": ["[..]/target/debug/build/foo-[..]/metabuild_foo-[..][EXE]"],
Expand All @@ -472,6 +475,7 @@ fn metabuild_build_plan() {
"package_name": "foo",
"package_version": "0.0.1",
"target_kind": ["custom-build"],
"compile_mode": "run-custom-build",
"kind": "Host",
"deps": [2],
"outputs": [],
Expand All @@ -485,6 +489,7 @@ fn metabuild_build_plan() {
"package_name": "foo",
"package_version": "0.0.1",
"target_kind": ["lib"],
"compile_mode": "build",
"kind": "Host",
"deps": [3],
"outputs": ["[..]/foo/target/debug/deps/libfoo-[..].rlib"],
Expand Down