From bf84bb2ab6e552df92c32876da7042f8c3005ed0 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 30 Nov 2021 14:54:45 +0100 Subject: [PATCH] Make floating point operations compile with no_std Use num_traits and libm instead, also for euclid. --- sixtyfps_runtime/corelib/Cargo.toml | 3 +++ sixtyfps_runtime/corelib/graphics/brush.rs | 3 +++ sixtyfps_runtime/corelib/graphics/color.rs | 3 +++ sixtyfps_runtime/corelib/items/text.rs | 3 +++ sixtyfps_runtime/corelib/model.rs | 3 +++ 5 files changed, 15 insertions(+) diff --git a/sixtyfps_runtime/corelib/Cargo.toml b/sixtyfps_runtime/corelib/Cargo.toml index 34d759902..a98f64b4f 100644 --- a/sixtyfps_runtime/corelib/Cargo.toml +++ b/sixtyfps_runtime/corelib/Cargo.toml @@ -27,6 +27,8 @@ default = ["std"] # from a single core, and not in a interrupt or signal handler. unsafe_single_core = [] +libm = ["num-traits/libm", "euclid/libm"] + [dependencies] const-field-offset = { version = "0.1", path = "../../helper_crates/const-field-offset" } vtable = { version="0.1.1", path = "../../helper_crates/vtable" } @@ -52,6 +54,7 @@ unicode-segmentation = "1.8.0" rgb = "0.8.27" pin-project = "1" atomic-polyfill = { version = "0.1.5" } +num-traits = { version = "0.2", default-features = false } [target.'cfg(target_arch = "wasm32")'.dependencies] instant = { version = "0.1", features = [ "wasm-bindgen", "now" ] } diff --git a/sixtyfps_runtime/corelib/graphics/brush.rs b/sixtyfps_runtime/corelib/graphics/brush.rs index 4ec7c9179..483dff7c4 100644 --- a/sixtyfps_runtime/corelib/graphics/brush.rs +++ b/sixtyfps_runtime/corelib/graphics/brush.rs @@ -15,6 +15,9 @@ use super::{Color, Point}; use crate::properties::InterpolatedPropertyValue; use crate::SharedVector; +#[cfg(not(feature = "std"))] +use num_traits::float::Float; + /// A brush is a data structure that is used to describe how /// a shape, such as a rectangle, path or even text, shall be filled. /// A brush can also be applied to the outline of a shape, that means diff --git a/sixtyfps_runtime/corelib/graphics/color.rs b/sixtyfps_runtime/corelib/graphics/color.rs index f46d26469..432a73997 100644 --- a/sixtyfps_runtime/corelib/graphics/color.rs +++ b/sixtyfps_runtime/corelib/graphics/color.rs @@ -13,6 +13,9 @@ This module contains color related types for the run-time library. use crate::properties::InterpolatedPropertyValue; +#[cfg(not(feature = "std"))] +use num_traits::float::Float; + /// RgbaColor stores the red, green, blue and alpha components of a color /// with the precision of the generic parameter T. For example if T is f32, /// the values are normalized between 0 and 1. If T is u8, they values range diff --git a/sixtyfps_runtime/corelib/items/text.rs b/sixtyfps_runtime/corelib/items/text.rs index bfa639fd7..3b21b9986 100644 --- a/sixtyfps_runtime/corelib/items/text.rs +++ b/sixtyfps_runtime/corelib/items/text.rs @@ -32,6 +32,9 @@ use const_field_offset::FieldOffsets; use core::pin::Pin; use sixtyfps_corelib_macros::*; +#[cfg(not(feature = "std"))] +use num_traits::float::Float; + #[derive(Copy, Clone, Debug, PartialEq, strum::EnumString, strum::Display)] #[repr(C)] #[allow(non_camel_case_types)] diff --git a/sixtyfps_runtime/corelib/model.rs b/sixtyfps_runtime/corelib/model.rs index c51ca0a3d..5d8fab08c 100644 --- a/sixtyfps_runtime/corelib/model.rs +++ b/sixtyfps_runtime/corelib/model.rs @@ -27,6 +27,9 @@ use once_cell::unsync::OnceCell; use pin_project::pin_project; use pin_weak::rc::{PinWeak, Rc}; +#[cfg(not(feature = "std"))] +use num_traits::float::Float; + type DependencyListHead = crate::properties::dependency_tracker::DependencyListHead<*const dyn ErasedRepeater>; type ComponentRc = vtable::VRc;