rust/compiler/rustc_interface/src
bors 333b920fee Auto merge of #109421 - mhammerly:extern-force-option, r=petrochenkov
Add `force` option for `--extern` flag

When `--extern force:foo=libfoo.so` is passed to `rustc` and `foo` is not actually used in the crate, ~inject an `extern crate foo;` statement into the AST~ force it to be resolved anyway in `CrateLoader::postprocess()`. This allows you to, for instance, inject a `#[panic_handler]` implementation into a `#![no_std]` crate without modifying its source so that it can be built as a `dylib`. It may also be useful for `#![panic_runtime]` or `#[global_allocator]`/`#![default_lib_allocator]` implementations.

My work previously involved integrating Rust into an existing C/C++ codebase which was built with Buck and shipped on, among other platforms, Android. When targeting Android, Buck builds all "native" code with shared linkage* so it can be loaded from Java/Kotlin. My project was not itself `#![no_std]`, but many of our dependencies were, and they would fail to build with shared linkage due to a lack of a panic handler. With this change, that project can add the new `force` option to the `std` dependency it already explicitly provides to every crate to solve this problem.

*This is an oversimplification - Buck has a couple features for aggregating dependencies into larger shared libraries, but none that I think sustainably solve this problem.

~The AST injection happens after macro expansion around where we similarly inject a test harness and proc-macro harness. The resolver's list of actually-used extern flags is populated during macro expansion, and if any of our `--extern` arguments have the `force` option and weren't already used, we inject an `extern crate` statement for them. The injection logic was added in `rustc_builtin_macros` as that's where similar injections for tests, proc-macros, and std/core already live.~

(New contributor - grateful for feedback and guidance!)
2023-05-06 11:24:37 +00:00
..
callbacks.rs Simplify tls::enter_context. 2023-02-09 15:25:45 +11:00
errors.rs Remove a back compat warning 2023-02-22 19:39:03 +00:00
interface.rs Improve internal representation of check-cfg 2023-05-05 13:06:47 +02:00
lib.rs Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
passes.rs Remove QueryEngine trait 2023-04-26 07:46:13 +02:00
proc_macro_decls.rs rustc: Remove unused Session argument from some attribute functions 2023-03-22 13:55:55 +04:00
queries.rs Change rlink serialization from MemEncoder to FileEncoder. 2023-05-01 17:09:59 +10:00
tests.rs Auto merge of #109421 - mhammerly:extern-force-option, r=petrochenkov 2023-05-06 11:24:37 +00:00
util.rs Auto merge of #109611 - Zoxc:query-engine-rem, r=cjgillot 2023-04-29 21:58:13 +00:00