Skip to content

Commit

Permalink
add features for kurbo's std/libm features (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel McNab <[email protected]>
  • Loading branch information
ratmice and DJMcNab authored Feb 14, 2024
1 parent 50f256d commit e8e53e4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
53 changes: 32 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,34 @@ jobs:
# - name: restore cache
# uses: Swatinem/rust-cache@v2

# We don't currently have features, so there's no need to run these checks
# - name: cargo clippy (no default features)
# run: cargo clippy --workspace --lib --bins --no-default-features -- -D warnings
- name: cargo clippy (no default features with libm)
run: cargo clippy --workspace --lib --bins --no-default-features --features libm -- -D warnings

# - name: cargo clippy (no default features) (auxiliary)
# run: cargo clippy --workspace --tests --benches --examples --no-default-features -- -D warnings
- name: cargo clippy (no default features with libm) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples --no-default-features --features libm -- -D warnings

- name: cargo clippy (default features)
run: cargo clippy --workspace --lib --bins -- -D warnings

- name: cargo clippy (default features) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples -- -D warnings

# As above
# - name: cargo clippy (all features)
# run: cargo clippy --workspace --lib --bins --all-features -- -D warnings
- name: cargo clippy (all features)
run: cargo clippy --workspace --lib --bins --all-features -- -D warnings

# - name: cargo clippy (all features) (auxiliary)
# run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings
- name: cargo clippy (all features) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings

# At the time of writing, we don't have any tests. Nevertheless, it's better to still run this
- name: cargo test
run: cargo test --workspace --all-features


- run: rustup target add armv7a-none-eabi

# We use armv7a as a no_std with AtomicU64
- name: cargo build (no-default-features + libm, no_std target)
run: cargo build --no-default-features --features libm --target armv7a-none-eabi

clippy-msrv:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -100,25 +104,29 @@ jobs:
toolchain: ${{ env.MINIMUM_SUPPORTED_RUST_VERSION }}
components: clippy

# We don't currently have features, so there's no need to run these checks
# - name: cargo clippy (no default features)
# run: cargo clippy --workspace --lib --bins --no-default-features -- -D warnings
- name: cargo clippy (no default features with libm)
run: cargo clippy --workspace --lib --bins --no-default-features --features libm -- -D warnings

# - name: cargo clippy (no default features) (auxiliary)
# run: cargo clippy --workspace --tests --benches --examples --no-default-features -- -D warnings
- name: cargo clippy (no default features with libm) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples --no-default-features --features libm -- -D warnings

- name: cargo clippy (default features)
run: cargo clippy --workspace --lib --bins -- -D warnings -A clippy::doc_markdown

- name: cargo clippy (default features) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples -- -D warnings -A clippy::doc_markdown

# As above
# - name: cargo clippy (all features)
# run: cargo clippy --workspace --lib --bins --all-features -- -D warnings
- name: cargo clippy (all features)
run: cargo clippy --workspace --lib --bins --all-features -- -D warnings

# - name: cargo clippy (all features) (auxiliary)
# run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings
- name: cargo clippy (all features) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings

- run: rustup target add armv7a-none-eabi

# We use armv7a as a no_std with AtomicU64
- name: cargo build (no-default-features + libm, no_std target)
run: cargo build --no-default-features --features libm --target armv7a-none-eabi

clippy-stable-wasm:
runs-on: ubuntu-latest
Expand All @@ -136,6 +144,9 @@ jobs:
- name: cargo clippy (wasm)
run: cargo clippy --all-targets --target wasm32-unknown-unknown -- -D warnings

- name: cargo build (no-default-features + libm, wasm32)
run: cargo build --no-default-features --features libm --target wasm32-unknown-unknown

docs:
name: cargo doc
runs-on: ${{ matrix.os }}
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ readme = "README.md"
rust-version = "1.70"

[features]
# If adding the first feature, also enable the relevant sections of .github/workflows/ci.yaml
# (then remove this comment)
default = ["std"]
std = ["kurbo/std"]
libm = ["kurbo/libm"]

[dependencies]
kurbo = "0.10.2"
kurbo = { version = "0.11", default-features = false }
smallvec = "1.8.0"
9 changes: 6 additions & 3 deletions src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright 2022 The peniko authors.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::fmt;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Weak};
use core::fmt;
use core::sync::atomic::{AtomicU64, Ordering};
extern crate alloc;
use alloc::boxed::Box;
use alloc::sync::{Arc, Weak};
use alloc::vec::Vec;

/// Shared data with an associated unique identifier.
pub struct Blob<T> {
Expand Down
5 changes: 4 additions & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

// Borrows code heavily from the piet (https://github.com/linebender/piet/) Color
// type.
#[cfg(all(not(feature = "std"), feature = "libm"))]
#[allow(unused_imports)]
use kurbo::common::FloatFuncs as _;

/// 32-bit RGBA color.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
Expand Down Expand Up @@ -93,7 +96,7 @@ impl Color {
3. * d * d * (t - 4. / 29.)
}
}
let th = h * (std::f64::consts::PI / 180.);
let th = h * (core::f64::consts::PI / 180.);
let a = c * th.cos();
let b = c * th.sin();
let ll = (l + 16.) * (1. / 116.);
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//!
//! [`kurbo`]: https://crates.io/crates/kurbo

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
// doc_markdown was updated in https://github.com/rust-lang/rust-clippy/pull/11735
// to be more accurate, but our MSRV is earlier than that
#![cfg_attr(not(peniko_msrv), warn(clippy::doc_markdown))]
Expand Down

0 comments on commit e8e53e4

Please sign in to comment.