Merge pull request #503 from serde-rs/stack
Set RUST_MIN_STACK if unset
This commit is contained in:
commit
01f6115d73
36
serde_codegen/src/env.rs
Normal file
36
serde_codegen/src/env.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::ops::Drop;
|
||||
|
||||
pub fn set_if_unset<K, V>(k: K, v: V) -> TmpEnv<K>
|
||||
where K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
{
|
||||
match env::var(&k) {
|
||||
Ok(_) => TmpEnv::WasAlreadySet,
|
||||
Err(_) => {
|
||||
env::set_var(&k, v);
|
||||
TmpEnv::WasNotSet { k: k }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub enum TmpEnv<K>
|
||||
where K: AsRef<OsStr>,
|
||||
{
|
||||
WasAlreadySet,
|
||||
WasNotSet {
|
||||
k: K,
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> Drop for TmpEnv<K>
|
||||
where K: AsRef<OsStr>,
|
||||
{
|
||||
fn drop(&mut self) {
|
||||
if let TmpEnv::WasNotSet { ref k } = *self {
|
||||
env::remove_var(k);
|
||||
}
|
||||
}
|
||||
}
|
@ -35,11 +35,18 @@ include!(concat!(env!("OUT_DIR"), "/lib.rs"));
|
||||
#[cfg(not(feature = "with-syntex"))]
|
||||
include!("lib.rs.in");
|
||||
|
||||
#[cfg(feature = "with-syntex")]
|
||||
mod env;
|
||||
|
||||
#[cfg(feature = "with-syntex")]
|
||||
pub fn expand<S, D>(src: S, dst: D) -> Result<(), syntex::Error>
|
||||
where S: AsRef<Path>,
|
||||
D: AsRef<Path>,
|
||||
{
|
||||
let src = src.as_ref().to_owned();
|
||||
let dst = dst.as_ref().to_owned();
|
||||
|
||||
let expand_thread = move || {
|
||||
use syntax::{ast, fold};
|
||||
|
||||
/// Strip the serde attributes from the crate.
|
||||
@ -76,7 +83,14 @@ pub fn expand<S, D>(src: S, dst: D) -> Result<(), syntex::Error>
|
||||
|
||||
reg.add_post_expansion_pass(strip_attributes);
|
||||
|
||||
reg.expand("", src.as_ref(), dst.as_ref())
|
||||
reg.expand("", src, dst)
|
||||
};
|
||||
|
||||
// 16 MB stack unless otherwise specified
|
||||
let _tmp_env = env::set_if_unset("RUST_MIN_STACK", "16777216");
|
||||
|
||||
use std::thread;
|
||||
thread::spawn(expand_thread).join().unwrap()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "with-syntex"))]
|
||||
|
Loading…
Reference in New Issue
Block a user