Skip to content
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

Add force option for --extern flag #605

Closed
3 tasks done
mhammerly opened this issue Mar 21, 2023 · 3 comments
Closed
3 tasks done

Add force option for --extern flag #605

mhammerly opened this issue Mar 21, 2023 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@mhammerly
Copy link

mhammerly commented Mar 21, 2023

Proposal

See also: rust-lang/rust#109421

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. 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.

The AST injection in the linked PR happens after macro expansion around where the compiler similarly injects 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 the compilation session's --extern arguments have the force option and aren't in that list, the compiler injects 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.

Documentation for this option should be added to the "--extern Options" page of the Rust Unstable book.

The particular situation prompting this MCP is a project to integrate Rust into a preexisting large C/C++ codebase. To summarize: this codebase builds with Buck and ships on, among other platforms, Android. When targeting Android, Buck builds "native" code with shared linkage so that it can be loaded by Java/Kotlin, and the project's many #![no_std] dependencies failed to build as they lacked a panic handler. With this change, that project can add a force option to the existing std dependency it specifies on every crate and solve the problem.

nounused (from rust-lang/rust#96067) is a similar Buck-centric --extern option.

Mentors or Reviewers

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@mhammerly mhammerly added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Mar 21, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 21, 2023

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Mar 21, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 23, 2023
@pnkfelix
Copy link
Member

pnkfelix commented Apr 6, 2023

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Apr 6, 2023
@apiraino
Copy link
Contributor

@rustbot label -final-comment-period +major-change-accepted

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Apr 17, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants