-
Notifications
You must be signed in to change notification settings - Fork 312
Make wit-parser support no_std
#2415
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
Make wit-parser support no_std
#2415
Conversation
temporarily use forked id-arena use alloc BTreeMap and BinaryHeap use alloc BTreeMap and BTreeSet instead of std HashMap and HashSet import misc items from core/alloc instead of std use core Error, FromStr, and Debug add std feature and gate things behind it use different IndexMap/IndexSet for std vs no_std misc alloc imports add cargo check update workspace anyhow fixes
6f16777 to
a2f35e3
Compare
|
Thanks for this! I think this is reasonable to support, but will require a bit of care in terms of ensuring the crate doesn't suffer too much in terms of maintainability burden. Everything here looks mostly on the right track, but wanted to leave a few comments. For For maps, I think we may want a bit of care there. The Does that sound reasonable to you? I realize it's a bit vague with the map bits, so I can try to poke at those too if I'm not making any sense. |
use new instead of default make HashMap newtype remove collections mod
9deb106 to
2e235f0
Compare
|
Thanks for the feedback @alexcrichton.
Yes everything runs through the
I looked through this and it uses the newtype pattern to abstract over In my latest commit I do something similar. It's less robust but I think more appropriate for this crate. I am unifying Your type alias idea " Personally I like the simplicty of using |
|
Ah the btree/indexmap/hashmap situation in wasmparser is largely borne out of the desire to have a cargo feature to switch between hashing and Another idea I've now had: reading over |
|
Using hashbrown's HashMap simplifies the implementation. Since the workspace manifest already depends on hashbrown with the |
alexcrichton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me, thanks! I've left some comments below, but as an additionally one I think it'd be reasonable to drop the update to the id-arena crate from this PR. That would mean the crate isn't actually no-std compatible nor could CI be updated, but that'll help decouple that dependency update from this PR while that's sorted out.
…builder instead of ahash's and remove ashash as a dep
…es which uses String instead of PathBuf
bf13296 to
95b2756
Compare
…s to resolve/mod.rs cleanup move logic from PackageSourceMap to PackageSources make methods public to avoid no_std flag
95b2756 to
8c463f6
Compare
|
Thanks for comments. There's now a #[cfg(feature = "std")]
mod fs;
#[cfg(feature = "std")]
pub use fs::PackageSourceMap;Because I made the My PR in |
alexcrichton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh fine to update here, just didn't want to unduly block on that. Thanks again for this and thank you for your work on this, it's much appreciated!
#2414
I followed a pattern similar to #2401 but this crate required more adjustments and was not as straightforward.
Currently the work depends on my fork of
id-arenawhich updates theno_stdimplementation. PR for that is here: fitzgen/id-arena#20. It's a very simple fix. Additionally I updated the workspaceanyhowdep todefault-features=falsewhich didn't seem to cause any issues.This work maintains the existing API without any breaking changes but puts the functions behind
stdflags. New methods added:SourceMap::push_str(&str, contents)- no_std version ofpush(&Path, contents)SourceMap::source_names()- no_std version ofsource_files()(returns&strinstead of&Path)UnresolvedPackageGroup::parse_str(path: &str, contents: &str)- no_std version ofparse(&Path)Resolve::push_group(UnresolvedPackageGroup)- already existed but now works in no_stdResolve::push_source(&str, &str)- no_std version ofpush_str(which uses Path)The existing
stdversions delegate to these newno_stdversions.Pathwas not really being "used" as just.display()was being called on it so&str/Stringare not a bad replacement in general.As
IndexSetandIndexMapare part of the "interface" of the crate I could not swap them out tohashbrownorBTree*. Instead I just use a different hash build (S) for the different "envs" (ahash::RandomStateforno_std) and switched to thedefaultconstructor instead ofnew.I've added a check in the github CI:
If an alternate strategy seems better I am happy to try that out. Thanks!