macOS support and stack size
Closed this issue · 6 comments
Hi,
I was curious about Expositor and wanted to try it, so I downloaded the source code and tried to build it.
However, I'm on a Mac (with an Intel CPU, if that's relevant), and no build instructions were given for macOS. Luckily, the Linux build script almost works. The build runs successfully, but the following error occurs upon trying to run the resulting program:
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
zsh: abort ./target/release/expositor
Rust seems to be especially nice in reporting errors; evidently, the stack size is too small. It took me a few attempts to find the right number to use in the linker flags, but I have fixed the error by changing the last two lines of /build
to the following, which sets the stack size to 128 MiB:
RUSTFLAGS='-C target-cpu=native -C link-args=-Wl,-stack_size,0x7000000' cargo build
RUSTFLAGS='-C target-cpu=native -C link-args=-Wl,-stack_size,0x7000000' cargo build --release
Can you update the build script to set these flags on macOS?
Thank you :)
Thanks for reporting the issue!
I actually ran into this problem with Windows (#1) and the same flag is used in the release build script.
I’ve pushed the fix; let me know if it’s still broken! I don’t have a Mac to test on ^^'
Unfortunately, this doesn't work, as macOS ld
uses a different, and extremely weird, set of flags. Relevant to us is that stack size is specified with -stack_size
, with one hyphen, instead of --stack
, and that this flag insists on having its argument in hexadecimal. (Why, just why!?)
Thus, we should use this at lines 20-22:
if [[ "$(uname)" = 'Darwin' ]]; then
FLAGS="$FLAGS -C link-arg=-Wl,-stack_size,0x2000000"
fi
Relevant excerpt from man ld
:
-stack_size size
Specifies the maximum stack size for the main thread in a program. Without this option a program has a 8MB stack. The argument size is a hexadecimal number with an optional leading 0x. The size should be a multiple of the architecture's page size (4KB or 16KB).
I’m so sorry about that; just pushed again ^^'
It's -stack_size
rather than -stack
. Other than that, everything's fine.
Note to self: I should probably just open a pull request if something like this comes up instead of wasting time going back and forth.
Oh my god, I can’t read. Okay, now should be fixed.
It’s alright! I should have just copied the flag from your comment.
It works! (^-^)