Skip to content

Commit

Permalink
Merge #213
Browse files Browse the repository at this point in the history
213: compile core and compiler_builtins (+mem) ... r=japaric a=japaric

if no Xargo.toml was specified

closes #212

cc @phil-opp

Co-authored-by: Jorge Aparicio <[email protected]>
  • Loading branch information
bors[bot] and japaric committed Apr 8, 2018
2 parents da390b9 + 65c8871 commit 440e48f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 48 deletions.
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@ matrix:
- env: TARGET=x86_64-apple-darwin
os: osx

- env: TARGET=i686-unknown-linux-gnu
rust: nightly
- env: TARGET=i686-unknown-linux-musl
rust: nightly
# Tests
- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly
- env: TARGET=x86_64-unknown-linux-musl
rust: nightly
- env: TARGET=i686-apple-darwin
os: osx
- env: TARGET=x86_64-apple-darwin
os: osx
rust: nightly

install:
- bash ci/install.sh
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["cli", "cross", "compilation", "std"]
license = "MIT OR Apache-2.0"
name = "xargo"
repository = "https://github.com/japaric/xargo"
version = "0.3.11"
version = "0.3.12"

[dependencies]
error-chain = "0.7.2"
Expand Down
2 changes: 2 additions & 0 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ main() {
if [ $TRAVIS_OS_NAME = linux ]; then
target=x86_64-unknown-linux-gnu
sort=sort

sudo apt-get install gcc-arm-none-eabi
else
target=x86_64-apple-darwin
sort=gsort # for `sort --sort-version`, from brew's coreutils.
Expand Down
4 changes: 2 additions & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ main() {
cross run --target $TARGET -- -V

if [ $TRAVIS_RUST_VERSION = nightly ]; then
cross test --features dev --target $TARGET
cross test --target $TARGET
cargo test --features dev --target $TARGET
cargo test --target $TARGET
fi
}

Expand Down
54 changes: 39 additions & 15 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::BTreeMap;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::io::{self, Write};
use std::path::PathBuf;
use std::process::Command;
use std::io::{self, Write};
use std::{env, fs};

use rustc_version::VersionMeta;
Expand Down Expand Up @@ -54,7 +54,8 @@ version = "0.0.0"
util::mkdir(&dst)?;

if cmode.triple().contains("pc-windows-gnu") {
let src = &sysroot.path()
let src = &sysroot
.path()
.join("lib")
.join("rustlib")
.join(cmode.triple())
Expand All @@ -64,8 +65,13 @@ version = "0.0.0"
for file in ["rsbegin.o", "rsend.o", "crt2.o", "dllcrt2.o"].iter() {
let file_src = src.join(file);
let file_dst = dst.join(file);
fs::copy(&file_src, &file_dst)
.chain_err(|| format!("couldn't copy {} to {}", file_src.display(), file_dst.display()))?;
fs::copy(&file_src, &file_dst).chain_err(|| {
format!(
"couldn't copy {} to {}",
file_src.display(),
file_dst.display()
)
})?;
}
}

Expand Down Expand Up @@ -218,7 +224,16 @@ pub fn update(
let hash = hash(cmode, &blueprint, rustflags, &ctoml, meta)?;

if old_hash(cmode, home)? != Some(hash) {
build(cmode, blueprint, &ctoml, home, rustflags, sysroot, hash, verbose)?;
build(
cmode,
blueprint,
&ctoml,
home,
rustflags,
sysroot,
hash,
verbose,
)?;
}

// copy host artifacts into the sysroot, if necessary
Expand Down Expand Up @@ -326,10 +341,22 @@ impl Blueprint {
))?
},
(None, None) => {
// If no dependencies were listed, we assume `core` as the
// only dependency
// If no dependencies were listed, we assume `core` and `compiler_builtins` as the
// dependencies
let mut t = BTreeMap::new();
t.insert("core".to_owned(), Value::Table(BTreeMap::new()));
let mut core = BTreeMap::new();
core.insert("stage".to_owned(), Value::Integer(0));
t.insert("core".to_owned(), Value::Table(core));
let mut cb = BTreeMap::new();
cb.insert(
"features".to_owned(),
Value::Array(vec![Value::String("mem".to_owned())]),
);
cb.insert("stage".to_owned(), Value::Integer(1));
t.insert(
"compiler_builtins".to_owned(),
Value::Table(cb),
);
t
}
};
Expand Down Expand Up @@ -372,8 +399,7 @@ impl Blueprint {
Err(format!(
"Xargo.toml: target.{}.dependencies.{} must be \
a table",
target,
k
target, k
))?
}
}
Expand All @@ -382,11 +408,9 @@ impl Blueprint {
}

