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

Implement no_std support #102

Merged
merged 5 commits into from
Aug 30, 2018
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
24 changes: 9 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,24 @@ rust:
- stable

env:
- GIMLI_JOB="test" GIMLI_PROFILE=
- GIMLI_JOB="test" GIMLI_PROFILE="--release"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features" GIMLI_FEATURES="cpp_demangle"
- GIMLI_JOB="build" GIMLI_PROFILE="--no-default-features" GIMLI_FEATURES="rustc-demangle"
- GIMLI_JOB="build"
- GIMLI_JOB="features"

matrix:
fast_finish: true
exclude:
# Testing needs addr2line
- os: osx
env: GIMLI_JOB="test" GIMLI_PROFILE=
- os: osx
env: GIMLI_JOB="test" GIMLI_PROFILE="--release"
include:
# Coverage should only run on Linux and stable Rust.
- rust: stable
os: linux
sudo: required
env: GIMLI_JOB="coverage" GIMLI_PROFILE=
env: GIMLI_JOB="coverage"
# Building docs only needs to happen on one os and only on stable.
- rust: stable
os: linux
env: GIMLI_JOB="doc" GIMLI_PROFILE=
# Benching should only happen on nightly with --release.
env: GIMLI_JOB="doc"
# Benching should only happen on nightly.
- rust: nightly
env: GIMLI_JOB="bench" GIMLI_PROFILE="--release"
env: GIMLI_JOB="bench"
# Some features require nightly.
- rust: nightly
env: GIMLI_JOB="nightly_features"
16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ exclude = ["/benches/*", "/fixtures/*"]
travis-ci = { repository = "gimli-rs/addr2line" }

[dependencies]
gimli = "0.16"
fallible-iterator = "0.1"
object = { version = "0.9", optional = true }
intervaltree = "0.2"
smallvec = "0.6"
gimli = { version = "0.16.1", default-features = false }
fallible-iterator = { version = "0.1", default-features = false }
object = { version = "0.10", default-features = false, optional = true }
intervaltree = { version = "0.2", default-features = false }
smallvec = { version = "0.6", default-features = false }
lazycell = "1.0"
rustc-demangle = { version = "0.1", optional = true }
cpp_demangle = { version = "0.2", optional = true }
cpp_demangle = { version = "0.2", default-features = false, optional = true }

[dev-dependencies]
memmap = "0.6"
Expand All @@ -37,7 +37,9 @@ debug = true
debug = true

[features]
default = ["rustc-demangle", "cpp_demangle", "object"]
default = ["rustc-demangle", "cpp_demangle", "object", "std"]
std = ["gimli/std", "intervaltree/std", "object/std", "smallvec/std"]
alloc = ["gimli/alloc"]

[[test]]
name = "output_equivalence"
Expand Down
20 changes: 16 additions & 4 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ set -ex

case "$GIMLI_JOB" in
"build")
cargo build $GIMLI_PROFILE --features "$GIMLI_FEATURES"
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
cargo test
cargo test --release
else
cargo build
cargo build --release
fi
;;

"test")
cargo build $GIMLI_PROFILE --features "$GIMLI_FEATURES"
cargo test $GIMLI_PROFILE --features "$GIMLI_FEATURES"
"features")
cargo build --no-default-features --features "std"
cargo build --no-default-features --features "std cpp_demangle"
cargo build --no-default-features --features "std rustc-demangle"
cargo build --no-default-features --features "std object"
;;

"nightly_features")
cargo build --no-default-features --features "alloc"
;;

"doc")
Expand Down
25 changes: 23 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
//! which is parsed using [`gimli`](https://github.com/gimli-rs/gimli). The example CLI
//! wrapper also uses symbol table information provided by the `object` crate.
#![deny(missing_docs)]
#![no_std]
#![cfg_attr(not(feature = "std"), feature(alloc))]

#[cfg(feature = "std")]
#[macro_use]
extern crate std;

#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
extern crate core as std;

#[cfg(feature = "cpp_demangle")]
extern crate cpp_demangle;
Expand All @@ -35,10 +46,19 @@ extern crate object;
extern crate rustc_demangle;
extern crate smallvec;

#[cfg(feature = "std")]
mod alloc {
pub use std::{borrow, rc, string, vec};
}

use alloc::borrow::Cow;
#[cfg(feature = "object")]
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use alloc::vec::Vec;

use std::cmp::Ordering;
use std::borrow::Cow;
use std::u64;
use std::rc::Rc;

use fallible_iterator::FallibleIterator;
use intervaltree::{Element, IntervalTree};
Expand Down Expand Up @@ -384,6 +404,7 @@ impl<R: gimli::Reader> FunctionName<R> {
/// Demangle a symbol name using the demangling scheme for the given language.
///
/// Returns `None` if demangling failed or is not required.
#[allow(unused_variables)]
pub fn demangle(name: &str, language: gimli::DwLang) -> Option<String> {
match language {
#[cfg(feature = "rustc-demangle")]
Expand Down