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

Avoid further trycatch and throw when exceptions are disabled #1403

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ahayzen-kdab
Copy link
Contributor

For WASM targets the cc crate changed to always set -fno-exceptions,
before only -fignore-exceptions was being set elsewhere, so now programs
fail to build when using cxx if any throw or try ... catch are used.

error: cannot use 'try' with exceptions disabled

Instead for trycatch just call func(), if the inner code has thrown it will instead abort.

error: cannot use 'throw' with exceptions disabled

Instead of throwing just print the error and abort, any previous code that was trying to catch can't exist anyway.

Any suggestions on better routes are welcome :-)

For WASM targets the `cc` crate changed to always set `-fno-exceptions`,
before only `-fignore-exceptions` was being set elsewhere, so now programs
fail to build when using `cxx` if any `throw` or `try ... catch` are used.

> error: cannot use 'try' with exceptions disabled

Instead for trycatch just call `func()`.
For WASM targets the `cc` crate changed to always set `-fno-exceptions`,
before only `-fignore-exceptions` was being set elsewhere, so now programs
fail to build when using `cxx` if any `throw` or `try ... catch` are used.

> error: cannot use 'throw' with exceptions disabled

Instead of throwing just abort.
@ahayzen-kdab
Copy link
Contributor Author

A further problem is that CXX itself fails in it's build script to build the crate unless RUST_CXX_NO_EXCEPTIONS is set, this only works if i set CXXFLAGS="-DRUST_CXX_NO_EXCEPTIONS as an env var, but maybe the build script could detect the arch in the same way as cc and set the define itself 🤔

@ahayzen-kdab
Copy link
Contributor Author

Hmm looks like that didn't quite work i'll go back to just using an env var for now, unless anyone has suggestions.

@ahayzen-kdab
Copy link
Contributor Author

Also found an alternate route through this downstream by ensuring we don't use/generate anything such as Result that would generate exception code when building for WASM.

So this pull request becomes more a question of, when RUST_CXX_NO_EXCEPTIONS is enabled should trycatch and any uses of Result have exception code in them which fails to build (therefore hinting to the developer that that code needs changing) or should they use alternate abort routes (therefore building and potentially silently working until they abort) ?

Which makes me wonder that these changes are not relevant. therefore i'll mark as draft and wait for feedback.

@ahayzen-kdab ahayzen-kdab marked this pull request as draft November 18, 2024 15:19
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.

1 participant