Skip to content

Commit

Permalink
fix path inference on windows hosts
Browse files Browse the repository at this point in the history
also add support for WASM binaries

closes #32
  • Loading branch information
japaric committed Oct 27, 2018
1 parent 301a00c commit d4cf578
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 94 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.1.5] - 2018-10-28

### Added

- Path inference support for WASM binaries

### Fixed

- Path inference on windows hosts

## [v0.1.4] - 2018-09-09

### Fixed
Expand Down Expand Up @@ -54,7 +64,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Initial release

[Unreleased]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.4...HEAD
[Unreleased]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.5...HEAD
[v0.1.5]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.4...v0.1.5
[v0.1.4]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.3...v0.1.4
[v0.1.3]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.2...v0.1.3
[v0.1.2]: https://github.com/rust-embedded/cargo-binutils/compare/v0.1.1...v0.1.2
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -11,10 +11,11 @@ repository = "https://github.com/japaric/cargo-binutils"
version = "0.1.5"

[dependencies]
cargo-project = "0.1.0"
cargo-project = "0.2.0"
clap = "2.32.0"
failure = "0.1.1"
regex = "0.2.10"
rustc-cfg = "0.4.0"
rustc-demangle = "0.1.7"
rustc_version = "0.2.2"
walkdir = "2.1.4"
walkdir = "2.1.4"
23 changes: 17 additions & 6 deletions src/lib.rs
Expand Up @@ -5,6 +5,7 @@ extern crate cargo_project;
extern crate failure;
extern crate clap;
extern crate regex;
extern crate rustc_cfg;
extern crate rustc_demangle;
extern crate rustc_version;
extern crate walkdir;
Expand All @@ -17,11 +18,11 @@ use std::{env, str};

use cargo_project::{Artifact, Error, Profile, Project};
use clap::{App, AppSettings, Arg};
use rustc_cfg::Cfg;
use walkdir::WalkDir;

mod llvm;
mod postprocess;
mod rustc;

#[derive(Clone, Copy, PartialEq)]
pub enum Tool {
Expand Down Expand Up @@ -67,10 +68,14 @@ pub enum Endian {
pub struct Context {
/// Directory within the Rust sysroot where the llvm tools reside
bindir: PathBuf,
cfg: rustc::Cfg,
cfg: Cfg,
/// In a Cargo project or not?
project: Option<Project>,
/// `--target`
target_flag: Option<String>,
/// Final compilation target
target: String,
host: String,
}

impl Context {
Expand Down Expand Up @@ -104,8 +109,8 @@ impl Context {
let target = target_flag
.or(project.as_ref().and_then(|p| p.target()))
.map(|t| t.to_owned())
.unwrap_or(host);
let cfg = rustc::Cfg::parse(&target)?;
.unwrap_or_else(|| host.clone());
let cfg = Cfg::of(&target)?;

for entry in WalkDir::new(sysroot.trim()) {
let entry = entry?;
Expand All @@ -118,6 +123,8 @@ impl Context {
cfg,
project,
target,
target_flag: target_flag.map(|s| s.to_owned()),
host,
});
}
}
Expand All @@ -137,10 +144,14 @@ impl Context {
self.project.as_ref().ok_or(Error::NotACargoProject)
}

fn rustc_cfg(&self) -> &rustc::Cfg {
fn rustc_cfg(&self) -> &Cfg {
&self.cfg
}

fn target_flag(&self) -> Option<&str> {
self.target_flag.as_ref().map(|s| &**s)
}

fn tool(&self, tool: Tool, target: &str) -> Command {
let mut c = Command::new(self.bindir().join(&*exe(&format!("llvm-{}", tool.name()))));

Expand Down Expand Up @@ -340,7 +351,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- -help`.{}",
// Artifact
if let Some(kind) = artifact {
let project = ctxt.project()?;
let artifact = project.path(kind, profile, project.target());
let artifact = project.path(kind, profile, ctxt.target_flag(), &ctxt.host)?;

match tool {
// for some tools we change the CWD (current working directory) and
Expand Down
32 changes: 18 additions & 14 deletions src/llvm.rs
@@ -1,4 +1,4 @@
use {rustc, Endian};
use rustc_cfg::Cfg;

// Here we map Rust arches to LLVM arches
//
Expand Down Expand Up @@ -53,30 +53,34 @@ use {rustc, Endian};
// - wasm64
// - x86
// - x86-64
pub fn arch_name<'a>(cfg: &'a rustc::Cfg, target: &'a str) -> &'a str {
let endian = cfg.endian();
let arch = cfg.arch();
pub fn arch_name<'a>(cfg: &'a Cfg, target: &'a str) -> &'a str {
const BIG: &str = "big";
const LITTLE: &str = "little";

let endian = &*cfg.target_endian;
let arch = &*cfg.target_arch;

if target.starts_with("thumb") {
// no way to tell from `--print cfg` that the target is thumb only so we
// completely rely on the target name here
match endian {
Endian::Little => "thumb",
Endian::Big => "thumbeb",
if endian == BIG {
"thumbeb"
} else {
"thumb"
}
} else {
match (arch, endian) {
// non standard endianness
("aarch64", Endian::Big) => "aarch64_be",
("arm", Endian::Big) => "armeb",
("mips", Endian::Little) => "mipsel",
("mips64", Endian::Little) => "mips64el",
("powerpc64", Endian::Little) => "ppc64le",
("sparc", Endian::Little) => "sparcel",
("aarch64", BIG) => "aarch64_be",
("arm", BIG) => "armeb",
("mips", LITTLE) => "mipsel",
("mips64", LITTLE) => "mips64el",
("powerpc64", LITTLE) => "ppc64le",
("sparc", LITTLE) => "sparcel",

// names that match
("powerpc", _) => "ppc32",
("powerpc64", Endian::Big) => "ppc64",
("powerpc64", BIG) => "ppc64",
("sparc64", _) => "sparcv9",
("s390x", _) => "systemz",
("x86_64", _) => "x86-64",
Expand Down
71 changes: 0 additions & 71 deletions src/rustc.rs

This file was deleted.

0 comments on commit d4cf578

Please sign in to comment.