From cb36872a267a8b6c48b156beaf12986bad0526ce Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 8 Apr 2018 12:32:07 +0200 Subject: [PATCH 1/3] compile core and compiler_builtins (+mem) ... if no Xargo.toml was specified --- Cargo.toml | 2 +- src/sysroot.rs | 54 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 209688a..88df15f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/sysroot.rs b/src/sysroot.rs index 1a0d9da..8c69656 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -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; @@ -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()) @@ -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() + ) + })?; } } @@ -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 @@ -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 } }; @@ -372,8 +399,7 @@ impl Blueprint { Err(format!( "Xargo.toml: target.{}.dependencies.{} must be \ a table", - target, - k + target, k ))? } } @@ -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)); From c22841fc5d124138a51b9fe8f592551f913822c0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 8 Apr 2018 13:14:11 +0200 Subject: [PATCH 2/3] update Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9501b33..fcdea0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,7 +223,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "xargo" -version = "0.3.11" +version = "0.3.12" dependencies = [ "error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "fs2 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", From 0de819d5cc319090193a34a21e5957a40f5ef064 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 8 Apr 2018 14:19:43 +0200 Subject: [PATCH 3/3] fix tests --- tests/smoke.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/smoke.rs b/tests/smoke.rs index 9ccb8f0..20cf812 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -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)?; @@ -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)?; @@ -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( @@ -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)?; @@ -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))?; @@ -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" "#, )?; @@ -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( @@ -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))?; @@ -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))?; @@ -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)?; @@ -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)?; @@ -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)?; @@ -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)?; @@ -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, )?; @@ -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)?; @@ -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, )?;