Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# The file is the workflow for rustfmt
#
# It runs `cargo fmt --check`
#
# It will fail if there are formatting problems.
on: [push, pull_request]
name: rustfmt

env:
CARGO_TERM_COLOR: always

jobs:
rustfmt:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- shell: bash
run: |
cargo fmt --all -- --check
23 changes: 23 additions & 0 deletions .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Checks spelling with typos
# This has very few false positives, only checking for known misspellings (similar to codespell).
# This action is based on https://github.com/crate-ci/typos/blob/master/docs/github-action.md
name: Check Spelling
on: [push, pull_request]

env:
CLICOLOR: 1

permissions:
contents: read

jobs:
typos:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

name: Check spelling with typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Run typos (pinned version)
uses: crate-ci/typos@v1.35.6
174 changes: 174 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# We use `actions-rs` for most of our actions
#
# This file is for the main tests. clippy & rustfmt are separate workflows
on: [push, pull_request]
name: Cargo Test

env:
CARGO_TERM_COLOR: always
# has a history of occasional bugs (especially on old versions)
#
# the ci is free so we might as well use it ;)
CARGO_INCREMENTAL: 0



jobs:
test:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

runs-on: ubuntu-latest
strategy:
fail-fast: false # Even if one job fails we still want to see the other ones
matrix:
rust:
# Minimum Supported Rust Version
#
# This is hardcoded and needs to be in sync with Cargo.toml and the README
#
# If one of the features does not support this MSRV,
# you need to remove this from the main list and manually add the desired
# feature/version combinations to 'include'
# This hack is not currently needed because serde-erased v0.3 supports our MSRV.
- 1.63

# Intermediate Releases (between MSRV and latest stable)
# Be careful not to add these needlessly; they hold up CI

# The most recent version of stable rust (automatically updated)
- stable
- nightly
# NOTE: Features to test must be specified manually. They are applied to all versions separately.
features:
- "std"
- "std bytemuck slog serde"
include:
- rust: stable
features: "std parking_lot"
- rust: nightly
features: "nightly" # no features except nightly
- rust: nightly
features: "nightly alloc" # no features except nightly + alloc
- rust: nightly
features: "std nightly"
- rust: nightly
features: "std unique-wrap-std nightly"
- rust: nightly
features: "std nightly parking_lot"
- rust: nightly
features: "std nightly parking_lot bytemuck slog serde"
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Cache Cargo Registry
id: cache-index
uses: actions/cache@v4
with:
path:
# Before the sparse index, updating the registry took forever
~/.cargo/registry/index/
key: ${{ runner.os }}-cargo-${{ matrix.rust }}
restore-keys: |
${{ runner.os }}-cargo-
continue-on-error: false
- name: Test
# NOTE: Running --all-targets does not include doc tests
# Does not compile benchmarks because they break on MSRV. Still checked by clippy
run: |
cargo test --all --verbose --no-default-features --features "${{ matrix.features }}" --exclude "benchmarks"

clippy:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust:
# in hardcoded versions, warnings will fail the build
- 1.89
# in auto-updated versions, warnings will not fail the build
- stable
- nightly
features:
# NOTE: Unfortunately, the benchmarks crate implicitly requires 'std'
- "std parking_lot bytemuck slog serde"
include:
- rust: nightly
features: "std slog bytemuck parking_lot serde nightly"
- rust: nightly
features: "std nightly unique-wrap-std"

steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy
- name: Clippy
run: |
cargo clippy --all --all-targets --verbose --no-default-features --features "${{ matrix.features }}" -- -D warnings
# When using hardcoded/pinned versions, warnings are forbidden.
#
# On automatically updated versions of rust (both stable & nightly) we allow clippy to fail.
# This is because automatic updates can introduce new lints or change existing lints.
continue-on-error: ${{ !contains(matrix.rust, '1.') }}

docs:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: "-D warnings"
strategy:
fail-fast: false
matrix:
rust:
- nightly
- stable
features:
- "std parking_lot bytemuck slog serde"
include:
- rust: nightly
features: "std parking_lot bytemuck slog serde nightly nightly-docs"
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Docs
run: |
cargo doc --verbose --no-default-features --features "${{ matrix.features }}"
cargo-rdme:
# Only run on PRs if the source branch is on someone else's repo
if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
components: rust-src
# need to cache cargo-rdme to avoid redundant install
- name: Cache Binaries
id: cache-binaries
uses: actions/cache@v4
with:
path:
~/.cargo/bin/cargo-rdme
key: ${{ runner.os }}-binary-cargo-rdme
- name: Install cargo-rdme
shell: bash
# NOTE: This doesn't worry about installing updates
run: |
if not test -f "~/.cargo/bin/cargo-rdme"; then
cargo install cargo-rdme
fi
- name: Run cargo-rdme
run: |
cargo rdme --check
26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "threadid"
description = "Fast and flexible thread identifiers"
version = "0.1.0-alpha.1"
version = "0.1.0"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/Techcable/threadid.rs"
edition = "2021"
Expand All @@ -10,6 +10,8 @@ edition = "2021"
# 1.61 - dep:foo and foo?/std syntax
# 1.63 - const Mutex::new
rust-version = "1.63"
categories = ["concurrency", "development-tools::debugging", "no-std", "no-std::no-alloc"]
keywords = ["threadid", "tid", "name"]

[dependencies]
cfg-if = "1"
Expand All @@ -18,19 +20,16 @@ portable-atomic = { version = "1", features = ["require-cas"] }
nonmax = { version = "0.5", default-features = false }
# optional
parking_lot = { version = "0.12", optional = true }
serde = { version = "1", optional = true, features = ["derive"] }
serde = { version = "1", optional = true }
slog = { version = "2.6", optional = true, default-features = false }
bytemuck = { version = "1.23", optional = true, features = ["derive"] }
bytemuck = { version = "1.23", optional = true }

[dev-dependencies]
# criterion = "0.7"
crossbeam-utils = "0.8"

[[bench]]
name = "access"
required-features = []
harness = false
test = false
[[example]]
name = "thread_name"
required-features = ["std"]

[features]
default = ["std"]
Expand All @@ -42,7 +41,7 @@ alloc = []
nightly = ["parking_lot?/nightly"]
# Enables serde serialization for most types
#
# Deserialization can not be reasonbly implemented
# Deserialization can not be reasonably implemented
serde = ["dep:serde", "nonmax/serde"]
# Implements slog::Value for most types
slog = ["dep:slog"]
Expand All @@ -64,3 +63,10 @@ parking_lot = ["dep:parking_lot"]
# By default, this is implicitly enabled on nightly + std,
# this feature only makes the requirement explicit.
unique-wrap-std = ["std"]

[package.metadata.docs.rs]
all-features = true

[workspace]
members = [".", "benchmarks"]
resolver = "2"
19 changes: 19 additions & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "threadid-benchmarks"
description = "Benchmarks for the threadid crate"
version = "0.0.0"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/Techcable/threadid.rs"
publish = false # internal use only
edition = "2021"

[dev-dependencies]
threadid.path = ".."
criterion = "0.7"
crossbeam-utils = "0.8"

[[bench]]
name = "access"
required-features = []
harness = false
test = false
2 changes: 2 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Benchmarks for thraedid.rs
Separate from the main crate to avoid compiling criterion and because the MSRV is different.
2 changes: 2 additions & 0 deletions benches/access.rs → benchmarks/benches/access.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::redundant_closure)] // slightly cleaner

use criterion::{Criterion, criterion_group, criterion_main};
use threadid::{LiveThreadId, StdThreadId, UniqueThreadId};

Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
)]

#[cfg(not(any(feature = "nightly", feature = "std")))]
compile_error!("Either the `nightly` or `std` feature must be enabled for this crate to work");

#[cfg(all(feature = "unique-wrap-std", not(feature = "nightly")))]
compile_error!("The `unique-wrap-std` feature currently requires the `nightly` feature to be enabled");
compile_error!("The `threadid` crate requires at least one of the `nightly` or `std` features");

#[cfg(feature = "alloc")]
extern crate alloc;
Expand All @@ -70,9 +67,12 @@ pub use unique::UniqueThreadId;
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub use self::std::StdThreadId;

#[macro_use]
mod utils;
#[macro_use]
mod locals;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub mod debug;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
Expand All @@ -81,7 +81,6 @@ pub mod live;
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub mod std;
pub mod unique;
mod utils;

/// Defines methods common to all thread ids.
///
Expand Down
5 changes: 4 additions & 1 deletion src/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::utils::sync::{Mutex, MutexGuard};
/// It is guaranteed that `Option<LiveThreadId>` has the same representation as `LiveThreadId`.
/// Currently [`LiveThreadId::to_int`] can be zero, reducing wasted indexes.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[must_use]
#[repr(transparent)]
pub struct LiveThreadId {
Expand Down Expand Up @@ -112,13 +111,17 @@ impl LiveThreadId {
self.index.get()
}
}
simple_serde_serialize!(LiveThreadId, |this| this.to_int());
#[cfg(feature = "bytemuck")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "bytemuck")))]
// SAFETY: We wrap a NonMax, which has the same niche as NonZero
unsafe impl bytemuck::ZeroableInOption for LiveThreadId {}
#[cfg(feature = "bytemuck")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "bytemuck")))]
// SAFETY: A NonMax is equivalent to a NonZero
unsafe impl bytemuck::NoUninit for LiveThreadId {}
#[cfg(feature = "slog")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "slog")))]
impl slog::Value for LiveThreadId {
fn serialize(&self, _record: &slog::Record, key: slog::Key, serializer: &mut dyn slog::Serializer) -> slog::Result {
serializer.emit_arguments(key, &format_args!("{self:?}"))
Expand Down
Loading
Loading