如何增加“cargo test”使用的线程的堆栈大小?

1 testing rust rust-cargo

我有一个使用大量堆栈的程序。我使用 Linux,因此已经通过ulimit -s 1048576.

运行cargo test -- --test-threads 1按预期工作,但是当我使用多个线程时,例如cargo test -- --test-threads 2,我得到fatal runtime error: stack overflow. 我相信这是因为运行测试时使用的 Rust 线​​程默认堆栈大小太小。

运行时如何增加堆栈大小cargo test

小智 5

找到它RUST_MIN_STACK,如RUST_MIN_STACK=104857600 cargo test