no_std for wtf8, sre_engine, compiler-core, literal#7051
no_std for wtf8, sre_engine, compiler-core, literal#7051youknowone merged 2 commits intoRustPython:mainfrom
Conversation
📝 WalkthroughWalkthroughMultiple crates migrate to no_std compilation by adding Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/wtf8/src/lib.rs`:
- Around line 36-46: The workspace dependency for itertools must be configured
for no_std; update the Cargo.toml entry for itertools to disable default
features and enable its alloc support by setting itertools = { version =
"0.14.0", default-features = false, features = ["use_alloc"] } so the crate
using #![no_std] and alloc (see extern crate alloc and uses like
itertools::Either / itertools::Itertools) compiles without pulling in std.
| #![no_std] | ||
| #![allow(clippy::precedence, clippy::match_overlapping_arm)] | ||
|
|
||
| extern crate alloc; | ||
|
|
||
| use alloc::borrow::{Cow, ToOwned}; | ||
| use alloc::boxed::Box; | ||
| use alloc::collections::TryReserveError; | ||
| use alloc::string::String; | ||
| use alloc::vec::Vec; | ||
| use core::borrow::Borrow; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
fd 'Cargo.toml' crates/wtf8 --exec cat {}Repository: RustPython/RustPython
Length of output: 458
🏁 Script executed:
grep -A 50 '\[workspace\.dependencies\]' Cargo.toml | head -100Repository: RustPython/RustPython
Length of output: 2625
🏁 Script executed:
# Check the actual lib.rs to see import usage and configuration
head -100 crates/wtf8/src/lib.rsRepository: RustPython/RustPython
Length of output: 3814
🏁 Script executed:
# Check how itertools and bstr are used in the code
rg -n "itertools::" crates/wtf8/src/ -A 2Repository: RustPython/RustPython
Length of output: 211
🏁 Script executed:
# Search for actual usage of Either, Itertools, ByteSlice, ByteVec
rg "Either|Itertools|ByteSlice|ByteVec" crates/wtf8/src/ --max-count=20Repository: RustPython/RustPython
Length of output: 364
🏁 Script executed:
# Check for any cargo features or configuration related to no_std in wtf8
rg "feature\|no_std" crates/wtf8/ -B 2 -A 2Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
# Check if there are any tests or CI configuration that builds with no_std
fd 'Cargo.toml|\.rs' crates/wtf8 --exec grep -l "no_std\|no-std" {}Repository: RustPython/RustPython
Length of output: 87
🏁 Script executed:
# Let's check if bstr crate documentation or source indicates no_std requirements
# First, let me see if there's a Cargo.lock or any evidence of successful builds
git log --oneline crates/wtf8/Cargo.toml | head -5Repository: RustPython/RustPython
Length of output: 122
🏁 Script executed:
# Check the commit that added no_std support to see what pattern was used
git show 2c5ece945 --stat | head -30Repository: RustPython/RustPython
Length of output: 1737
🏁 Script executed:
# Check if wtf8 was included in that commit and see what changes were made
git show 2c5ece945 -- crates/wtf8/ | head -200Repository: RustPython/RustPython
Length of output: 6676
🏁 Script executed:
# Check if there's any .cargo/config.toml configuration related to building crates
cat .cargo/config.toml | head -50Repository: RustPython/RustPython
Length of output: 343
🏁 Script executed:
# Check if there are any actual usages of ascii and memchr
rg "ascii::|memchr::" crates/wtf8/src/ -A 2Repository: RustPython/RustPython
Length of output: 1327
🏁 Script executed:
# Check if any of the dependencies have been explicitly configured for no_std elsewhere
# Let's search for how other no_std crates in the workspace handle dependencies
rg "default-features.*false" Cargo.toml | head -20Repository: RustPython/RustPython
Length of output: 576
🏁 Script executed:
# Check if there are any tests or build configurations that verify no_std compilation
rg "no.std|no-std" . --type toml | head -20Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
# Let me verify if these specific dependency versions support no_std out of the box
# by checking their documentation or configuration patterns used elsewhere in the repo
python3 << 'EOF'
# Check if other crates in the workspace use similar dependencies
import subprocess
import re
# Search for patterns of how dependencies are configured in Cargo.toml files
result = subprocess.run(['rg', 'ascii|bstr|itertools|memchr', '--type', 'toml', '-B2', '-A2'],
capture_output=True, text=True)
print(result.stdout)
EOFRepository: RustPython/RustPython
Length of output: 47
🌐 Web query:
itertools 0.14.0 no_std alloc feature requirements
💡 Result:
For itertools = 0.14.0, std is enabled by default (default = ["use_std"]). The crate’s features are: use_std (which implies use_alloc) and use_alloc alone. [1][2]
no_std + alloc (no std)
Use default-features = false and enable use_alloc:
[dependencies]
itertools = { version = "0.14.0", default-features = false, features = ["use_alloc"] }This avoids use_std (and thus avoids enabling either/use_std) while allowing the parts of itertools that rely on alloc. [1][2]
no_std without alloc (core-only)
Disable default features and don’t enable use_alloc:
[dependencies]
itertools = { version = "0.14.0", default-features = false }(You can only use the subset of itertools that doesn’t require allocation.) [1][2]
Note: In a #![no_std] binary, alloc-using code also requires that your target provides the alloc crate and that you have a global allocator available at link/runtime. [1]
Sources: [1] Cargo.toml for itertools 0.14.0 on docs.rs, [2] docs.rs feature flags page.
itertools requires explicit no_std configuration — add default-features = false, features = ["use_alloc"] to the workspace dependency.
The crate uses #![no_std] with itertools::Either and itertools::Itertools, but itertools 0.14.0 defaults to use_std. Update the workspace dependency in Cargo.toml:
itertools = { version = "0.14.0", default-features = false, features = ["use_alloc"] }The other dependencies (ascii, bstr, memchr) support no_std with their default configurations.
🤖 Prompt for AI Agents
In `@crates/wtf8/src/lib.rs` around lines 36 - 46, The workspace dependency for
itertools must be configured for no_std; update the Cargo.toml entry for
itertools to disable default features and enable its alloc support by setting
itertools = { version = "0.14.0", default-features = false, features =
["use_alloc"] } so the crate using #![no_std] and alloc (see extern crate alloc
and uses like itertools::Either / itertools::Itertools) compiles without pulling
in std.
Summary by CodeRabbit
New Features
Refactor