Add force option for --extern flag#109421
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jackh726 (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
f08dc30 to
2c5c361
Compare
|
I believe adding a new option like this requires a Major Change Proposal |
|
I'm not on the compiler team, but I believe the MCP is the process nowadays. |
|
This will probably remain a buck-only feature, as the one added by #96067 was too. As in, for cargo the problem should already solved because even if you specify some crate to be compiled as I guess this feature is the crate-level equivalent of the |
|
@rustbot blocked i'll create an MCP and then bump for review later EDIT: MCP rust-lang/compiler-team#605 |
|
Injecting I suggest directly calling |
|
@petrochenkov I think the injected crates are processed fully; following the lead of That said, I went with the AST approach because it seemed like a "complete" injection and I worried merely calling As an aside: with |
User code can refer to these (even to
These need to be in AST/HIR (or at least it's the simplest way to achieve the desired effect).
These are added only for linking side effect, so they can be added directly to |
|
thanks for those details! that all makes sense. |
2c5c361 to
698c24f
Compare
|
the MCP was seconded a week ago so I updated the PR to take @petrochenkov's suggestion: skip the @rustbot review |
698c24f to
76f076c
Compare
|
@rustbot review thanks for the feedback! |
f733c8b to
9a0ee5f
Compare
|
alright, the CI configuration + my copy of #111141 has been backed out. unlike the previous failed run, these logs don't print a line for each test so i can't explicitly confirm my tests ran, but this run has the same number of "ignored" tests as the failing one and everything else passed so we're probably good? i apologize for the noisy iterations, but thanks to y'all for the support! |
|
@bors r+ |
|
📌 Commit 9a0ee5fc73128c11b6b4657d86ab76c9f5f5ffc0 has been approved by It is now in the queue for this repository. |
|
⌛ Testing commit 9a0ee5fc73128c11b6b4657d86ab76c9f5f5ffc0 with merge ed03c68bf1780fb1a8050b6a57d3f177895e781a... |
|
💔 Test failed - checks-actions |
|
alright, this time i looked into the as windows doesn't pass this latest run was rebased past the process question: is there a tracking issue template i should use for this? i can't edit #98405 to link to a new issue, but i would be happy to file one and update the docs in this PR or a follow-up PR to follow suit with the other |
|
@bors r+ |
You can create a new tracking issue using those linked from #98405 as examples, and I'll then update #98405 to link to it. |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (333b920): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 653.613s -> 656.005s (0.37%) |
|
@jsgf @pcwalton i've been in touch with @capickett about this separately, but you may also be interested in this PR. it lets you build vendored |
When
--extern force:foo=libfoo.sois passed torustcandfoois not actually used in the crate,inject anforce it to be resolved anyway inextern crate foo;statement into the ASTCrateLoader::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 adylib. 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 newforceoption to thestddependency 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--externarguments have theforceoption and weren't already used, we inject anextern cratestatement for them. The injection logic was added inrustc_builtin_macrosas that's where similar injections for tests, proc-macros, and std/core already live.(New contributor - grateful for feedback and guidance!)