-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The current state of codegen changing depending on whether the `std` feature is enabled is messy. The main problem is that features are controlled by immediate dependents, which are usually libraries in our case, but they cannot be expected to know whether `std` is safe to enable or disable. Unlike typical features, Lithium's `std` doesn't gate any functionality: the API exposed to users stays the same. However: - Under SEH, `std` controls whether panics within `intercept` surface or abort the program. A library often has no idea whether a certain function can panic, and as such does not have enough information to know whether `std` needs to be enabled. As such, libraries often need to enable `std`. - `std` gates printing errors to stderr on abort. This is not something libraries should control, it's the responsibility of the binary crate. - `std` also controls the TLS mechanism. Certain targets don't have a working `#[thread_local]` implementation, so `std` becomes a required feature on those targets. Platform-independent crates cannot be expected to use platform-dependent dependency feature sets. - `std` is effectively required on stable and optional on nightly. The Rust version is a responsibility of either the binary crate or the package maintainers, but certainly not of library crates. All of this makes the `std` feature broken, so instead, we gate previously-`std`-only capabilities behind probing in `build.rs`, which is guaranteed to produce valid code in the majority of cases: - As SEH can handle Rust panics whenever `panic_unwind` is linked in, even without `std`, and we only support `-C panic=unwind`, we forcibly enable sane panic handling under SEH. - We detect presence of `std::io` and always print errors in that case. This might, unfortunately, bring in I/O machinery to `#![no_main]` binaries, but should be cheap otherwise. - We choose between `#[thread_local]` and `std::thread_local!` depending on availability. `std::thread_local!` is the last choice if we can't avoid using it, so this shouldn't lead to regressions. This also fixes TLS on the GNU/Windows target, which ships a broken `#[thread_local]` that we detect with `cfg(target_thread_local)`. - We use `extern crate std;` only when it's available, and raise a compile-time error if we need it but it's unavailable.
- Loading branch information
1 parent
c51ee47
commit b7e33d1
Showing
12 changed files
with
125 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.