rust - How to set the thread stack size during compile time? -
when attempting run program builds large clap::app
(find source here), stackoverflow: thread '<main>' has overflowed stack
.
so far unable figure out how instruct rustc
increase stacksize brute-force workaround. rust_min_stack
seems apply runtime, , there didn't seem have effect.
as code generated, have move subcommand
creation runtime, try next.
however, see way fix differently ?
it seems quite important figure 1 out builder patterns appears prone issue, if built structure large , nested enough.
how reproduce
git clone -b clap https://github.com/byron/google-apis-rs cd google-apis-rs git checkout 9a8ae4b make dfareporting2d1-cli-cargo args=run
please note need fork of quasi , set override locally allow building latest compiler.
meta
➜ google-apis-rs git:(clap) rustc --version rustc 1.1.0-nightly (97d4e76c2 2015-04-27) (built 2015-04-28)
there's no way set stack size of main thread in rust. in fact, assumption size of main thread's stack made @ source code level in rust runtime library (https://github.com/rust-lang/rust/blob/master/src/libstd/rt/mod.rs#l85).
the environment variable rust_min_stack
influences stack size of threads created within program that's not main thread, specify value within source code @ runtime.
the straightforward way solve problem might run clap in separate thread create, can control stack size.
take code example:
extern crate clap; use clap::app; use std::thread; fn main() { let child = thread::builder::new().stack_size(32 * 1024 * 1024).spawn(move || { return app::new("example") .version("v1.0-beta") .args_from_usage("<input> 'sets input file use'") .get_matches(); }).unwrap(); let matches = child.join().unwrap(); println!("input is: {}", matches.value_of("input").unwrap()); }
clap appears able terminate application correctly within child thread code should work little modification.
Comments
Post a Comment