From 2fa0d3f5b2b7ac11ef1751c133706f29e548bd6d Mon Sep 17 00:00:00 2001 From: Matt Campbell Date: Tue, 22 Oct 2024 04:36:12 -0500 Subject: [PATCH] feat!: Make the core crate no-std (#468) --- common/Cargo.toml | 2 +- common/src/geometry.rs | 16 +--------------- common/src/lib.rs | 7 ++++++- consumer/Cargo.toml | 1 - platforms/atspi-common/Cargo.toml | 1 + platforms/macos/Cargo.toml | 1 + platforms/unix/Cargo.toml | 1 - platforms/windows/Cargo.toml | 1 - platforms/winit/Cargo.toml | 1 - 9 files changed, 10 insertions(+), 21 deletions(-) diff --git a/common/Cargo.toml b/common/Cargo.toml index 238f4e9ba..c7ac1d824 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -18,7 +18,7 @@ features = ["schemars", "serde"] enumn = { version = "0.1.6", optional = true } pyo3 = { version = "0.20", optional = true } schemars = { version = "0.8.7", optional = true } -serde = { version = "1.0", features = ["derive"], optional = true } +serde = { version = "1.0", default-features = false, features = ["alloc", "derive"], optional = true } [features] enumn = ["dep:enumn"] diff --git a/common/src/geometry.rs b/common/src/geometry.rs index 6c9446136..fe04c62cf 100644 --- a/common/src/geometry.rs +++ b/common/src/geometry.rs @@ -9,7 +9,7 @@ // the LICENSE-APACHE file) or the MIT license (found in // the LICENSE-MIT file), at your option. -use std::{ +use core::{ fmt, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; @@ -67,20 +67,6 @@ impl Affine { Affine([s_x, 0.0, 0.0, s_y, 0.0, 0.0]) } - /// An affine transform representing rotation. - /// - /// The convention for rotation is that a positive angle rotates a - /// positive X direction into positive Y. Thus, in a Y-down coordinate - /// system (as is common for graphics), it is a clockwise rotation, and - /// in Y-up (traditional for math), it is anti-clockwise. - /// - /// The angle, `th`, is expressed in radians. - #[inline] - pub fn rotate(th: f64) -> Affine { - let (s, c) = th.sin_cos(); - Affine([c, s, -s, c, 0.0, 0.0]) - } - /// An affine transform representing translation. #[inline] pub fn translate>(p: V) -> Affine { diff --git a/common/src/lib.rs b/common/src/lib.rs index db5a6a82c..7f0805f66 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -8,6 +8,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE.chromium file. +#![cfg_attr(not(any(feature = "pyo3", feature = "schemars")), no_std)] + +extern crate alloc; + +use alloc::{boxed::Box, string::String, vec::Vec}; +use core::fmt; #[cfg(feature = "pyo3")] use pyo3::pyclass; #[cfg(feature = "schemars")] @@ -22,7 +28,6 @@ use serde::{ ser::{SerializeMap, Serializer}, Deserialize, Serialize, }; -use std::fmt; mod geometry; pub use geometry::{Affine, Point, Rect, Size, Vec2}; diff --git a/consumer/Cargo.toml b/consumer/Cargo.toml index fa53e0daf..1fb31d987 100644 --- a/consumer/Cargo.toml +++ b/consumer/Cargo.toml @@ -14,4 +14,3 @@ rust-version.workspace = true [dependencies] accesskit = { version = "0.16.3", path = "../common" } immutable-chunkmap = "2.0.5" - diff --git a/platforms/atspi-common/Cargo.toml b/platforms/atspi-common/Cargo.toml index c95c53efc..ad8d144fd 100644 --- a/platforms/atspi-common/Cargo.toml +++ b/platforms/atspi-common/Cargo.toml @@ -21,3 +21,4 @@ atspi-common = { version = "0.6", default-features = false } serde = "1.0" thiserror = "1.0" zvariant = { version = "4.2", default-features = false } + diff --git a/platforms/macos/Cargo.toml b/platforms/macos/Cargo.toml index a3914ca8e..ce1bd461c 100644 --- a/platforms/macos/Cargo.toml +++ b/platforms/macos/Cargo.toml @@ -34,3 +34,4 @@ objc2-app-kit = { version = "0.2.0", features = [ "NSView", "NSWindow", ] } + diff --git a/platforms/unix/Cargo.toml b/platforms/unix/Cargo.toml index 77e1d4cd5..e1906efda 100644 --- a/platforms/unix/Cargo.toml +++ b/platforms/unix/Cargo.toml @@ -36,4 +36,3 @@ tokio-stream = { version = "0.1.14", optional = true } version = "1.32.0" optional = true features = ["macros", "net", "rt", "sync", "time"] - diff --git a/platforms/windows/Cargo.toml b/platforms/windows/Cargo.toml index 7593eaedf..db54ccbac 100644 --- a/platforms/windows/Cargo.toml +++ b/platforms/windows/Cargo.toml @@ -37,4 +37,3 @@ features = [ once_cell = "1.13.0" scopeguard = "1.1.0" winit = "0.30" - diff --git a/platforms/winit/Cargo.toml b/platforms/winit/Cargo.toml index d590f7648..6cb38c7db 100644 --- a/platforms/winit/Cargo.toml +++ b/platforms/winit/Cargo.toml @@ -40,4 +40,3 @@ accesskit_unix = { version = "0.12.3", path = "../unix", optional = true, defaul version = "0.30" default-features = false features = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] -