-
Notifications
You must be signed in to change notification settings - Fork 340
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
cxxbridge doesn't run with panic=abort #130
Comments
Cargo always build host tools (build scripts and macros) with panicking even if the final artifact uses That said, I understand that this is an obstacle in non-Cargo codebases and I am not opposed to considering ways to fix it. The catch_unwind in proc-macro2 is used for determining whether or not we are currently executing inside of a proc macro. Inside a proc macro (like inside the implementation of structopt-derive which cxxbridge-cmd depends on), proc-macro2 must use the compiler's token representation because otherwise the compiler won't understand the provenance of the output tokens for correct name resolution and error reporting. Outside of a proc macro (such as when cxxbridge-cmd itself is parsing an input file) proc-macro2 must not use the compiler's token representation because that's backed by a client/server that rustc provides only to proc macros. Two fixes would be:
Does it look like you will be able to fix this in your build system in a reasonable time or would it be better to pursue one of the above? |
Thanks for the comment. In theory, our non-Cargo build system can cope with this. It requires us to jump through significant hoops to parameterize the Rust toolchain details, but I do think those humps are worth jumping through. We're bound to hit the same problem elsewhere in the future. So speaking purely from the point of view of our needs, let's not do anything here. Speaking more generally though, it feels like |
proc_macro::is_available() This PR adds `proc_macro::is_available() -> bool` to determine whether proc_macro has been made accessible to the currently running program. The proc_macro crate is only intended for use inside the implementation of procedural macros. All the functions in the crate panic if invoked from outside of a procedural macro, such as from a build script or unit test or ordinary Rust binary. Unfortunately those panics made it impossible for libraries that are designed to support both macro and non-macro use cases (e.g. Syn) to be used from binaries that are compiled with panic=abort. In panic=unwind mode we're able to attempt a proc macro call inside catch_unwind and use libproc_macro's result if it succeeds, otherwise fall back to a non-macro alternative implementation. But in panic=abort there was no way to determine which implementation needs to be used. r? @eddyb attn: @petrochenkov @adetaylor ref: dtolnay/cxx#130
I've landed a non-panicking |
Cargo always runs build scripts with panic=unwind, but other build environments might not -- see here for a similar issue in cxx: dtolnay/cxx#130 And the corresponding fix: dtolnay/cxx#184
This issue is not a bug; it is working as designed; and the issue should be closed. I'm writing it up here for the benefit of others who come across it.
Our build system provides
-Cpanic=abort
as flags torustc
in order to minimize binary size. As it happens we can guarantee that the various use-cases we're using on the target devices should not panic, and it's OK to abort if they do.Unfortunately, that means we're building host-side tools using this setting as well. This is obviously not ideal, and this is what we need to fix.
Meanwhile, though, this means we cannot use
cxxbridge
:gives
As far as I can tell, that's because of this code in
proc_macro2
'ssrc/wrapper.rs
:So, this isn't a bug in cxx. It's not even a bug in proc_macro2. It's intentional usage of exceptions within proc_macro2, and we need to adjust our build system. But I'm writing it up here for others' benefit.
The text was updated successfully, but these errors were encountered: