From 0c67dc5c15f4b6ffe23c184e7072bf9bf8d4a99a Mon Sep 17 00:00:00 2001 From: Plecra Date: Thu, 10 Sep 2020 21:54:44 +0100 Subject: [PATCH] Automatic alloc detection (#95) * feat: automatic `alloc` detection * fix: leave the feature in for compatibility --- miniz_oxide/Cargo.toml | 6 +++++- miniz_oxide/build.rs | 5 +++++ miniz_oxide/src/lib.rs | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 miniz_oxide/build.rs diff --git a/miniz_oxide/Cargo.toml b/miniz_oxide/Cargo.toml index 8ffd3419..39e42854 100644 --- a/miniz_oxide/Cargo.toml +++ b/miniz_oxide/Cargo.toml @@ -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 } @@ -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 = [] diff --git a/miniz_oxide/build.rs b/miniz_oxide/build.rs new file mode 100644 index 00000000..937e4e52 --- /dev/null +++ b/miniz_oxide/build.rs @@ -0,0 +1,5 @@ +use autocfg; + +fn main() { + autocfg::new().emit_sysroot_crate("alloc"); +} diff --git a/miniz_oxide/src/lib.rs b/miniz_oxide/src/lib.rs index 0b4c6078..ba15f072 100644 --- a/miniz_oxide/src/lib.rs +++ b/miniz_oxide/src/lib.rs @@ -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)]