Skip to content

Commit

Permalink
Restore support for compilers without alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 8, 2020
1 parent 6c8f528 commit 1d8e6e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::env;
use std::process::Command;
use std::str;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};

if minor < 36 {
println!("cargo:rustc-cfg=inventory_require_std");
}
}

fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
}
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![no_std]
//! **Typed distributed plugin registration.**
//!
//! This crate provides a way to set up a plugin registry into which plugins
Expand Down Expand Up @@ -95,7 +94,11 @@
//! There is no guarantee about the order that plugins of the same type are
//! visited by the iterator. They may be visited in any order.
#![cfg_attr(not(inventory_require_std), no_std)]

#[cfg(not(inventory_require_std))]
extern crate alloc;
#[cfg(not(inventory_require_std))]
use alloc::boxed::Box;

// Not public API.
Expand Down

0 comments on commit 1d8e6e9

Please sign in to comment.