Skip to content

internal: use std as extern crate#6054

Open
Person-93 wants to merge 1 commit into
PyO3:mainfrom
Person-93:extern_std
Open

internal: use std as extern crate#6054
Person-93 wants to merge 1 commit into
PyO3:mainfrom
Person-93:extern_std

Conversation

@Person-93

@Person-93 Person-93 commented May 18, 2026

Copy link
Copy Markdown
Contributor

This PR is to prepare for no_std support.

  • I've made the main crate no_std and added extern crate std instead.
  • I've also added a new top-level mod platform to hold all the upcoming std replacements. As of now, it just has a prelude which contains
    • Things from the alloc crate people generate use from std's prelude
    • the eprintln macro (we will need to find a replacement for this)
  • I've added import crate::platform::prelude::* to every file that uses things from the standard prelude.
  • The test_utils file could not import the prelude so it had to import directly from the alloc crate.
  • in py_format macro: replace use of ToOwned with Clone

ETA: It looks like a large PR because of the number of files changed, but most of that is just importing the new prelude into the files that need it. There are only four files that have more changes than that.

@Person-93 Person-93 force-pushed the extern_std branch 2 times, most recently from c683aa6 to 43509a5 Compare May 18, 2026 07:30
@Person-93 Person-93 marked this pull request as draft May 18, 2026 07:38
@Person-93 Person-93 force-pushed the extern_std branch 11 times, most recently from ecec57a to 3461bb7 Compare May 18, 2026 09:17
@Person-93 Person-93 marked this pull request as ready for review May 18, 2026 09:42
@Person-93 Person-93 changed the title use std as extern crate internal: use std as extern crate May 24, 2026
@Person-93 Person-93 force-pushed the extern_std branch 2 times, most recently from 4dedc7a to 17559a0 Compare May 26, 2026 20:34
Comment thread src/conversions/bytes.rs
Comment on lines +71 to +72
#[allow(unused_imports, reason = "used to build docs")]
use crate::platform::prelude::*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be hard to apply the correct cfg() clauses on these? That way we can clean up if the imports ever become unused rather than this line just floating around indefinitely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It wouldn't be hard to apply, but it'd cause more churn as files get updated and start/stop using things from the prelude.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Understood, will leave as is for now, I might seek to tighten this later.

Comment thread src/platform.rs
Comment on lines +13 to +14
// TODO find a `no_std` replacement for eprintln
pub use std::eprintln;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the two uses are in print_panic_and_unwind and PyUntypedBuffer::drop.

I think we can probably eliminate the PyUntypedBuffer::drop case eventually, I think implementing GC traversal might want to be unsafe with the user responsible for no side effects.

print_panic_and_unwind - I suspect that the behavior is unhelpful anyway, if there's a lot of rust and python frames interleaved I think this'll amplify the traceback a lot. Perhaps we can explore both the rust-embeds-python and python-embeds-rust cases to check what the best experience would be in each case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can that be a separate PR?

I'd like to keep this one as small as possible so it can be merged sooner. This PR is very likely to fail in the merge queue any time any other PR gets merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, absolutely, I was primarily suggesting we might be able to avoid the need to find a replacement.

@davidhewitt

Copy link
Copy Markdown
Member

Let's merge this to unblock proceeding on this work.

@davidhewitt davidhewitt added this pull request to the merge queue Jun 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jun 9, 2026
@davidhewitt

Copy link
Copy Markdown
Member

I can fix the conflicts after #6056 merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants