Commit 5c379688 authored by Tim Crawford's avatar Tim Crawford
Browse files

Improve no-std config



Replace the `no_std` feature with `std`, and have that set by default.
Allows building for a `no_std` target by disabling deault features.

Make the SDL dependencies optional, and only use them if either the
`sdl` or `bundled` feature is used. Hosted targets that want to use
SDL2 must now select one of these features.

Add a `no_std` target (Cortex-M0) to CI to ensure it continues to build.

Additionally, made sure it builds for UEFI target.

    cargo +nightly build --no-default-features \
        --target x86_64-unknown-uefi -Z build-std=core,alloc
Signed-off-by: Tim Crawford's avatarTim Crawford <tcrawford@system76.com>
parent 192dc30e
Pipeline #10138 failed with stage
in 2 minutes and 10 seconds
......@@ -4,7 +4,7 @@ build:linux:
before_script:
- apt-get install cmake -y
script:
- cargo build
- cargo build --features bundled
build:redox:
image: "redoxos/redoxer"
......@@ -17,4 +17,12 @@ build:wasm32:
- rustup toolchain add stable
- rustup target add wasm32-unknown-unknown --toolchain stable
script:
- cargo +stable build --no-default-features --target wasm32-unknown-unknown
- cargo +stable build --target wasm32-unknown-unknown
build:no_std:
image: "rust:latest"
before_script:
- rustup toolchain add stable
- rustup target add thumbv6m-none-eabi --toolchain stable
script:
- cargo +stable build --no-default-features --target thumbv6m-none-eabi
......@@ -6,8 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## unreleased
* Replaced `no_std` feature with `std` feature, selected by default
* `no_std` environments are now built by setting `default-features = false`
* Removed `bundled` from default features
* Hosted environments that want to use SDL2 must now enable the `bundled` feature
* Added new `sdl` feature for building SDL2 without bundling
* Included by `bundled`, so only one or the other needs to be selected
## 0.3.32
* Change Rust edition from 2015 to 2018
* Change `Color` from `repr(packed)` to `repr(transparent)`
* Fix compiling against wayland > 1.20.0
## 0.3.31
......
......@@ -18,18 +18,20 @@ keywords = [
name = "orbclient"
path = "src/lib.rs"
[dependencies]
cfg-if = "1.0"
[target.'cfg(all(not(target_os = "redox"), not(target_arch = "wasm32")))'.dependencies]
sdl2 = { version = "0.35", features = ["bundled", "static-link", "raw-window-handle"] }
sdl2-sys = "0.35"
libc = "0.2"
raw-window-handle = "0.3"
sdl2 = { version = "0.35", features = ["bundled", "static-link", "raw-window-handle"], optional = true }
sdl2-sys = { version = "0.35", optional = true }
libc = { version = "0.2", optional = true }
raw-window-handle = { version = "0.3", optional = true }
[target.'cfg(target_os="redox")'.dependencies]
redox_syscall = { version = "0.2.1" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.69"
# js-sys = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3"
......@@ -57,6 +59,7 @@ features = [
]
[features]
default = ["bundled"]
bundled = ["sdl2/bundled", "sdl2/static-link", "sdl2-sys/bundled", "sdl2-sys/static-link"]
no_std = []
default = ["std"]
std = []
sdl = ["sdl2", "sdl2-sys", "libc", "raw-window-handle"]
bundled = ["sdl", "sdl2/bundled", "sdl2/static-link", "sdl2-sys/bundled", "sdl2-sys/static-link"]
......@@ -5,7 +5,7 @@ Inspired from http://blog.ivank.net/fastest-gaussian-blur.html the algorithm 4.
The struct MathColor is needed for the calculate with bigger numbers, the Color struct save the r,g,b values with a u8.
*/
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::ops::{Add, AddAssign, Sub};
......
// SPDX-License-Identifier: MIT
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
/// point type (is the point a new position or a connection point)
......
// SPDX-License-Identifier: MIT
#![crate_name = "orbclient"]
#![crate_type = "lib"]
#![cfg_attr(feature = "no_std", feature(alloc))]
#![cfg_attr(feature = "no_std", no_std)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "no_std"))]
extern crate core;
cfg_if::cfg_if! {
if #[cfg(all(feature = "std", feature = "sdl"))] {
#[path = "sys/sdl2.rs"]
mod sys;
pub use sys::{get_display_size, EventIter, Window};
} else if #[cfg(all(feature = "std", not(target_arch = "wasm"), target_os = "redox"))] {
#[path = "sys/orbital.rs"]
mod sys;
pub use sys::{get_display_size, EventIter, Window};
} else if #[cfg(target_arch = "wasm32")] {
#[path = "sys/web.rs"]
mod sys;
pub use sys::{animation_loop, log, get_display_size, EventIter, Window};
}
}
pub static FONT: &[u8] = include_bytes!("../res/unifont.font");
......@@ -16,13 +27,8 @@ pub use color::Color;
pub use event::*;
pub use graphicspath::GraphicsPath;
pub use renderer::Renderer;
#[cfg(not(feature = "no_std"))]
pub use sys::{get_display_size, EventIter, Window};
#[cfg(target_arch = "wasm32")]
pub use sys::{animation_loop, log};
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
mod blur;
pub mod color;
pub mod event;
......@@ -45,23 +51,3 @@ pub enum Mode {
Blend, //Composite
Overwrite, //Replace
}
#[cfg(all(
not(feature = "no_std"),
not(target_arch = "wasm32"),
target_os = "redox"
))]
#[path = "sys/orbital.rs"]
mod sys;
#[cfg(all(
not(feature = "no_std"),
not(target_arch = "wasm32"),
not(target_os = "redox")
))]
#[path = "sys/sdl2.rs"]
mod sys;
#[cfg(target_arch = "wasm32")]
#[path = "sys/web.rs"]
mod sys;
......@@ -3,7 +3,7 @@
use core::cell::Cell;
use core::cmp;
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
use crate::blur;
use crate::color::Color;
use crate::graphicspath::GraphicsPath;
......@@ -338,7 +338,7 @@ pub trait Renderer {
//}
}
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn box_blur(&mut self, x: i32, y: i32, w: u32, h: u32, r: i32) {
let self_w = self.width();
let self_h = self.height();
......@@ -374,7 +374,7 @@ pub trait Renderer {
}
#[allow(clippy::too_many_arguments)]
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn box_shadow(
&mut self,
x: i32,
......@@ -553,7 +553,7 @@ pub trait Renderer {
/// Draw a linear gradient in a rectangular region
#[allow(clippy::too_many_arguments)]
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn linear_gradient(
&mut self,
rect_x: i32,
......@@ -677,7 +677,7 @@ pub trait Renderer {
}
/// Draws antialiased line
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn wu_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: Color) {
//adapted from https://rosettacode.org/wiki/Xiaolin_Wu's_line_algorithm#C.23
let mut x0 = x0 as f64;
......@@ -826,7 +826,7 @@ pub trait Renderer {
}
///Draws antialiased circle
#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn wu_circle(&mut self, x0: i32, y0: i32, radius: i32, color: Color) {
let r = color.r();
let g = color.g();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment