Skip to content

Commit

Permalink
Merge pull request #33 from japaric/src
Browse files Browse the repository at this point in the history
use source provided by rustup
  • Loading branch information
Jorge Aparicio authored Aug 30, 2016
2 parents dcd89bd + a4a0b33 commit 807e819
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Xargo can now use the source code installed by rustup. When available, this is the preferred way
to fetch the source code and saves network bandwidth by not having to fetch the source tarball.

## [v0.1.5] - 2016-08-11

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ environment:
CHANNEL: nightly

install:
- ps: Start-FileDownload "https://static.rust-lang.org/dist/channel-rust-stable"
- ps: $env:RUST_VERSION = Get-Content channel-rust-stable | select -first 1 | %{$_.split('-')[1]}
- if NOT "%CHANNEL%" == "stable" set RUST_VERSION=%CHANNEL%
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:RUST_VERSION}-${env:TARGET}.exe"
- rust-%RUST_VERSION%-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
- SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
- curl -sSf -o rustup-init.exe https://win.rustup.rs
- rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustc -V
- cargo -V

Expand Down
36 changes: 29 additions & 7 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ use term::color::GREEN;

use Target;

enum Source {
Rustup(PathBuf),
Xargo,
}

/// Create a sysroot that looks like this:
///
/// ``` text
Expand Down Expand Up @@ -73,14 +78,14 @@ pub fn create(config: &Config,
// XXX AFAIK this is not guaranteed to be correct, but it appears to be a good approximation.
let build_date = commit_date.succ();

try!(update_source(config, &build_date, root));
try!(rebuild_sysroot(config, root, target, verbose, rustflags));
let src = try!(update_source(config, &build_date, root));
try!(rebuild_sysroot(config, root, target, verbose, rustflags, src));
try!(symlink_host_crates(config, root));

Ok(())
}

fn update_source(config: &Config, date: &NaiveDate, root: &Filesystem) -> CargoResult<()> {
fn update_source(config: &Config, date: &NaiveDate, root: &Filesystem) -> CargoResult<Source> {
const TARBALL: &'static str = "rustc-nightly-src.tar.gz";

/// Reads the `NaiveDate` stored in `~/.xargo/date`
Expand Down Expand Up @@ -146,9 +151,21 @@ fn update_source(config: &Config, date: &NaiveDate, root: &Filesystem) -> CargoR

let lock = try!(root.open_rw("date", config, "xargo"));

let rustup_src_dir = try!(sysroot()).join("lib/rustlib/src/rust");

if rustup_src_dir.exists() {
let xargo_src_dir = &lock.path().parent().unwrap().join("src");

if xargo_src_dir.exists() {
try!(fs::remove_dir_all(xargo_src_dir));
}

return Ok(Source::Rustup(rustup_src_dir));
}

if try!(read_date(lock.file())).as_ref() == Some(date) {
// Source is up to date
return Ok(());
return Ok(Source::Xargo);
}

try!(lock.remove_siblings());
Expand All @@ -162,14 +179,15 @@ fn update_source(config: &Config, date: &NaiveDate, root: &Filesystem) -> CargoR
try!(file.set_len(0));
try!(file.write_all(date.format("%Y-%m-%d").to_string().as_bytes()));

Ok(())
Ok(Source::Xargo)
}

fn rebuild_sysroot(config: &Config,
root: &Filesystem,
target: &Target,
verbose: bool,
rustflags: &[String])
rustflags: &[String],
src: Source)
-> CargoResult<()> {
/// Reads the hash stored in `~/.xargo/lib/rustlib/$TARGET/hash`
fn read_hash(mut file: &File) -> CargoResult<Option<u64>> {
Expand Down Expand Up @@ -215,10 +233,14 @@ version = '0.0.0'
try!(fs::copy(&target.path, td.join(target.path.file_name().unwrap())));
try!(File::create(td.join("src/lib.rs")));
let toml = &mut String::from(TOML);
let src_dir = &match src {
Source::Rustup(dir) => dir.join("src"),
Source::Xargo => root.join("src"),
};
for krate in CRATES {
toml.push_str(&format!("{} = {{ path = '{}' }}\n",
krate,
root.join(format!("src/lib{}", krate)).display()))
src_dir.join(format!("lib{}", krate)).display()))
}
try!(try!(File::create(td.join("Cargo.toml"))).write_all(toml.as_bytes()));
if !rustflags.is_empty() {
Expand Down

0 comments on commit 807e819

Please sign in to comment.