rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.76k stars 425 forks source link

Fix WASI compilation for C++ #1083

Closed antaalt closed 2 weeks ago

antaalt commented 1 month ago

It seems that currently cc-rs cannot build c++ to WASI correctly, it is using clang instead of clang++, not declaring some unsupported features such as no-exceptions (WASI does not support exceptions), and not linking libc++ aswell that is coming from WASI SDK. With this PR, I am hoping this could fix this and avoid some extra code such as .compiler("clang++") to fix it

antaalt commented 1 month ago

I will look into the changes requested, in the meantime, I think it should be better to use WASI sysroot and not rely on WASI SDK so that we can use standard clang and not wasi SDK bundled clang, I will try to look into this aswell

thomcc commented 4 weeks ago

not declaring some unsupported features such as no-exceptions (WASI does not support exceptions)

FWIW, I don't think it's libc's job to automatically pass a flag like -fno-exceptions, if that's what you mean.

antaalt commented 3 weeks ago

You mean the flag should still be user provided ? As exceptions are not supported on the target and WASI only support clang as a compiler right now, I think it does make sense to provide it