Skip to content

Commit da2327f

Browse files
committed
Merge branch 'master' into tree-depth
2 parents 40791da + 238a9fa commit da2327f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+692
-385
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
other: i686-pc-windows-gnu
5555
steps:
5656
- uses: actions/checkout@v2
57+
- name: Update Rustup (temporary workaround)
58+
run: rustup self update
59+
shell: bash
60+
if: startsWith(matrix.os, 'windows')
5761
- run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
5862
- run: rustup target add ${{ matrix.other }}
5963
- run: rustup component add rustc-dev llvm-tools-preview rust-docs

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ num_cpus = "1.0"
5050
opener = "0.4"
5151
percent-encoding = "2.0"
5252
rustfix = "0.5.0"
53-
semver = { version = "0.10", features = ["serde"] }
53+
semver = { version = "1.0", features = ["serde"] }
5454
serde = { version = "1.0.123", features = ["derive"] }
5555
serde_ignored = "0.1.0"
5656
serde_json = { version = "1.0.30", features = ["raw_value"] }
5757
shell-escape = "0.1.4"
5858
strip-ansi-escapes = "0.1.0"
59-
tar = { version = "0.4.26", default-features = false }
59+
tar = { version = "0.4.35", default-features = false }
6060
tempfile = "3.0"
6161
termcolor = "1.1"
6262
toml = "0.5.7"

crates/resolver-tests/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub trait ToDep {
506506

507507
impl ToDep for &'static str {
508508
fn to_dep(self) -> Dependency {
509-
Dependency::parse_no_deprecated(self, Some("1.0.0"), registry_loc()).unwrap()
509+
Dependency::parse(self, Some("1.0.0"), registry_loc()).unwrap()
510510
}
511511
}
512512

@@ -626,7 +626,7 @@ pub fn dep(name: &str) -> Dependency {
626626
dep_req(name, "*")
627627
}
628628
pub fn dep_req(name: &str, req: &str) -> Dependency {
629-
Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap()
629+
Dependency::parse(name, Some(req), registry_loc()).unwrap()
630630
}
631631
pub fn dep_req_kind(name: &str, req: &str, kind: DepKind, public: bool) -> Dependency {
632632
let mut dep = dep_req(name, req);
@@ -639,7 +639,7 @@ pub fn dep_loc(name: &str, location: &str) -> Dependency {
639639
let url = location.into_url().unwrap();
640640
let master = GitReference::Branch("master".to_string());
641641
let source_id = SourceId::for_git(&url, master).unwrap();
642-
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
642+
Dependency::parse(name, Some("1.0.0"), source_id).unwrap()
643643
}
644644
pub fn dep_kind(name: &str, kind: DepKind) -> Dependency {
645645
dep(name).set_kind(kind).clone()

src/bin/cargo/commands/tree.rs

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub fn cli() -> App {
4343
"edges",
4444
"KINDS",
4545
"The kinds of dependencies to display \
46-
(features, normal, build, dev, all, no-dev, no-build, no-normal)",
46+
(features, normal, build, dev, all, \
47+
no-normal, no-build, no-dev, no-proc-macro)",
4748
)
4849
.short("e"),
4950
)
@@ -148,7 +149,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
148149
};
149150
let target = tree::Target::from_cli(targets);
150151

151-
let edge_kinds = parse_edge_kinds(config, args)?;
152+
let (edge_kinds, no_proc_macro) = parse_edge_kinds(config, args)?;
152153
let graph_features = edge_kinds.contains(&EdgeKind::Feature);
153154

154155
let packages = args.packages_from_flags()?;
@@ -203,25 +204,51 @@ subtree of the package given to -p.\n\
203204
format: args.value_of("format").unwrap().to_string(),
204205
graph_features,
205206
max_display_depth: args.value_of_u32("depth")?.unwrap_or(u32::MAX),
207+
no_proc_macro,
206208
};
207209

210+
if opts.graph_features && opts.duplicates {
211+
return Err(format_err!("the `-e features` flag does not support `--duplicates`").into());
212+
}
213+
208214
tree::build_and_print(&ws, &opts)?;
209215
Ok(())
210216
}
211217

