Skip to content

Commit f663d4b

Browse files
authored
Stack size troubleshooting (#1548)
- **Run Cairo compiler in new thread** - **Add troubleshooting page to docs**
1 parent 26ca41a commit f663d4b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

scarb/src/ops/compile.rs

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use cairo_lang_utils::Upcast;
55
use indoc::formatdoc;
66
use itertools::Itertools;
77
use smol_str::{SmolStr, ToSmolStr};
8+
use std::thread;
89

910
use scarb_ui::args::FeaturesSpec;
1011
use scarb_ui::components::Status;
@@ -150,7 +151,20 @@ where
150151
Ok(())
151152
}
152153

154+
/// Run compiler in a new thread.
155+
/// The stack size of created threads can be altered with `RUST_MIN_STACK` env variable.
153156
pub fn compile_unit(unit: CompilationUnit, ws: &Workspace<'_>) -> Result<()> {
157+
thread::scope(|s| {
158+
thread::Builder::new()
159+
.name(format!("scarb compile {}", unit.id()))
160+
.spawn_scoped(s, || compile_unit_inner(unit, ws))
161+
.expect("Failed to spawn compiler thread.")
162+
.join()
163+
.expect("Compiler thread has panicked.")
164+
})
165+
}
166+
167+
fn compile_unit_inner(unit: CompilationUnit, ws: &Workspace<'_>) -> Result<()> {
154168
let package_name = unit.main_package_id().name.clone();
155169

156170
ws.config()

website/.vitepress/config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const sidebar = {
9090
"https://github.com/software-mansion/scarb/tree/main/examples",
9191
),
9292
p("Scarb vs Cargo", "/docs/scarb-vs-cargo"),
93+
p("Troubleshooting", "/docs/troubleshooting"),
9394
],
9495
},
9596
],

website/docs/troubleshooting.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Troubleshooting
2+
3+
It is possible that you encounter some issues while working with Scarb.
4+
This page lists some common issues and their possible solutions.
5+
Before reporting an issue to the Scarb team, please make sure to check the following list.
6+
7+
## Stack overflow
8+
9+
In case of a bug in the Cairo compiler implementation, it may consume too much stack space in some specific cases.
10+
Usually, this happens while compiling large Cairo codebases.
11+
This often results in an error message like:
12+
13+
```
14+
thread 'main' has overflowed its stack
15+
fatal runtime error: stack overflow
16+
Aborted (core dumped)
17+
```
18+
19+
Usually it does not seem to consume infinite amounts though, so you can try to confine it in an arbitrarily chosen
20+
big memory chunk.
21+
22+
To run the Cairo compiler with a bigger stack size, you can use the `RUST_MIN_STACK` environmental variable.
23+
For example, to set the stack size to 128MB, you can run:
24+
25+
```bash
26+
RUST_MIN_STACK=134217728 scarb build
27+
```
28+
29+
Please note that this is a workaround and not a permanent solution.
30+
If you encounter this issue, please report it to the compiler team at [Cairo issues].
31+
32+
[Cairo issues]: https://github.com/starkware-libs/cairo/issues/

0 commit comments

Comments
 (0)