Skip to content

Commit

Permalink
Merge pull request #26 from japaric/no-atomics
Browse files Browse the repository at this point in the history
support targets that don't support atomics
  • Loading branch information
Jorge Aparicio committed Aug 6, 2016
2 parents 933bea8 + 5e8965c commit 77ff6c8
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Support targets that don't support atomics (`"max-atomic-width": 0`). For these targets, Xargo
only compiles the `core` and `rustc_unicode` crates as the other crates depend on atomics (e.g.
`alloc::Arc`).

## [v0.1.3] - 2016-04-24

### Added
Expand Down
96 changes: 96 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ chrono = "0.2.20"
curl = "0.2.18"
flate2 = "0.2.13"
rustc_version = "0.1.7"
serde_json = "0.8.0"
tar = "0.4.4"
tempdir = "0.3.4"
term = "0.4.4"
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@ extern crate chrono;
extern crate curl;
extern crate flate2;
extern crate rustc_version;
extern crate serde_json;
extern crate tar;
extern crate tempdir;
extern crate term;

use std::{env, fs, mem};
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs::File;
use std::hash::{Hash, SipHasher};
use std::io::Read;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs, mem};

use cargo::util::{self, CargoResult, ChainError, Config, Filesystem};
use cargo::core::shell::{ColorConfig, Verbosity};
use serde_json::{de, Value};

mod sysroot;

type Spec = HashMap<String, Value>;

fn main() {
let config_opt = &mut None;
if let Err(e) = run(config_opt) {
Expand Down Expand Up @@ -91,6 +96,7 @@ pub struct Target {
hasher: SipHasher,
// Path to $triple.json file
path: PathBuf,
spec: Spec,
triple: String,
}

Expand Down Expand Up @@ -129,11 +135,18 @@ impl Target {
Ok(Target {
hasher: try!(hash(path)),
path: try!(fs::canonicalize(path)),
spec: try!(parse_json(path)),
triple: triple,
})
}
}

fn parse_json(p: &Path) -> CargoResult<Spec> {
let json = &mut String::new();
try!(try!(File::open(p)).read_to_string(json));
de::from_str(json).map_err(|_| util::human("Target specification file is not valid JSON"))
}

fn parse_args() -> CargoResult<(Command, Option<Target>, bool)> {
let mut cargo = Command::new("cargo");
let mut target = None;
Expand Down
11 changes: 9 additions & 2 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ fn rebuild_sysroot(config: &Config,
}

const CRATES: &'static [&'static str] = &["collections", "rand"];
const NO_ATOMICS_CRATES: &'static [&'static str] = &["rustc_unicode"];
const TOML: &'static str = "[package]
name = 'sysroot'
version = '0.0.0'
Expand Down Expand Up @@ -233,8 +234,14 @@ version = '0.0.0'
if verbose {
cargo.arg("--verbose");
}
for krate in CRATES {
cargo.args(&["-p", krate]);
if target.spec.get("max-atomic-width").map(|w| w.as_u64() == Some(0)) == Some(true) {
for krate in NO_ATOMICS_CRATES {
cargo.args(&["-p", krate]);
}
} else {
for krate in CRATES {
cargo.args(&["-p", krate]);
}
}
cargo.current_dir(td);
let status = try!(cargo.status());
Expand Down
35 changes: 35 additions & 0 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ const CUSTOM_JSON: &'static str = r#"
}
"#;

const NO_ATOMICS_JSON: &'static str = r#"
{
"arch": "arm",
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"llvm-target": "thumbv6m-none-eabi",
"max-atomic-width": 0,
"os": "none",
"target-endian": "little",
"target-pointer-width": "32"
}
"#;

fn xargo() -> Command {
let mut path = try!(env::current_exe());
path.pop();
Expand Down Expand Up @@ -250,3 +262,26 @@ fn rebuild_on_modified_rustflags() {

cleanup(TARGET);
}

// For targets that don't support atomics, Xargo only compiles the `core` crate
#[test]
fn no_atomics() {
const TARGET: &'static str = "__no_atomics";
const CRATES: &'static [&'static str] = &["core", "rustc_unicode"];

let td = try!(TempDir::new("xargo"));
let td = &td.path();
try!(try!(File::create(td.join(format!("{}.json", TARGET))))
.write_all(NO_ATOMICS_JSON.as_bytes()));

run(xargo().args(&["init", "--vcs", "none", "--name", TARGET]).current_dir(td));
try!(try!(OpenOptions::new().truncate(true).write(true).open(td.join("src/lib.rs")))
.write_all(LIB_RS));
run(xargo().args(&["build", "--target", TARGET]).current_dir(td));

for krate in CRATES {
assert!(exists_rlib(krate, TARGET));
}

cleanup(TARGET);
}

0 comments on commit 77ff6c8

Please sign in to comment.