212-
fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult<HashSet<EdgeKind>> {
213-
let mut kinds: Vec<&str> = args
214-
.values_of("edges")
215-
.map_or_else(|| Vec::new(), |es| es.flat_map(|e| e.split(',')).collect());
216-
if args.is_present("no-dev-dependencies") {
217-
config
218-
.shell()
219-
.warn("the --no-dev-dependencies flag has changed to -e=no-dev")?;
220-
kinds.push("no-dev");
221-
}
222-
if kinds.is_empty() {
223-
kinds.extend(&["normal", "build", "dev"]);
224-
}
218+
/// Parses `--edges` option.
219+
///
220+
/// Returns a tuple of `EdgeKind` map and `no_proc_marco` flag.
221+
fn parse_edge_kinds(
222+
config: &Config,
223+
args: &ArgMatches<'_>,
224+
) -> CargoResult<(HashSet<EdgeKind>, bool)> {
225+
let (kinds, no_proc_macro) = {
226+
let mut no_proc_macro = false;
227+
let mut kinds = args.values_of("edges").map_or_else(
228+
|| Vec::new(),
229+
|es| {
230+
es.flat_map(|e| e.split(','))
231+
.filter(|e| {
232+
no_proc_macro = *e == "no-proc-macro";
233+
!no_proc_macro
234+
})
235+
.collect()
236+
},
237+
);
238+
239+
if args.is_present("no-dev-dependencies") {
240+
config
241+
.shell()
242+
.warn("the --no-dev-dependencies flag has changed to -e=no-dev")?;
243+
kinds.push("no-dev");
244+
}
245+
246+
if kinds.is_empty() {
247+
kinds.extend(&["normal", "build", "dev"]);
248+
}
249+
250+
(kinds, no_proc_macro)
251+
};
225252

226253
let mut result = HashSet::new();
227254
let insert_defaults = |result: &mut HashSet<EdgeKind>| {
@@ -233,7 +260,7 @@ fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult<HashS
233260
bail!(
234261
"unknown edge kind `{}`, valid values are \
235262
\"normal\", \"build\", \"dev\", \
236-
\"no-normal\", \"no-build\", \"no-dev\", \
263+
\"no-normal\", \"no-build\", \"no-dev\", \"no-proc-macro\", \
237264
\"features\", or \"all\"",
238265
k
239266
)
@@ -247,12 +274,17 @@ fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult<HashS
247274
"no-dev" => result.remove(&EdgeKind::Dep(DepKind::Development)),
248275
"features" => result.insert(EdgeKind::Feature),
249276
"normal" | "build" | "dev" | "all" => {
250-
bail!("`no-` dependency kinds cannot be mixed with other dependency kinds")
277+
bail!(
278+
"`{}` dependency kind cannot be mixed with \
279+
\"no-normal\", \"no-build\", or \"no-dev\" \
280+
dependency kinds",
281+
kind
282+
)
251283
}
252284
k => return unknown(k),
253285
};
254286
}
255-
return Ok(result);
287+
return Ok((result, no_proc_macro));
256288
}
257289
for kind in &kinds {
258290
match *kind {
@@ -278,5 +310,5 @@ fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult<HashS
278310
if kinds.len() == 1 && kinds[0] == "features" {
279311
insert_defaults(&mut result);
280312
}
281-
Ok(result)
313+
Ok((result, no_proc_macro))
282314
}

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::PathBuf;
55

66
use cargo_platform::CfgExpr;
77
use cargo_util::{paths, ProcessBuilder};
8-
use semver::Version;
98

109
use super::BuildContext;
1110
use crate::core::compiler::{CompileKind, Metadata, Unit};
@@ -316,10 +315,7 @@ impl<'cfg> Compilation<'cfg> {
316315
.env("CARGO_PKG_VERSION_MAJOR", &pkg.version().major.to_string())
317316
.env("CARGO_PKG_VERSION_MINOR", &pkg.version().minor.to_string())
318317
.env("CARGO_PKG_VERSION_PATCH", &pkg.version().patch.to_string())
319-
.env(
320-
"CARGO_PKG_VERSION_PRE",
321-
&pre_version_component(pkg.version()),
322-
)
318+
.env("CARGO_PKG_VERSION_PRE", pkg.version().pre.as_str())
323319
.env("CARGO_PKG_VERSION", &pkg.version().to_string())
324320
.env("CARGO_PKG_NAME", &*pkg.name())
325321
.env(
@@ -368,23 +364,6 @@ fn fill_rustc_tool_env(mut cmd: ProcessBuilder, unit: &Unit) -> ProcessBuilder {
368364
cmd
369365
}
370366

371-
fn pre_version_component(v: &Version) -> String {
372-
if v.pre.is_empty() {
373-
return String::new();
374-
}
375-
376-
let mut ret = String::new();
377-
378-
for (i, x) in v.pre.iter().enumerate() {
379-
if i != 0 {
380-
ret.push('.')
381-
};
382-
ret.push_str(&x.to_string());
383-
}
384-
385-
ret
386-
}
387-
388367
fn target_runner(
389368
bcx: &BuildContext<'_, '_>,
390369
kind: CompileKind,

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher) {
595595
//
596596
// This assumes that the first segment is the important bit ("nightly",
597597
// "beta", "dev", etc.). Skip other parts like the `.3` in `-beta.3`.
598-
vers.pre[0].hash(hasher);
598+
vers.pre.split('.').next().hash(hasher);
599599
// Keep "host" since some people switch hosts to implicitly change
600600
// targets, (like gnu vs musl or gnu vs msvc). In the future, we may want
601601
// to consider hashing `unit.kind.short_name()` instead.

src/cargo/core/compiler/custom_build.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct BuildOutput {
2525
/// Names and link kinds of libraries, suitable for the `-l` flag.
2626
pub library_links: Vec<String>,
2727
/// Linker arguments suitable to be passed to `-C link-arg=<args>`
28-
pub linker_args: Vec<(Option<LinkType>, String)>,
28+
pub linker_args: Vec<(LinkType, String)>,
2929
/// Various `--cfg` flags to pass to the compiler.
3030
pub cfgs: Vec<String>,
3131
/// Additional environment variables to run the compiler with.
@@ -562,18 +562,36 @@ impl BuildOutput {
562562
"rustc-link-lib" => library_links.push(value.to_string()),
563563
"rustc-link-search" => library_paths.push(PathBuf::from(value)),
564564
"rustc-link-arg-cdylib" | "rustc-cdylib-link-arg" => {
565-
linker_args.push((Some(LinkType::Cdylib), value))
565+
linker_args.push((LinkType::Cdylib, value))
566566
}
567567
"rustc-link-arg-bins" => {
568568
if extra_link_arg {
569-
linker_args.push((Some(LinkType::Bin), value));
569+
linker_args.push((LinkType::Bin, value));
570+
} else {
571+
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
572+
}
573+
}
574+
"rustc-link-arg-bin" => {
575+
if extra_link_arg {
576+
let parts = value.splitn(2, "=").collect::<Vec<_>>();
577+
if parts.len() == 2 {
578+
linker_args.push((
579+
LinkType::SingleBin(parts[0].to_string()),
580+
parts[1].to_string(),
581+
));
582+
} else {
583+
warnings.push(format!(
584+
"cargo:{} has invalid syntax: expected `cargo:{}=BIN=ARG`",
585+
key, key
586+
));
587+
}
570588
} else {
571589
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
572590
}
573591
}
574592
"rustc-link-arg" => {
575593
if extra_link_arg {
576-
linker_args.push((None, value));
594+
linker_args.push((LinkType::All, value));
577595
} else {
578596
warnings.push(format!("cargo:{} requires -Zextra-link-arg flag", key));
579597
}

src/cargo/core/compiler/mod.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,27 @@ use cargo_util::{paths, ProcessBuilder, ProcessError};
6262

6363
const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";
6464

65-
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq)]
65+
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
6666
pub enum LinkType {
67+
All,
6768
Cdylib,
6869
Bin,
70+
SingleBin(String),
6971
Test,
7072
Bench,
7173
Example,
7274
}
7375

74-
impl From<&super::Target> for Option<LinkType> {
75-
fn from(value: &super::Target) -> Self {
76-
if value.is_cdylib() {
77-
Some(LinkType::Cdylib)
78-
} else if value.is_bin() {
79-
Some(LinkType::Bin)
80-
} else if value.is_test() {
81-
Some(LinkType::Test)
82-
} else if value.is_bench() {
83-
Some(LinkType::Bench)
84-
} else if value.is_exe_example() {
85-
Some(LinkType::Example)
86-
} else {
87-
None
76+
impl LinkType {
77+
pub fn applies_to(&self, target: &Target) -> bool {
78+
match self {
79+
LinkType::All => true,
80+
LinkType::Cdylib => target.is_cdylib(),
81+
LinkType::Bin => target.is_bin(),
82+
LinkType::SingleBin(name) => target.is_bin() && target.name() == name,
83+
LinkType::Test => target.is_test(),
84+
LinkType::Bench => target.is_bench(),
85+
LinkType::Example => target.is_exe_example(),
8886
}
8987
}
9088
}
@@ -227,7 +225,6 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
227225
// If we are a binary and the package also contains a library, then we
228226
// don't pass the `-l` flags.
229227
let pass_l_flag = unit.target.is_lib() || !unit.pkg.targets().iter().any(|t| t.is_lib());
230-
let link_type = (&unit.target).into();
231228

232229
let dep_info_name = if cx.files().use_extra_filename(unit) {
233230
format!(
@@ -280,7 +277,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
280277
&script_outputs,
281278
&build_scripts,
282279
pass_l_flag,
283-
link_type,
280+
&target,
284281
current_id,
285282
)?;
286283
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
@@ -371,7 +368,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
371368
build_script_outputs: &BuildScriptOutputs,
372369
build_scripts: &BuildScripts,
373370
pass_l_flag: bool,
374-
link_type: Option<LinkType>,
371+
target: &Target,
375372
current_id: PackageId,
376373
) -> CargoResult<()> {
377374
for key in build_scripts.to_link.iter() {
@@ -396,11 +393,9 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
396393
}
397394
}
398395

399-
if link_type.is_some() {
400-
for (lt, arg) in &output.linker_args {
401-
if lt.is_none() || *lt == link_type {
402-
rustc.arg("-C").arg(format!("link-arg={}", arg));
403-
}
396+
for (lt, arg) in &output.linker_args {
397+
if lt.applies_to(&target) {
398+
rustc.arg("-C").arg(format!("link-arg={}", arg));
404399
}
405400
}
406401
}

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn resolve_std<'cfg>(
4747
.iter()
4848
.map(|&name| {
4949
let source_path = SourceId::for_path(&src_path.join("library").join(name))?;
50-
let dep = Dependency::parse_no_deprecated(name, None, source_path)?;
50+
let dep = Dependency::parse(name, None, source_path)?;
5151
Ok(dep)
5252
})
5353
.collect::<CargoResult<Vec<_>>>()?;

0 commit comments

Comments
 (0)