Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WASI compilation for C++ #1083

Merged
merged 8 commits into from
Jun 21, 2024
Merged

Fix WASI compilation for C++ #1083

merged 8 commits into from
Jun 21, 2024

Conversation

antaalt
Copy link
Contributor

@antaalt antaalt commented Jun 5, 2024

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

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@antaalt
Copy link
Contributor Author

antaalt commented Jun 7, 2024

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
Copy link
Member

thomcc commented Jun 8, 2024

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
Copy link
Contributor Author

antaalt commented Jun 11, 2024

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

@antaalt antaalt requested a review from NobodyXu June 12, 2024 21:33
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine I suppose, but I can't help but think this will cause problems in the future.

src/lib.rs Outdated Show resolved Hide resolved
if self.get_target()?.contains("wasi") {
let wasi_sysroot = self.wasi_sysroot()?;
self.cargo_output.print_metadata(&format_args!(
"cargo:rustc-flags=-L {}/lib/wasm32-wasi -lstatic=c++ -lstatic=c++abi",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took another look and realise it is hardcoded to wasi.

I don't like it, but I think it's ok given that the preview wasi is also wasi.

Copy link
Collaborator

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

It LGTM now!

@NobodyXu NobodyXu merged commit 6a6107a into rust-lang:main Jun 21, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants