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

Pass rustc shim flags using environment variable #116448

Merged
merged 4 commits into from
Oct 12, 2023

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Oct 5, 2023

This PR implements a generalized way of passing of host flags to the rustc shim in bootstrap, as proposed here.

I tried to implement the bootstrap side using OsString, but then I realized that the shim code was using env::var before anyway, instead of env::var_os, so I just settled on a String. The shim side is still general and uses env::vars_os now.

I'm not sure if we actually need to do something with the rustdoc shim. It seems to me that the env. vars passed to it (RUSTDOC_LINKER) and (RUSTDOC_LLD_NO_THREADS) could just be passed to cargo directly (or rather, the commands that they invoke in the shim could be passed directly). I'm not sure why are they set by the shim.

r? @onur-ozkan
CC @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 5, 2023
src/bootstrap/builder.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

could just be passed to cargo directly

If something can be passed directly rather than through the shims, it certainly should be.
The shims only exist due to cargo deficiencies, the logic in them should be minimized when possible, and ideally they wouldn't exist at all.

@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 5, 2023

@petrochenkov The rustdoc linker flag was first added in #45191 😅 I don't understand the full context from the PR though, notably what is "...the issue with doctests...".

@petrochenkov
Copy link
Contributor

It was many years ago, I don't remember what was the issue exactly 🤦
But rustdoc needs linker because it compiles and runs code snippets in doc comments (doctests).

@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 5, 2023

But rustdoc needs linker because it compiles and runs code snippets in doc comments (doctests).

I'll send a PR where I'll try to pass the linker directly, without the shim. Seems to not crash locally.

@petrochenkov
Copy link
Contributor

But rustdoc needs linker because it compiles and runs code snippets in doc comments (doctests).

I'll send a PR where I'll try to pass the linker directly, without the shim. Seems to not crash locally.

It needs to be tested separately, the linker option in config.toml is not tested by CI, AFAIK.
I tested #45191 by setting [target.x86_64-unknown-linux-gnu] linker to my custom nonsensically named symlink and making sure there are no other linkers with standard names are in PATH.

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

thanks!

@onur-ozkan
Copy link
Member

@bors r+ rollup=iffy

@bors
Copy link
Contributor

bors commented Oct 5, 2023

📌 Commit eddbd7c has been approved by onur-ozkan

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 Oct 5, 2023
@Kobzol Kobzol changed the title Pass bootstrap shim flags using environment variables Pass bootstrap shim flags using environment variable Oct 5, 2023
@petrochenkov
Copy link
Contributor

I think rustdoc shim should also be migrated before merge, #116449 is unlikely to work.

@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 5, 2023

I would rather do these things in two separate PRs, if we needed to revert them in the future. I think that they are orthogonal (or not?).

@onur-ozkan onur-ozkan changed the title Pass bootstrap shim flags using environment variable Pass rustc shim flags using environment variable Oct 5, 2023
@onur-ozkan
Copy link
Member

Feel free to dequeue the PR if you want to handle rustdoc too in this PR.

@petrochenkov
Copy link
Contributor

@bors r-
Even for the rustc shim this PR seems to only scratch the surface.
The shim adds many compiler options, for both host and target, that can be passed in a pre-cooked way through the new env var, while in this PR even host options are not fully migrated.

I think, the only options that cannot be passed like this are those that inspect which specific crate we are building right now (e.g. inspect crate_name).

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 5, 2023
@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 5, 2023

else {
        // FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
        // here, but rather Cargo should know what flags to pass rustc itself.

        // Find any host flags that were passed by bootstrap.
        // The flags are stored in a RUSTC_HOST_FLAGS variable, separated by spaces.
        if let Ok(flags) = std::env::var("RUSTC_HOST_FLAGS") {
            for flag in flags.split(' ') {
                cmd.arg(flag);
            }
        }

        // Cargo doesn't pass RUSTFLAGS to proc_macros:
        // https://github.com/rust-lang/cargo/issues/4423
        // Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
        // We also declare that the flag is expected, which we need to do to not
        // get warnings about it being unexpected.
        if stage == "0" {
            cmd.arg("--cfg=bootstrap");
        }
        cmd.arg("-Zunstable-options");
        cmd.arg("--check-cfg=values(bootstrap)");
    }

This is (AFAIK) the only block that deals with host-only options. Do you want me to also pass these three options via the env. variable? Since they are either unconditional or dependent on stage, which is readily available, I thought that it would be easier to keep this in the shim. If we pass --cfg=bootstrap, we could remove passing the stage in theory, though.

@petrochenkov
Copy link
Contributor

Do you want me to also pass these three options via the env. variable?

Yes, if possible.
It fall under the general idea that ideally the shim shouldn't exist at all, that I mentioned above.

@rust-log-analyzer

This comment has been minimized.

@onur-ozkan onur-ozkan 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 Oct 11, 2023
@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 11, 2023

Looks like it might be spurious? I would just retry.

@onur-ozkan
Copy link
Member

@bors retry

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 11, 2023
@Kobzol
Copy link
Contributor Author

Kobzol commented Oct 11, 2023

@bors r=onur-ozkan,petrochenkov

@bors
Copy link
Contributor

bors commented Oct 11, 2023

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Oct 11, 2023

📌 Commit 3f9ab7a has been approved by onur-ozkan,petrochenkov

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 11, 2023

⌛ Testing commit 3f9ab7a with merge 9d1e4b7...

@bors
Copy link
Contributor

bors commented Oct 12, 2023

☀️ Test successful - checks-actions
Approved by: onur-ozkan,petrochenkov
Pushing 9d1e4b7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 12, 2023
@bors bors merged commit 9d1e4b7 into rust-lang:master Oct 12, 2023
12 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 12, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9d1e4b7): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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

mean range count
Regressions ❌
(primary)
3.9% [2.2%, 5.5%] 2
Regressions ❌
(secondary)
1.8% [1.8%, 1.8%] 1
Improvements ✅
(primary)
-3.9% [-5.6%, -2.5%] 3
Improvements ✅
(secondary)
-2.2% [-2.7%, -1.6%] 2
All ❌✅ (primary) -0.8% [-5.6%, 5.5%] 5

Cycles

Results

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

