Skip to content

Commit

Permalink
Automatic alloc detection (#95)
Browse files Browse the repository at this point in the history
* feat: automatic `alloc` detection

* fix: leave the feature in for compatibility
  • Loading branch information
Plecra committed Sep 10, 2020
1 parent 743d6d3 commit 0c67dc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion miniz_oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ documentation = "https://docs.rs/miniz_oxide"
description = "DEFLATE compression and decompression library rewritten in Rust based on miniz"
edition = "2018"
exclude = ["benches/*", "tests/*"]
build = "build.rs"

[lib]
name = "miniz_oxide"

[build-dependencies]
autocfg = "1.0"

[dependencies]
adler = { version = "0.2.1", default-features = false }

Expand All @@ -29,5 +33,5 @@ compiler_builtins = { version = '0.1.2', optional = true }
# Internal feature, only used when building as part of libstd, not part of the
# stable interface of this crate.
rustc-dep-of-std = ['core', 'alloc', 'compiler_builtins', 'adler/rustc-dep-of-std']
# Use std instead of alloc. This should only be used for backwards compatibility.
# This feature has no effect (See Frommi/miniz_oxide#95)
no_extern_crate_alloc = []
5 changes: 5 additions & 0 deletions miniz_oxide/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use autocfg;

fn main() {
autocfg::new().emit_sysroot_crate("alloc");
}
6 changes: 3 additions & 3 deletions miniz_oxide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

#![allow(warnings)]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "no_extern_crate_alloc"), no_std)]
#![cfg_attr(has_alloc, no_std)]

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

#[cfg(test)]
Expand Down

0 comments on commit 0c67dc5

Please sign in to comment.