Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase 1 of stdlib dependencies (RFC #1133) #2768

Closed
wants to merge 12 commits into from
10 changes: 10 additions & 0 deletions src/cargo/core/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ impl SourceId {
Ok(SourceId::for_registry(&url))
}

/// Returns the `SourceId` corresponding to the compiler source
///
/// This is located in the sysroot in <sysroot>/rustlib/src.
pub fn compiler(config: &Config) -> CargoResult<SourceId> {
let mut loc = try!(config.rustc()).sysroot.clone();
loc.push("rustlib");
loc.push("src");
Self::for_local_registry(&loc)
}

pub fn url(&self) -> &Url {
&self.inner.url
}
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl<'cfg> SourceConfigMap<'cfg> {
id: try!(SourceId::crates_io(config)),
replace_with: None,
});
base.add("compiler", SourceConfig {
id: try!(SourceId::compiler(config)),
replace_with: None,
});
Ok(base)
}

Expand Down Expand Up @@ -165,6 +169,12 @@ a lock file compatible with `{orig}` cannot be generated in this situation
`source.{}`", name)))
}

if name == "compiler" || src == try!(SourceId::compiler(self.config)) {
try!(self.config.shell().warn(
"the \"compiler source\" is unstable \
and may be removed in any later version of Cargo"));
}

let mut replace_with = None;
if let Some(val) = table.get("replace-with") {
let (s, path) = try!(val.string(&format!("source.{}.replace-with",
Expand Down
13 changes: 12 additions & 1 deletion src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Rustc {
pub path: PathBuf,
pub verbose_version: String,
pub host: String,
pub sysroot: PathBuf,
/// Backwards compatibility: does this compiler support `--cap-lints` flag?
pub cap_lints: bool,
}
Expand All @@ -29,9 +30,18 @@ impl Rustc {
};

let verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| {
internal("rustc -v didn't return utf8 output")
internal("rustc -v didn't return UTF-8 output")
}));

let mut sysroot_raw = try!(util::process(&path).arg("--print").arg("sysroot")
.exec_with_output()).stdout;
// Trim final newline
assert_eq!(sysroot_raw.pop(), Some(b'\n'));
// What about invalid code sequences on Windows?
let sysroot = From::from(try!(String::from_utf8(sysroot_raw).map_err(|_| {
internal("rustc --print sysroot didn't not return UTF-8 output")
})));

let host = {
let triple = verbose_version.lines().find(|l| {
l.starts_with("host: ")
Expand All @@ -46,6 +56,7 @@ impl Rustc {
path: path,
verbose_version: verbose_version,
host: host,
sysroot: sysroot,
cap_lints: cap_lints,
})
}
Expand Down
76 changes: 76 additions & 0 deletions src/cargo/util/toml/implicit_deps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::collections::HashMap;

use util::CargoResult;
use util::config::Config;
use util::toml::{TomlDependency, DetailedTomlDependency};

fn marshall<S, I>(name_ver: I)
-> HashMap<String, TomlDependency>
where I: Iterator<Item=(S, &'static str)>,
S: Into<String>
{
name_ver
.map(|(n, v)| (n.into(),
TomlDependency::Detailed(DetailedTomlDependency {
version: Some(v.into()),
stdlib: Some(true),
.. Default::default()
})))
.collect()
}

mod default {
use std::collections::HashMap;
use util::toml::TomlDependency;
use super::marshall;

pub fn primary() -> HashMap<String, TomlDependency> {
marshall(vec![
("core", "^1.0"),
("std", "^1.0"),
].into_iter())
}

pub fn dev() -> HashMap<String, TomlDependency> {
let mut map = marshall(vec![
("test", "^1.0"),
].into_iter());
map.extend(self::primary().into_iter());
map
}

pub fn build() -> HashMap<String, TomlDependency> {
self::primary()
}
}

fn get_custom(sort: &'static str, config: &Config)
-> CargoResult<Option<HashMap<String, TomlDependency>>>
{
let overrides = try!(config.get_list(&format!(
"custom-implicit-stdlib-dependencies.{}",
sort)));

Ok(overrides.map(|os| marshall(os.val.into_iter().map(|o| (o.0, "^1.0")))))
}

pub fn primary(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("dependencies", config))
.unwrap_or_else(|| default::primary()))
}

pub fn dev(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("dev-dependencies", config))
.unwrap_or_else(|| default::dev()))
}

pub fn build(config: &Config)
-> CargoResult<HashMap<String, TomlDependency>>
{
Ok(try!(get_custom("build-dependencies", config))
.unwrap_or_else(|| default::build()))
}
Loading