mean range count
Regressions ❌
(primary)
0.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
2.1% [2.1%, 2.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.8%, 0.8%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 626.264s -> 629.226s (0.47%)
Artifact size: 271.33 MiB -> 271.32 MiB (-0.01%)

@Kobzol Kobzol deleted the bootstrap-host-flags branch October 12, 2023 05:44
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 12, 2023
48: Pull upstream master 2023 10 12 r=tshepang a=Dajamante

* rust-lang/rust#113487
* rust-lang/rust#116506
* rust-lang/rust#116448
* rust-lang/rust#116640
  * rust-lang/rust#116627
  * rust-lang/rust#116597
  * rust-lang/rust#116436
  * rust-lang/rust#116315
  * rust-lang/rust#116219
* rust-lang/rust#113218
* rust-lang/rust#115937
* rust-lang/rust#116014
* rust-lang/rust#116623
* rust-lang/rust#112818
* rust-lang/rust#115948
* rust-lang/rust#116622
* rust-lang/rust#116621
  * rust-lang/rust#116612
  * rust-lang/rust#116611
  * rust-lang/rust#116530
  * rust-lang/rust#95967
* rust-lang/rust#116578
* rust-lang/rust#113915
* rust-lang/rust#116605
  * rust-lang/rust#116574
  * rust-lang/rust#116560
  * rust-lang/rust#116559
  * rust-lang/rust#116503
  * rust-lang/rust#116444
  * rust-lang/rust#116250
  * rust-lang/rust#109422
* rust-lang/rust#116598
  * rust-lang/rust#116596
  * rust-lang/rust#116595
  * rust-lang/rust#116589
  * rust-lang/rust#116586
* rust-lang/rust#116551
* rust-lang/rust#116409
* rust-lang/rust#116548
* rust-lang/rust#116366
* rust-lang/rust#109882
* rust-lang/rust#116497
* rust-lang/rust#116532
* rust-lang/rust#116569
  * rust-lang/rust#116561
  * rust-lang/rust#116556
  * rust-lang/rust#116549
  * rust-lang/rust#116543
  * rust-lang/rust#116537
  * rust-lang/rust#115882
* rust-lang/rust#116142
* rust-lang/rust#115238
* rust-lang/rust#116533
* rust-lang/rust#116096
* rust-lang/rust#116468
* rust-lang/rust#116515
* rust-lang/rust#116454
* rust-lang/rust#116183
* rust-lang/rust#116514
* rust-lang/rust#116509
* rust-lang/rust#116487
* rust-lang/rust#116486
* rust-lang/rust#116450
* rust-lang/rust#114623
* rust-lang/rust#116416
* rust-lang/rust#116437
* rust-lang/rust#100806
* rust-lang/rust#116330
* rust-lang/rust#116310
* rust-lang/rust#115583
* rust-lang/rust#116457
* rust-lang/rust#116508
* rust-lang/rust#109214
* rust-lang/rust#116318
* rust-lang/rust#116501
  * rust-lang/rust#116500
  * rust-lang/rust#116458
  * rust-lang/rust#116400
  * rust-lang/rust#116277
* rust-lang/rust#114709
* rust-lang/rust#116492
  * rust-lang/rust#116484
  * rust-lang/rust#116481
  * rust-lang/rust#116474
  * rust-lang/rust#116466
  * rust-lang/rust#116423
  * rust-lang/rust#116297
  * rust-lang/rust#114564
* rust-lang/rust#114811
* rust-lang/rust#116489
* rust-lang/rust#115304

Co-authored-by: Peter Hall <peter.hall@hyperexponential.com>
Co-authored-by: Emanuele Vannacci <emanuele.vannacci@gmail.com>
Co-authored-by: Neven Villani <vanille@crans.org>
Co-authored-by: Alex Macleod <alex@macleod.io>
Co-authored-by: Tamir Duberstein <tamird@gmail.com>
Co-authored-by: Eduardo Sánchez Muñoz <eduardosm-dev@e64.io>
Co-authored-by: koka <koka.code@gmail.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Camille GILLOT <gillot.camille@gmail.com>
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Co-authored-by: Ralf Jung <post@ralfj.de>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 13, 2023
48: Pull upstream master 2023 10 12 r=tshepang a=Dajamante

* rust-lang/rust#113487
* rust-lang/rust#116506
* rust-lang/rust#116448
* rust-lang/rust#116640
  * rust-lang/rust#116627
  * rust-lang/rust#116597
  * rust-lang/rust#116436
  * rust-lang/rust#116315
  * rust-lang/rust#116219
* rust-lang/rust#113218
* rust-lang/rust#115937
* rust-lang/rust#116014
* rust-lang/rust#116623
* rust-lang/rust#112818
* rust-lang/rust#115948
* rust-lang/rust#116622
* rust-lang/rust#116621
  * rust-lang/rust#116612
  * rust-lang/rust#116611
  * rust-lang/rust#116530
  * rust-lang/rust#95967
* rust-lang/rust#116578
* rust-lang/rust#113915
* rust-lang/rust#116605
  * rust-lang/rust#116574
  * rust-lang/rust#116560
  * rust-lang/rust#116559
  * rust-lang/rust#116503
  * rust-lang/rust#116444
  * rust-lang/rust#116250
  * rust-lang/rust#109422
* rust-lang/rust#116598
  * rust-lang/rust#116596
  * rust-lang/rust#116595
  * rust-lang/rust#116589
  * rust-lang/rust#116586
* rust-lang/rust#116551
* rust-lang/rust#116409
* rust-lang/rust#116548
* rust-lang/rust#116366
* rust-lang/rust#109882
* rust-lang/rust#116497
* rust-lang/rust#116532
* rust-lang/rust#116569
  * rust-lang/rust#116561
  * rust-lang/rust#116556
  * rust-lang/rust#116549
  * rust-lang/rust#116543
  * rust-lang/rust#116537
  * rust-lang/rust#115882
* rust-lang/rust#116142
* rust-lang/rust#115238
* rust-lang/rust#116533
* rust-lang/rust#116096
* rust-lang/rust#116468
* rust-lang/rust#116515
* rust-lang/rust#116454
* rust-lang/rust#116183
* rust-lang/rust#116514
* rust-lang/rust#116509
* rust-lang/rust#116487
* rust-lang/rust#116486
* rust-lang/rust#116450
* rust-lang/rust#114623
* rust-lang/rust#116416
* rust-lang/rust#116437
* rust-lang/rust#100806
* rust-lang/rust#116330
* rust-lang/rust#116310
* rust-lang/rust#115583
* rust-lang/rust#116457
* rust-lang/rust#116508
* rust-lang/rust#109214
* rust-lang/rust#116318
* rust-lang/rust#116501
  * rust-lang/rust#116500
  * rust-lang/rust#116458
  * rust-lang/rust#116400
  * rust-lang/rust#116277
* rust-lang/rust#114709
* rust-lang/rust#116492
  * rust-lang/rust#116484
  * rust-lang/rust#116481
  * rust-lang/rust#116474
  * rust-lang/rust#116466
  * rust-lang/rust#116423
  * rust-lang/rust#116297
  * rust-lang/rust#114564
* rust-lang/rust#114811
* rust-lang/rust#116489
* rust-lang/rust#115304

Co-authored-by: Emanuele Vannacci <emanuele.vannacci@gmail.com>
Co-authored-by: Neven Villani <vanille@crans.org>
Co-authored-by: Alex Macleod <alex@macleod.io>
Co-authored-by: Tamir Duberstein <tamird@gmail.com>
Co-authored-by: Eduardo Sánchez Muñoz <eduardosm-dev@e64.io>
Co-authored-by: koka <koka.code@gmail.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Camille GILLOT <gillot.camille@gmail.com>
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: ShE3py <52315535+she3py@users.noreply.github.com>
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request Nov 9, 2023
…ozkan

Restore rustc shim error message

Fixes: rust-lang#117595 (comment)

The error message was originally introduced in rust-lang#111323, and subsequently broken by my change in rust-lang#116448.

r? `@onur-ozkan`
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request Nov 9, 2023
…ozkan

Restore rustc shim error message

Fixes: rust-lang#117595 (comment)

The error message was originally introduced in rust-lang#111323, and subsequently broken by my change in rust-lang#116448.

r? ``@onur-ozkan``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2023
Rollup merge of rust-lang#117724 - Kobzol:shim-error-message, r=onur-ozkan

Restore rustc shim error message

Fixes: rust-lang#117595 (comment)

The error message was originally introduced in rust-lang#111323, and subsequently broken by my change in rust-lang#116448.

r? ``@onur-ozkan``
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2023
…rochenkov

Pass flags to `rustdoc` shim without env. vars

Discussed here: rust-lang#116448 (comment). Since it was not really documented why these flags were passed through the shim, I guess that the only way to find out if it's really needed... is to remove it :)

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2023
…rochenkov

Pass flags to `rustdoc` shim without env. vars

Discussed here: rust-lang#116448 (comment). Since it was not really documented why these flags were passed through the shim, I guess that the only way to find out if it's really needed... is to remove it :)

r? `@petrochenkov`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 25, 2023
Pass flags to `rustdoc` shim without env. vars

Discussed here: rust-lang/rust#116448 (comment). Since it was not really documented why these flags were passed through the shim, I guess that the only way to find out if it's really needed... is to remove it :)

r? `@petrochenkov`
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
Pass flags to `rustdoc` shim without env. vars

Discussed here: rust-lang/rust#116448 (comment). Since it was not really documented why these flags were passed through the shim, I guess that the only way to find out if it's really needed... is to remove it :)

r? `@petrochenkov`
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Pass flags to `rustdoc` shim without env. vars

Discussed here: rust-lang/rust#116448 (comment). Since it was not really documented why these flags were passed through the shim, I guess that the only way to find out if it's really needed... is to remove it :)

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants