Skip to content

Commit 2e39355

Browse files
committed
Add implicit-dependencies = <bool> package key, add warnings
1 parent 43ecceb commit 2e39355

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ pub struct TomlProject {
300300
include: Option<Vec<String>>,
301301
publish: Option<bool>,
302302
workspace: Option<String>,
303+
implicit_dependencies: Option<bool>,
303304

304305
// package metadata
305306
description: Option<String>,
@@ -659,10 +660,34 @@ impl TomlManifest {
659660
cx.warnings.push("explicit dependencies are unstable".to_string());
660661
}
661662

663+
if project.implicit_dependencies.is_some() {
664+
cx.warnings.push(
665+
"the implicit-dependencies flag is unstable \
666+
(and furthermore is not currently planned on being stabilized)."
667+
.to_string());
668+
}
669+
670+
// Based on "implicit_dependencies" flag and actual usage of
671+
// explicit stdlib dependencies
672+
let implicit_primary = match (explicit_primary,
673+
project.implicit_dependencies)
674+
{
675+
(true, Some(true)) => bail!(
676+
"cannot use explicit stdlib deps when implicit deps \
677+
were explicitly enabled."),
678+
// With explicit deps, and flag not "yes", resolve "no"
679+
(true, _) => false,
680+
// With no explcit deps and no flag, resolve "yes" for
681+
// backwards-compat
682+
(false, None) => true,
683+
// With no explcit deps and the flag, obey the flag
684+
(false, Some(x)) => x,
685+
};
686+
662687
// Add implicit deps
663688
cx.platform = None;
664689

665-
if !explicit_primary {
690+
if implicit_primary {
666691
try!(process_deps(&mut cx, Some(&implicit_deps::primary()),
667692
true, keep_stdlib_deps, None));
668693
}

tests/stdlib-deps.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,107 @@ version required: ^1.0
143143
"));
144144
}
145145

146+
147+
#[test]
148+
fn explicit_stdlib_deps_with_flag() {
149+
setup();
150+
Package::new("core", "1.0.0").local(true).publish();
151+
Package::new("std", "1.0.0").local(true).file("src/lib.rs", STD).publish();
152+
Package::new("test", "1.0.0").local(true).publish();
153+
154+
let p = project("local")
155+
.file("Cargo.toml", r#"
156+
[package]
157+
name = "local"
158+
version = "0.0.1"
159+
authors = []
160+
implicit-dependencies = false
161+
162+
[dependencies]
163+
core = { version = "1", stdlib = true }
164+
std = { version = "1", stdlib = true }
165+
test = { version = "1", stdlib = true }
166+
"#)
167+
.file("src/lib.rs", "");
168+
169+
assert_that(p.cargo_process("build").arg("--verbose"),
170+
execs().with_status(0)
171+
.with_stderr_contains(
172+
"[WARNING] the \"compiler source\" is unstable [..]")
173+
.with_stderr_contains(
174+
"[WARNING] explicit dependencies are unstable"));
175+
}
176+
177+
#[test]
178+
fn implicit_stdlib_dep_with_flag() {
179+
setup();
180+
Package::new("core", "1.0.0").local(true).publish();
181+
Package::new("std", "1.0.0").local(true).file("src/lib.rs", STD).publish();
182+
Package::new("test", "1.0.0").local(true).publish();
183+
184+
let p = project("local")
185+
.file("Cargo.toml", r#"
186+
[package]
187+
name = "local"
188+
version = "0.0.1"
189+
authors = []
190+
implicit-dependencies = true
191+
"#)
192+
.file("src/lib.rs", "");
193+
194+
assert_that(p.cargo_process("build").arg("--verbose"),
195+
execs().with_status(0)
196+
.with_stderr_contains(
197+
"[WARNING] the \"compiler source\" is unstable [..]"));
198+
}
199+
200+
#[test]
201+
fn no_primary_stdlib_deps_at_all() {
202+
setup();
203+
// For dev & build
204+
Package::new("core", "1.0.0")
205+
.file("src/lib.rs", "I AM INVALID SYNTAX CANNOT COMPILE")
206+
.local(true).publish();
207+
Package::new("std", "1.0.0").local(true).publish();
208+
Package::new("test", "1.0.0").local(true).publish();
209+
210+
let foo = project("foo")
211+
.file("Cargo.toml", r#"
212+
[package]
213+
name = "foo"
214+
version = "0.0.0"
215+
authors = []
216+
implicit-dependencies = false
217+
"#)
218+
.file("src/lib.rs", "");
219+
assert_that(foo.cargo_process("build").arg("-v"),
220+
execs().with_status(0));
221+
}
222+
223+
#[test]
224+
fn mixed_expicit_and_implicit_stdlib_deps() {
225+
setup();
226+
let foo = project("foo")
227+
.file("Cargo.toml", r#"
228+
[package]
229+
name = "foo"
230+
version = "0.0.0"
231+
authors = []
232+
implicit-dependencies = true
233+
234+
[dependencies]
235+
foo = { stdlib = true }
236+
"#)
237+
.file("src/lib.rs", "");
238+
assert_that(foo.cargo_process("build").arg("-v"),
239+
execs().with_status(101).with_stderr("\
240+
[ERROR] failed to parse manifest at `[..]`
241+
242+
Caused by:
243+
cannot use explicit stdlib deps when implicit deps were explicitly enabled.
244+
"));
245+
}
246+
146247
#[test]
147248
fn stdlib_replacement() {
148249
setup();

0 commit comments

Comments
 (0)