as an alternative to passing the link-args using the environmental variable, we can also use build script to pass the "-C link-args=<FLAG>" to the compiler. see https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargorustc-link-argflag to ensure that cargo is called again by ninja, after build.rs is updated, build.rs is added as a dependency of {wasm} files along with Cargo.lock. this change is verified using following command ``` RUSTFLAGS='--print link-args' cargo build \ --target=wasm32-wasi \ --example=return_input \ --locked \ --manifest-path=Cargo.toml \ --target-dir=build/cmake/test/resource/wasm/rust ``` the output includes "-zstack-size=131072" in the argument passed to lld: ``` Compiling examples v0.0.0 (/home/kefu/dev/scylladb/test/resource/wasm/rust) LC_ALL="C" PATH="/usr/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/kefu/.local/bin:/home/kefu/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin" VSLANG="1033" "lld" "-flavor" "wasm" "--rsp-quoting=posix" "--export" "_scylla_abi" "--export" "_scylla_free" "--export" "_scylla_malloc" "--export" "return_input" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--fatal-warnings" "--no-demangle" ... "-L" "/usr/lib/rustlib/wasm32-wasi/lib" "-L" "/usr/lib/rustlib/wasm32-wasi/lib/self-contained" "-o" "/home/kefu/dev/scylladb/build/cmake/test/resource/wasm/rust/wasm32-wasi/debug/examples/return_input-ef03083560989040.wasm" "--gc-sections" "--no-entry" "-O0" "-zstack-size=131072" ``` with this change, it'd be easier to build .wat files in CMake, so we don't need to repeat the settings in both configure.py and CMakeLists.txt Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> Closes #14123
9 lines
389 B
Rust
9 lines
389 B
Rust
// The default stack size in Rust is 1MB, which causes oversized allocation warnings,
|
|
// because it's allocated in a single chunk as a part of a Wasm Linear Memory.
|
|
// We change the stack size to 128KB using the RUSTFLAGS environment variable
|
|
// in the command below.
|
|
fn main() {
|
|
println!("cargo:rustc-link-arg=-zstack-size=131072");
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
}
|