Skip to content
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ description = "ewasm API for Rust"
edition = "2018"

[dependencies]
wee_alloc = "0.4.4"
cfg-if = "0.1.7"
wee_alloc = { version = "0.4.4", optional = true }
qimalloc = { version = "0.1", optional = true }

[features]
default = [ "std" ]
default = ["std", "wee_alloc"]
std = []
debug = []
experimental = []
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ jobs:
cargo build --release --no-default-features --features experimental
cargo build --release --features experimental,debug
cargo build --release --no-default-features --features experimental,debug
cargo build --release --features wee_alloc
cargo build --release --features qimalloc
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@
/// finish_data(&a.bytes);
/// }
/// ```
extern crate wee_alloc;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[macro_use]
extern crate cfg_if;

cfg_if! {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure we don't need the cfg_if dependency here. We can do something like #[cfg(feature = "wee_alloc")] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also has/needs that #[global_allocator] annotation. Will that work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, attributes apply to the item below. If the item is not compiled in, then the attribute isn't either.

if #[cfg(feature = "wee_alloc")] {
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
} else if #[cfg(feature = "qimalloc")] {
extern crate qimalloc;
#[global_allocator]
static ALLOC: qimalloc::QIMalloc = qimalloc::QIMalloc::INIT;
}
}

mod native;
pub mod types;
Expand Down