fn push(&mut self, stage: i64, krate: String, toml: Table) {
let stage = self.stages.entry(stage).or_insert_with(|| {
Stage {
crates: vec![],
toml: Table::new(),
}
let stage = self.stages.entry(stage).or_insert_with(|| Stage {
crates: vec![],
toml: Table::new(),
});

stage.toml.insert(krate.clone(), Value::Table(toml));
Expand Down
38 changes: 20 additions & 18 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl Drop for HProject {
#[test]
fn simple() {
fn run() -> Result<()> {
const TARGET: &'static str = "__simple";
const TARGET: &'static str = "thumbv6m-simple-eabi";

let project = Project::new(TARGET)?;
project.build(TARGET)?;
Expand All @@ -341,12 +341,13 @@ fn simple() {
#[test]
fn target_dependencies() {
fn run() -> Result<()> {
const TARGET: &'static str = "__target_dependencies";
// need this exact target name to get the right gcc flags
const TARGET: &'static str = "thumbv7m-none-eabi";

let project = Project::new(TARGET)?;
project.xargo_toml(
r#"
[target.__target_dependencies.dependencies.alloc]
[target.thumbv7m-none-eabi.dependencies.alloc]
"#,
)?;
project.build(TARGET)?;
Expand All @@ -364,7 +365,8 @@ fn target_dependencies() {
#[test]
fn dependencies() {
fn run() -> Result<()> {
const TARGET: &'static str = "__dependencies";
// need this exact target name to get the right gcc flags
const TARGET: &'static str = "thumbv6m-none-eabi";

let project = Project::new(TARGET)?;
project.xargo_toml(
Expand All @@ -387,7 +389,7 @@ fn dependencies() {
#[test]
fn doc() {
fn run() -> Result<()> {
const TARGET: &'static str = "__doc";
const TARGET: &'static str = "thumbv6m-doc-eabi";

let project = Project::new(TARGET)?;
project.doc(TARGET)?;
Expand All @@ -404,7 +406,7 @@ fn doc() {
#[test]
fn twice() {
fn run() -> Result<()> {
const TARGET: &'static str = "__twice";
const TARGET: &'static str = "thumbv6m-twice-eabi";

let project = Project::new(TARGET)?;
let stderr = project.build_and_get_stderr(Some(TARGET))?;
Expand All @@ -427,13 +429,13 @@ fn twice() {
#[test]
fn build_target() {
fn run() -> Result<()> {
const TARGET: &'static str = "__build_target";
const TARGET: &'static str = "thumbv6m-build_target-eabi";

let project = Project::new(TARGET)?;
project.config(
r#"
[build]
target = "__build_target"
target = "thumbv6m-build_target-eabi"
"#,
)?;

Expand All @@ -452,7 +454,7 @@ target = "__build_target"
#[test]
fn override_build_target() {
fn run() -> Result<()> {
const TARGET: &'static str = "__override_build_target";
const TARGET: &'static str = "thumbv6m-override_build_target-eabi";

let project = Project::new(TARGET)?;
project.config(
Expand All @@ -477,7 +479,7 @@ target = "BAD"
#[test]
fn lto_changed() {
fn run() -> Result<()> {
const TARGET: &'static str = "__lto_changed";
const TARGET: &'static str = "thumbv6m-lto_changed-eabi";

let project = Project::new(TARGET)?;
let stderr = project.build_and_get_stderr(Some(TARGET))?;
Expand Down Expand Up @@ -506,7 +508,7 @@ lto = true
#[test]
fn rustflags_changed() {
fn run() -> Result<()> {
const TARGET: &'static str = "__rustflags_changed";
const TARGET: &'static str = "thumbv6m-rustflags_changed-eabi";

let project = Project::new(TARGET)?;
let stderr = project.build_and_get_stderr(Some(TARGET))?;
Expand Down Expand Up @@ -535,7 +537,7 @@ rustflags = ["--cfg", "xargo"]
#[test]
fn rustflags() {
fn run() -> Result<()> {
const TARGET: &'static str = "__rustflags";
const TARGET: &'static str = "thumbv6m-rustflags-eabi";

let project = Project::new(TARGET)?;

Expand Down Expand Up @@ -567,7 +569,7 @@ rustflags = ["--cfg", "xargo"]
#[test]
fn panic_abort() {
fn run() -> Result<()> {
const TARGET: &'static str = "__panic_abort";
const TARGET: &'static str = "thumbv6m-panic_abort-eabi";

let project = Project::new(TARGET)?;

Expand Down Expand Up @@ -598,7 +600,7 @@ panic = "abort"
#[test]
fn link_arg() {
fn run() -> Result<()> {
const TARGET: &'static str = "__link_arg";
const TARGET: &'static str = "thumbv6m-link_arg-eabi";

let project = Project::new(TARGET)?;

Expand Down Expand Up @@ -642,7 +644,7 @@ fn specification_changed() {
"target-pointer-width": "32"
}
"#;
const TARGET: &'static str = "__specification_changed";
const TARGET: &'static str = "thumbv6m-specification_changed-eabi";

let project = Project::new(TARGET)?;

Expand All @@ -651,7 +653,7 @@ fn specification_changed() {
assert!(sysroot_was_built(&stderr, TARGET));

write(
&project.td.path().join("__specification_changed.json"),
&project.td.path().join("thumbv6m-specification_changed-eabi.json"),
false,
JSON,
)?;
Expand Down Expand Up @@ -685,7 +687,7 @@ fn unchanged_specification() {
"target-pointer-width": "32"
}
"#;
const TARGET: &'static str = "__unchanged_specification";
const TARGET: &'static str = "thumbv6m-unchanged_specification-eabi";

let project = Project::new(TARGET)?;

Expand All @@ -694,7 +696,7 @@ fn unchanged_specification() {
assert!(sysroot_was_built(&stderr, TARGET));

write(
&project.td.path().join("__unchanged_specification.json"),
&project.td.path().join("thumbv6m-unchanged_specification-eabi.json"),
false,
JSON,
)?;
Expand Down

0 comments on commit 440e48f

Please sign in to comment.