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

Update cargo-xbuild to new rust directory layout #87

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ In addition to the above configuration keys, `cargo-xbuild` can be also configur
If you want to use a local Rust source instead of `rust-src` rustup component, you can set the `XARGO_RUST_SRC` environment variable.

```
# The source of the `core` crate must be in `$XARGO_RUST_SRC/libcore`
# The source of the `core` crate must be in `$XARGO_RUST_SRC/core`
$ export XARGO_RUST_SRC=/path/to/rust/src

$ cargo xbuild --target msp430-none-elf.json
Expand Down
29 changes: 3 additions & 26 deletions src/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::env;
use std::ffi::OsStr;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::process::Command;
Expand All @@ -8,7 +7,6 @@ pub use rustc_version::version_meta as version;

use serde_json;
use serde_json::Value;
use walkdir::WalkDir;

use errors::*;
use extensions::CommandExt;
Expand Down Expand Up @@ -65,38 +63,17 @@ impl Sysroot {
&self.path
}

/// Returns the path to Rust source, `$SRC`, where `$SRC/libstd/Carg.toml`
/// Returns the path to Rust source, `$SRC`, where `$SRC/std/Cargo.toml`
/// exists
pub fn src(&self) -> Result<Src> {
let src = self.path().join("lib").join("rustlib").join("src");

if src.join("rust/src/libstd/Cargo.toml").is_file() {
if src.join("rust/library/std/Cargo.toml").is_file() {
return Ok(Src {
path: src.join("rust/src"),
path: src.join("rust/library"),
});
}

if src.exists() {
for e in WalkDir::new(src) {
let e = e.chain_err(|| "couldn't walk the sysroot")?;

// Looking for $SRC/libstd/Cargo.toml
if e.file_type().is_file() && e.file_name() == "Cargo.toml" {
let toml = e.path();

if let Some(std) = toml.parent() {
if let Some(src) = std.parent() {
if std.file_name() == Some(OsStr::new("libstd")) {
return Ok(Src {
path: src.to_owned(),
});
}
}
}
}
}
}

Err("`rust-src` component not found. Run `rustup component add \
rust-src`.")?
}
Expand Down
6 changes: 3 additions & 3 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ version = "0.1.0"
stoml.push_str("[dependencies.core]\n");
stoml.push_str(&format!(
"path = '{}'\n",
src.path().join("libcore").display()
src.path().join("core").display()
));

if config.panic_immediate_abort {
Expand All @@ -187,10 +187,10 @@ version = "0.1.0"
stoml.push_str("[patch.crates-io.rustc-std-workspace-core]\n");
stoml.push_str(&format!(
"path = '{}'\n",
src.path().join("tools/rustc-std-workspace-core").display()
src.path().join("rustc-std-workspace-core").display()
));

let path = src.path().join("liballoc/lib.rs").display().to_string();
let path = src.path().join("alloc/src/lib.rs").display().to_string();
let mut map = Table::new();
let mut lib = Table::new();
lib.insert("name".to_owned(), Value::String("alloc".to_owned()));
Expand Down