Skip to content

bootstrap: add explicit UTF-8 encoding to text-mode open() calls#152536

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ozankenangungor:bootstrap-explicit-open-encoding
Feb 14, 2026
Merged

bootstrap: add explicit UTF-8 encoding to text-mode open() calls#152536
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ozankenangungor:bootstrap-explicit-open-encoding

Conversation

@ozankenangungor
Copy link

@ozankenangungor ozankenangungor commented Feb 12, 2026

Make text-mode open() calls in bootstrap.py
explicitly use encoding="utf-8".

This avoids relying on platform-dependent default encodings
when running Python < 3.15.

Binary-mode opens remain unchanged.

Copilot AI review requested due to automatic review settings February 12, 2026 14:02
@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 Feb 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

This comment was marked as spam.

@Kobzol
Copy link
Member

Kobzol commented Feb 12, 2026

If the script sets r, it should already be assumed to be text, this is only a concern when there was no "r"/"rb" specified, no?

@apiraino
Copy link
Contributor

And please @ozankenangungor don't invoke Copilot in this project.

@ozankenangungor
Copy link
Author

Apologies, I won’t invoke Copilot again in this repository.

Regarding the change: my understanding was that the issue aimed to avoid relying on the platform/locale-dependent default encoding, even in text mode. For that reason, I added encoding="utf-8" to existing text-mode open() calls and left binary opens unchanged.

If this is broader than intended, I’m happy to narrow the scope to only the cases where no mode/encoding was specified.

@workingjubilee
Copy link
Member

issue? what issue?

@ozankenangungor
Copy link
Author

I was referring to #152510.

@jieyouxu
Copy link
Member

jieyouxu commented Feb 13, 2026

If the script sets r, it should already be assumed to be text, this is only a concern when there was no "r"/"rb" specified, no?

Looks like in the "r" case up to Python 3.14.* (https://docs.python.org/3/library/functions.html#open), it will use a platform-dependent locale under text mode. "rb" is different because that produces a byte stream. It also seems like "r" is the default mode, so leaving "r" out is equivalent to specifying "r".

I'm fine with the change itself, however @ozankenangungor can you please double-check your PR description

The change is purely mechanical and does not alter behavior.

This is not true and why #152485 and thus #152510 exist in the first place, because the behavior is different when you specifying an explicit UTF-8 encoding or not on Python < 3.15. We want to "alter behavior" so it doesn't randomly choke on user systems (read: Windows) with different default locales.

Tested with:
./x.py test bootstrap

I don't see how that tests the Python script? The change itself seems fine, just that ./x test bootstrap doesn't test the effect of this change.

@rustbot author

@rustbot rustbot 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 Feb 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 13, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@ozankenangungor
Copy link
Author

Since the associated issue #152510 has been closed as not planned,
I will close this PR as well.

Thanks for the review and clarification.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 13, 2026
@jieyouxu
Copy link
Member

@ozankenangungor sorry, to be clear, I'm fine with the changes in this PR (just with slightly fixed PR description), I closed the issue as not-planned because it's not super accurate. Your change might potentially help if user is using Windows with non-UTF-8 locale plus they are using Python < 3.15 (which is still in pre-release, plus some users will be stuck on < 3.15 for a while anyway).

@ozankenangungor
Copy link
Author

ozankenangungor commented Feb 13, 2026

Thanks for the clarification. I assumed that since the issue was closed as not planned, the PR was no longer desired that was my mistake. I will reopen the PR and adjust the description.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 13, 2026
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.

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 13, 2026

📌 Commit 9448bdf has been approved by jieyouxu

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Feb 13, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 13, 2026
…-open-encoding, r=jieyouxu

bootstrap: add explicit UTF-8 encoding to text-mode open() calls

Make text-mode `open()` calls in `bootstrap.py`
explicitly use `encoding="utf-8"`.

This avoids relying on platform-dependent default encodings
when running Python < 3.15.

Binary-mode opens remain unchanged.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 13, 2026
…-open-encoding, r=jieyouxu

bootstrap: add explicit UTF-8 encoding to text-mode open() calls

Make text-mode `open()` calls in `bootstrap.py`
explicitly use `encoding="utf-8"`.

This avoids relying on platform-dependent default encodings
when running Python < 3.15.

Binary-mode opens remain unchanged.
rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #152323 (Fix ICE in borrowck when recovering `fn_sig` for `-> _`)
 - #152469 (Remove unused features)
 - #152515 (Extract `DepKindVTable` constructors to their own module)
 - #152555 (Port `#[rustc_diagnostic_item]` to the new attribute parsers)
 - #152218 (Report unconstrained region in hidden types lazily)
 - #152356 (Improve the `inline_fluent!` macro)
 - #152392 (Fix ICE in supertrait_vtable_slot when supertrait has missing generics)
 - #152407 (Add regression test for type_const with unit struct ctor under mGCA)
 - #152440 (Fix typos and grammar in compiler and build documentation)
 - #152536 (bootstrap: add explicit UTF-8 encoding to text-mode open() calls)
 - #152554 (Remove `deprecated_safe` and its corresponding feature gate)
 - #152556 (doc: move riscv64a23-unknown-linux-gnu to tier 2)
 - #152563 (Replace "bug" with "issue" in triagebot ping messages)
 - #152565 (fix missleading error for tuple ctor)

Failed merges:

 - #152512 (core: Implement feature `float_exact_integer_constants`)
 - #152296 (Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser)
rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #152323 (Fix ICE in borrowck when recovering `fn_sig` for `-> _`)
 - #152469 (Remove unused features)
 - #152515 (Extract `DepKindVTable` constructors to their own module)
 - #152555 (Port `#[rustc_diagnostic_item]` to the new attribute parsers)
 - #152218 (Report unconstrained region in hidden types lazily)
 - #152356 (Improve the `inline_fluent!` macro)
 - #152392 (Fix ICE in supertrait_vtable_slot when supertrait has missing generics)
 - #152407 (Add regression test for type_const with unit struct ctor under mGCA)
 - #152440 (Fix typos and grammar in compiler and build documentation)
 - #152536 (bootstrap: add explicit UTF-8 encoding to text-mode open() calls)
 - #152554 (Remove `deprecated_safe` and its corresponding feature gate)
 - #152556 (doc: move riscv64a23-unknown-linux-gnu to tier 2)
 - #152563 (Replace "bug" with "issue" in triagebot ping messages)
 - #152565 (fix missleading error for tuple ctor)

Failed merges:

 - #152512 (core: Implement feature `float_exact_integer_constants`)
 - #152296 (Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser)
@rust-bors rust-bors bot merged commit 9ca0ebb into rust-lang:main Feb 14, 2026
27 of 28 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 14, 2026
rust-timer added a commit that referenced this pull request Feb 14, 2026
Rollup merge of #152536 - ozankenangungor:bootstrap-explicit-open-encoding, r=jieyouxu

bootstrap: add explicit UTF-8 encoding to text-mode open() calls

Make text-mode `open()` calls in `bootstrap.py`
explicitly use `encoding="utf-8"`.

This avoids relying on platform-dependent default encodings
when running Python < 3.15.

Binary-mode opens remain unchanged.
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-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.

6 participants