Skip to content
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

Merged
merged 23 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e1a6e5
Switch to edition 2021 and resolver 2
bushrat011899 Mar 3, 2025
2486df2
Add useful `no_std` lints
bushrat011899 Mar 3, 2025
75c1cad
Update dependencies and features
bushrat011899 Mar 3, 2025
03c1dd9
Increase MSRV to 1.67
bushrat011899 Mar 3, 2025
4babadc
Switch to derived `Default`
bushrat011899 Mar 3, 2025
c05aad0
Suppress `clippy::should_implement_trait`
bushrat011899 Mar 3, 2025
59c3075
Remove redundant `into()` calls
bushrat011899 Mar 3, 2025
68b6071
Suppress `clippy::too_many_arguments`
bushrat011899 Mar 3, 2025
82c96b2
Remove redundant references
bushrat011899 Mar 3, 2025
b899925
Use `ilog10` in `count_digits`
bushrat011899 Mar 3, 2025
1d0bac9
Use of `format` is redundant
bushrat011899 Mar 3, 2025
3e333fa
Simplify `assert_eq!` statements
bushrat011899 Mar 3, 2025
95f5294
Implement `termcolor` feature gating
bushrat011899 Mar 3, 2025
af7c140
Add `no_std` support
bushrat011899 Mar 3, 2025
f079d1e
Added `check-no-std` to CI
bushrat011899 Mar 3, 2025
584f995
Fixes from CI run
bushrat011899 Mar 3, 2025
0bf71d2
Switch from underscore to `allow(unused)`
bushrat011899 Mar 8, 2025
128a6b2
Document clippy lints
bushrat011899 Mar 8, 2025
4df2c28
Fix `check-no-std`
bushrat011899 Mar 8, 2025
1130af9
Merge remote-tracking branch 'upstream/master' into no_std
bushrat011899 Mar 8, 2025
049900f
Format
bushrat011899 Mar 8, 2025
4382b81
Remove `serde/rc` from `codespan-reporting/serialization`
bushrat011899 Mar 8, 2025
b26948f
Test all combinations before giving up on `check-no-std`
bushrat011899 Mar 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: ["1.46.0", "stable", "beta", "nightly"]
rust: ["1.67.0", "stable", "beta", "nightly"]
name: Check (${{ matrix.rust }})
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -53,11 +53,43 @@ jobs:
command: check
args: --manifest-path "codespan-lsp/Cargo.toml"

check-no-std:
name: Check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust:
- "1.84.0"
- "stable"
- "beta"
- "nightly"
target:
- "x86_64-unknown-none"
- "wasm32v1-none"
- "thumbv6m-none-eabi"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- name: Run cargo check for codespan-reporting
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path "codespan-reporting/Cargo.toml" --no-default-features --features "serialization" --target ${{ matrix.target }}
- name: Run cargo check for codespan
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path "codespan/Cargo.toml" --no-default-features --features "serialization" --target ${{ matrix.target }}

test:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: ["1.46.0", "stable", "beta", "nightly"]
rust: ["1.67.0", "stable", "beta", "nightly"]
name: Test Suite (${{ matrix.rust }})
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -95,7 +127,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: ["1.46.0", "stable", "beta", "nightly"]
rust: ["1.67.0", "stable", "beta", "nightly"]
name: Rustfmt (${{ matrix.rust }})
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ members = [
"./codespan-reporting",
"./codespan-lsp",
]
resolver = "2"
2 changes: 1 addition & 1 deletion codespan-lsp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Copy link
Collaborator

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 👍

Copy link
Contributor Author

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!

This is because some dependencies now require this Rust version.

### Changed
Expand Down
18 changes: 16 additions & 2 deletions codespan-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@ description = "Conversions between codespan types and Language Server Protocol t
homepage = "https://github.com/brendanzab/codespan"
repository = "https://github.com/brendanzab/codespan"
documentation = "https://docs.rs/codespan-lsp"
edition = "2018"
edition = "2021"
rust-version = "1.67"

[dependencies]
codespan-reporting = { version = "0.11.1", path = "../codespan-reporting" }
codespan-reporting = { version = "0.11.1", path = "../codespan-reporting", features = [
"std",
"termcolor",
] }
# WARNING: Be extremely careful when expanding this version range.
# We should be confident that all of the uses of `lsp-types` in `codespan-lsp`
# will be valid for all the versions in this range. Getting this range wrong
# could potentially break down-stream builds on a `cargo update`. This is an
# absolute no-no, breaking much of what we enjoy about Cargo!
lsp-types = ">=0.84, <0.92"
url = "2"

[lints.clippy]
# Certain items from `core` are re-exported in `alloc` and `std`, and likewise `alloc` has items
# re-exported in `std`.
# `core` is available on all platforms, `alloc` is available on almost all, and `std` is only
# available on some.
# These lints ensure we don't import from a "less available" crate without reason.
alloc_instead_of_core = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
8 changes: 7 additions & 1 deletion codespan-lsp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Utilities for translating from codespan types into Language Server Protocol (LSP) types

#![forbid(unsafe_code)]
#![no_std]

use std::ops::Range;
#[cfg(test)]
extern crate alloc;

use core::ops::Range;

use codespan_reporting::files::{Error, Files};

Expand Down Expand Up @@ -139,6 +143,8 @@ where

#[cfg(test)]
mod tests {
use alloc::string::ToString;

use codespan_reporting::files::{Location, SimpleFiles};

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions codespan-reporting/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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`).
This is because some testing dependencies now require this Rust version.
The minimum supported rustc version is now `1.67.0` (was `1.40.0`).
This is because some dependencies now require this Rust version.

### Added

Expand Down
22 changes: 18 additions & 4 deletions codespan-reporting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ homepage = "https://github.com/brendanzab/codespan"
repository = "https://github.com/brendanzab/codespan"
documentation = "https://docs.rs/codespan-reporting"
exclude = ["assets/**"]
edition = "2018"
edition = "2021"
rust-version = "1.67"

[dependencies]
serde = { version = "1", optional = true, features = ["derive"] }
termcolor = "1.0.4"
serde = { version = "1", default-features = false, optional = true, features = ["derive", "alloc"] }
termcolor = { version = "1.0.4", optional = true }
unicode-width = ">=0.1,<0.3"

[dev-dependencies]
Expand All @@ -26,5 +27,18 @@ rustyline = "6"
unindent = "0.1"

[features]
serialization = ["serde", "serde/rc"]
default = ["std", "termcolor"]
Copy link
Collaborator

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)

Copy link
Contributor Author

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.

std = ["serde?/std"]
termcolor = ["std", "dep:termcolor"]
serialization = ["serde"]
ascii-only = []

[lints.clippy]
# Certain items from `core` are re-exported in `alloc` and `std`, and likewise `alloc` has items
# re-exported in `std`.
# `core` is available on all platforms, `alloc` is available on almost all, and `std` is only
# available on some.
# These lints ensure we don't import from a "less available" crate without reason.
alloc_instead_of_core = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
8 changes: 4 additions & 4 deletions codespan-reporting/examples/custom_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::term;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use std::ops::Range;
use core::ops::Range;

fn main() -> anyhow::Result<()> {
let mut files = files::Files::new();
Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() -> anyhow::Result<()> {
/// A module containing the file implementation
mod files {
use codespan_reporting::files;
use std::ops::Range;
use core::ops::Range;

/// A file that is backed by an `Arc<String>`.
#[derive(Debug, Clone)]
Expand All @@ -57,7 +57,7 @@ mod files {

impl File {
fn line_start(&self, line_index: usize) -> Result<usize, files::Error> {
use std::cmp::Ordering;
use core::cmp::Ordering;

match line_index.cmp(&self.line_starts.len()) {
Ordering::Less => Ok(*self
Expand Down Expand Up @@ -95,7 +95,7 @@ mod files {
name: impl Into<String>,
source: impl Into<String>,
) -> Option<FileId> {
use std::convert::TryFrom;
use core::convert::TryFrom;

let file_id = FileId(u32::try_from(self.files.len()).ok()?);
let name = name.into();
Expand Down
3 changes: 2 additions & 1 deletion codespan-reporting/examples/readme_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fn main() -> anyhow::Result<()> {
let mut buffer = Vec::new();
let mut writer = HtmlEscapeWriter::new(SvgWriter::new(&mut buffer));
let config = codespan_reporting::term::Config {
#[cfg(feature = "termcolor")]
styles: codespan_reporting::term::Styles::with_blue(Color::Blue),
..codespan_reporting::term::Config::default()
};
Expand Down Expand Up @@ -187,7 +188,7 @@ fn main() -> anyhow::Result<()> {
)?;
}
Opts::Stderr { color } => {
let writer = StandardStream::stderr(color.into());
let writer = StandardStream::stderr(color);
let config = codespan_reporting::term::Config::default();
for diagnostic in &diagnostics {
term::emit(&mut writer.lock(), &config, &file, diagnostic)?;
Expand Down
4 changes: 2 additions & 2 deletions codespan-reporting/examples/reusable_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFile;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use codespan_reporting::term::{self};
use std::ops::Range;
use core::ops::Range;

#[derive(Debug)]
pub struct Opts {
Expand Down Expand Up @@ -39,7 +39,7 @@ fn main() -> anyhow::Result<()> {
];

let Opts { color } = parse_args()?;
let writer = StandardStream::stderr(color.into());
let writer = StandardStream::stderr(color);
let config = codespan_reporting::term::Config::default();
for diagnostic in errors.iter().map(Error::report) {
term::emit(&mut writer.lock(), &config, &file, &diagnostic)?;
Expand Down
2 changes: 1 addition & 1 deletion codespan-reporting/examples/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn main() -> anyhow::Result<()> {
)]),
];

let writer = StandardStream::stderr(color.into());
let writer = StandardStream::stderr(color);
let config = codespan_reporting::term::Config::default();
for diagnostic in &diagnostics {
term::emit(&mut writer.lock(), &config, &files, diagnostic)?;
Expand Down
22 changes: 16 additions & 6 deletions codespan-reporting/src/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//! Diagnostic data structures.

use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::ops::Range;

#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::ops::Range;
use std::string::ToString;

/// A severity level for diagnostic messages.
///
Expand Down Expand Up @@ -188,9 +192,12 @@ impl<FileId> Diagnostic<FileId> {
self.labels.append(&mut labels);
self
}

/// Add some labels to the diagnostic.
pub fn with_labels_iter(mut self, labels: impl IntoIterator<Item = Label<FileId>>) -> Diagnostic<FileId> {
pub fn with_labels_iter(
mut self,
labels: impl IntoIterator<Item = Label<FileId>>,
) -> Diagnostic<FileId> {
self.labels.extend(labels);
self
}
Expand All @@ -206,9 +213,12 @@ impl<FileId> Diagnostic<FileId> {
self.notes.append(&mut notes);
self
}

/// Add some notes to the diagnostic.
pub fn with_notes_iter(mut self, notes: impl IntoIterator<Item = String>) -> Diagnostic<FileId> {
pub fn with_notes_iter(
mut self,
notes: impl IntoIterator<Item = String>,
) -> Diagnostic<FileId> {
self.notes.extend(notes);
self
}
Expand Down
Loading
Loading