-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add no_std
Support
#374
Add no_std
Support
#374
Conversation
This is effectively required for `no_std` support, as without it, dev-dependencies will enable features on regular dependencies, making it impossible to have `std` tests in `no_std` crates.
These clippy lints highlight cases where an import is referencing `std` or `alloc` when it instead could import from `alloc` or `core`. This helps expose the "true" extent of `std` usage in a crate.
`termcolor` is incompatible with `no_std`, but `codespan` and `codespan-reporting` have valid use even without this crate. Making it optional allows `no_std` to be entirely decided by the contents of the codespan crates themselves. Serde is also `no_std` compatible, as long as we disable default features.
During testing, `unicode-width` caused `cargo msrv find` to report `codespan-reporting`'s MSRV was 1.66, violating the current MSRV of 1.46. Since this is already the case, and there are features in 1.67, such as ilog10, which are desired within this crate, I have increased the MSRV to 1.67.
Before making substantive changes, `clippy` reported that these implementations for default can be derived. I have done so to silence the lint.
`Span::from_str` shadows `FromStr::from_str`. Instead of breaking the public API, I added an explicit `allow`
Caught by clippy, and actioned to reduce warnings
`Renderer::render_snippet_source` has too many arguments. Instead of breaking the public API, I'm suppressing this lint.
These double-references are automatically dereferenced anyway.
Increasing MSRV allows using the new `ilog10` method, solving a long-standing TODO
`ToString::to_string()` is preferred by `clippy` for converting `str` to `String`
`assert_eq` on a boolean is linted against by `clippy`, suggesting to use `assert!` instead.
The `Styles` type is only needed for controlling colour, which is only needed with `termcolor`. Since we only deal with UTF8 strings, `std::fmt::Write` is equivalent to `WriteColor` when colour isn't required.
Switch imports to relying on `core` and `alloc`. `std::io::Write` can be replaced by `core::fmt::Write` since we deal exclusively with UTF8 strings.
This checks for `no_std` compatibility on 3 key targets: - `x86_64-unknown-none`: represents desktop `no_std`, such as in kernels - `wasm32v1-none`: represents Web builds using the most broadly support WASM target -`thumbv6m-none-eabi`: represents typical embedded targets, such as the Raspberry Pi Pico Testing on all three platforms ensures the widest possible compatibility.
Thanks for the change, would be good if this crate can work in more places! (I need to update the CI, ignore the other errors) but I think Will review the code before merging later this week ~ Thursday/Friday. |
- `cargo fmt` - Fix typo in `ci.yml` which misused the matrix
Ran |
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.
Looks good!
I think the WASM CI needs some changes as it is currently showing error: component 'rust-std' for target 'wasm32v1-none' is unavailable for download for channel '1.82.0'
.
Once that is resolved and the new job is green I will merge.
I have mentioned a few other things that you can (but don't necessarily need to) amend.
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
## [Unreleased] | |||
|
|||
The minimum supported rustc version is now `1.46.0` (was `1.40.0`). | |||
The minimum supported rustc version is now `1.67.0` (was `1.40.0`). |
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.
I think this is a reasonable demand in 2025 👍
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.
Yeah I think it's been long enough haha!
@@ -26,5 +27,13 @@ rustyline = "6" | |||
unindent = "0.1" | |||
|
|||
[features] | |||
default = ["std", "termcolor"] |
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.
Nice, adding default
should not cause breaking changes (unless a dependent specified no-default-features
which would be pointless)
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.
Yeah it's still technically a breaking change semantically, so you'll want to bump the version number for a release, but it's the nice kind of breaking change where migrating should be just enabling these features.
// Use a saturating_add because in that edge case the number of digits | ||
// will not be changed. | ||
(n.saturating_add(1) as f64).log10().ceil() as usize | ||
n.ilog10() as usize + 1 |
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.
I see that rust-lang/rust#70887 was resolved. I think this is okay to be sneaked into this pr 👍
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.
Yeah without this change the MSRV is 1.66, and with it's 1.67, so I figured why not, I'm already bumping the MSRV, and it actually solves a problem too, since no_std
removes some of the floating point operations like log10
!
Co-Authored-By: Ben <[email protected]>
Co-Authored-By: Ben <[email protected]>
`wasm32v1-none` was only added in 1.84, so I've set that as the earliest Rust version used for testing `no_std` compatibility. Note that it's typical for embedded development to be done on nightly anyway, so `no_std` will usually happen on the very latest version of Rust.
Conflicts resolved and review items addressed. I believe the CI task should pass now too! |
Not currently used and is incompatible with `thumbv6m-none-eabi`
Fixed a minor issue with |
This comment was marked as outdated.
This comment was marked as outdated.
Co-Authored-By: Ben <[email protected]>
Stable check, test, format all work as well on these new targets! Thanks for the quick updates. Anything else before merge? Once merged, I will hopefully have a release within the next 7 days. Just waiting for some publishing keys from the owner of the repository :) |
Nope, I think this should be good to go! Thanks for being so receptive to the changes. Looking forward to the new release! |
Objective
Add
no_std
support tocodespan-reporting
, allowing its use in initiatives such aswasm32v1-none
support inwgpu
.Solution
termcolor
, as it does not haveno_std
support#![no_std]
to all 3 crates. Noting thatcodespan-lsp
does not haveno_std
support aslsp-types
does not haveno_std
support.std
andtermcolor
features tocodespan-reporting
andcodespan
, which are both enabled by default.clippy
Notes
This is my first time contributing to this project. I have attempted to split my changes into meaningful commits with descriptions as described in the
CONTRIBUTING.md
document. Please let me know if there's anything I can do to assist with reviewing and merging this PR.