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

Overhaul the -l option parser (for linking to native libs) #132934

Merged
merged 4 commits into from
Nov 18, 2024

Conversation

Zalathar
Copy link
Contributor

The current parser for -l options has accumulated over time, making it hard to follow. This PR tries to clean it up in several ways.

Key changes:

  • This code now gets its own submodule, to slightly reduce clutter in rustc_session::config.
  • Cleaner division between iterating over multiple -l options, and processing each individual one.
  • Separate “split” step that breaks up the value string into [KIND[:MODIFIERS]=]NAME[:NEW_NAME], but leaves parsing/validating those parts to later steps.
    • This step also gets its own (disposable) unit test, to make sure it works as expected.
  • A context struct reduces the burden of parameter passing, and makes it easier to write error messages that adapt to nightly/stable compilers.
  • Fewer calls to nightly_options helper functions, because at this point we can get the same information from UnstableOptions and UnstableFeatures (which are downstream of earlier calls to those helper functions).

There should be no overall change in compiler behaviour.

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2024
@Nadrieril
Copy link
Member

Nadrieril commented Nov 12, 2024

@petrochenkov did you try to take the assignment for yourself or was this you changing your mind?

@petrochenkov
Copy link
Contributor

@Nadrieril
It was a reminder for myself to take a look, which I indeed took later (there are several hours between assignment and unassignment).

@Nadrieril
Copy link
Member

r? compiler

@rustbot rustbot assigned TaKO8Ki and unassigned Nadrieril Nov 15, 2024
@jieyouxu
Copy link
Member

r? jieyouxu

@rustbot rustbot assigned jieyouxu and unassigned TaKO8Ki Nov 16, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, AFAICT this looks good.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 17, 2024

@Zalathar one question: do we want any dedicated UI tests for the failure cases (if not already)? But otherwise r=me.

@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 17, 2024
@Zalathar
Copy link
Contributor Author

(Rebased; no changes.)

Still looking into the test situation; it does seem a bit worrying.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 18, 2024

Yeah. AFAICT this has very sparse coverage (esp. for the more complex cases). It would be very cool if we can figure out some way to test this (like making the intermediate parsing outcome unit testable before it gets fed to library searching).

@Zalathar
Copy link
Contributor Author

Zalathar commented Nov 18, 2024

Decided that I don't want to fall too far down the rabbit-hole of adding tests, so I added just a few that I noticed were conspicuously missing (diff).

(Also note that one of these tests found a bug in one of the error messages, which had accidentally swapped the nightly and stable messages. The new implementation gets this correct.)

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 18, 2024
@Zalathar
Copy link
Contributor Author

It would be very cool if we can figure out some way to test this (like making the intermediate parsing outcome unit testable before it gets fed to library searching).

I do have some unit tests for one of the important intermediate steps (split_native_lib_value). Adding unit tests for NativeLib output should be viable, though I'll leave that for future work.

@Zalathar
Copy link
Contributor Author

@bors r=jieyouxu rollup

@bors
Copy link
Contributor

bors commented Nov 18, 2024

📌 Commit 78edefe has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 18, 2024
Overhaul the `-l` option parser (for linking to native libs)

The current parser for `-l` options has accumulated over time, making it hard to follow. This PR tries to clean it up in several ways.

Key changes:
- This code now gets its own submodule, to slightly reduce clutter in `rustc_session::config`.
- Cleaner division between iterating over multiple `-l` options, and processing each individual one.
- Separate “split” step that breaks up the value string into `[KIND[:MODIFIERS]=]NAME[:NEW_NAME]`, but leaves parsing/validating those parts to later steps.
  - This step also gets its own (disposable) unit test, to make sure it works as expected.
- A context struct reduces the burden of parameter passing, and makes it easier to write error messages that adapt to nightly/stable compilers.
- Fewer calls to `nightly_options` helper functions, because at this point we can get the same information from `UnstableOptions` and `UnstableFeatures` (which are downstream of earlier calls to those helper functions).

There should be no overall change in compiler behaviour.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
Rollup of 4 pull requests

Successful merges:

 - rust-lang#132934 (Overhaul the `-l` option parser (for linking to native libs))
 - rust-lang#133142 (rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect)
 - rust-lang#133145 (Document alternatives to `static mut`)
 - rust-lang#133158 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
Rollup of 4 pull requests

Successful merges:

 - rust-lang#132934 (Overhaul the `-l` option parser (for linking to native libs))
 - rust-lang#133142 (rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect)
 - rust-lang#133145 (Document alternatives to `static mut`)
 - rust-lang#133158 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 21654a2 into rust-lang:master Nov 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
Rollup merge of rust-lang#132934 - Zalathar:native-libs, r=jieyouxu

Overhaul the `-l` option parser (for linking to native libs)

The current parser for `-l` options has accumulated over time, making it hard to follow. This PR tries to clean it up in several ways.

Key changes:
- This code now gets its own submodule, to slightly reduce clutter in `rustc_session::config`.
- Cleaner division between iterating over multiple `-l` options, and processing each individual one.
- Separate “split” step that breaks up the value string into `[KIND[:MODIFIERS]=]NAME[:NEW_NAME]`, but leaves parsing/validating those parts to later steps.
  - This step also gets its own (disposable) unit test, to make sure it works as expected.
- A context struct reduces the burden of parameter passing, and makes it easier to write error messages that adapt to nightly/stable compilers.
- Fewer calls to `nightly_options` helper functions, because at this point we can get the same information from `UnstableOptions` and `UnstableFeatures` (which are downstream of earlier calls to those helper functions).

There should be no overall change in compiler behaviour.
@Zalathar Zalathar deleted the native-libs branch November 18, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants