Description
Right now, any compilation of any rust library will have a dependency on libstdc++
. If one views Rust as a targeted replacement for C++, then it seems weird to depend on it!
There are currently four reasons why rust depends on C++
- We use the
new
operator which I believe throws on OOM - We use statically initialized mutexes (statically run constructors)
- We use exceptions to implement unwinding.
- When linking librustrt, g++ is used instead of gcc
I have successfully extracted the dependency on C++ as part of alexcrichton@4b2bb6f. That patch is nowhere near a landable form, however.
I'm coming to believe that this is a fairly important dependency that we should be able to rid ourselves of (with strings attached). I propose the following plan of attack.
- Complete Create bindings for native mutexes #9105
- Remove all usage of static mutexes from C++ along with usage of the
new
operator - Move as many foo.cpp files to foo.c to prevent C++ from leaking in again.
- Add a compilation profile to librustrt. This new profile would turn
rust_try
to just callingf
, andrust_begin_unwind
would be equivalent toassert(false)
. This newlibrustrt
would be distributed along the rust standard libraries aslibrustrt_no_landing_pads
or something like that. - When compiling with
-Z no-landing-pads
, link tolibrustrt_no_landing_pads
instead oflibrustrt
As the strategy implies, the only way to drop the C++ dependency would be to forgo unwinding entirely. For now this is our best option of dropping the C++ dependency, and perhaps in the future if we ever implement unwinding without C++ exceptions we won't even need this business of a separate compilation profile.
How do others feel about this?