Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic CI checks #68

Merged
merged 9 commits into from
Jun 19, 2024
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
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
on:
pull_request:
push:
branches:
- main

name: CI

env:
RUSTDOCFLAGS: "-D warnings"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: "sparse"

jobs:

# MSRV check.
# Blitz only guarantees "latest stable". However we have this check here to ensure that we advertise
# our MSRV. We also make an effort not to increase MSRV in patch versions of Blitz.
#
# We only run `cargo build` (not `cargo test`) so as to avoid requiring dev-dependencies to build with the MSRV
# version. Building is likely sufficient as runtime errors varying between rust versions is very unlikely.
build-msrv:
name: "MSRV Build [Rust 1.79]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.79
- run: sudo apt install libgtk-3-dev libxdo-dev
- run: cargo build --workspace

test-features-default:
name: "Test [default features]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: sudo apt install libgtk-3-dev libxdo-dev
- run: cargo build --workspace
- run: cargo test --workspace

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- run: cargo fmt --all --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: clippy
- run: sudo apt install libgtk-3-dev libxdo-dev
- run: cargo clippy --workspace -- -D warnings

doc:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo doc
5 changes: 0 additions & 5 deletions examples/dom_only.rs

This file was deleted.

1 change: 0 additions & 1 deletion examples/font.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
fn app() -> Element {
rsx! {
style { {CSS} }
for row in 0..3 {
for _row in 0..3 {
div { class: "flex flex-row",
div { id: "cool", "h123456789asdjkahskj\nhiiiii" }
p { class: "cool", "hi" }
Expand Down
13 changes: 8 additions & 5 deletions packages/blitz/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,22 @@ where
.await
.expect("Error creating surface");

let default_threads = || -> Option<NonZeroUsize> {
#[cfg(target_arch = "macos")]
const DEFAULT_THREADS: Option<NonZeroUsize> = {
#[cfg(target_os = "macos")]
{
Some(NonZeroUsize::new(1)?)
NonZeroUsize::new(1)
}
#[cfg(not(target_os = "macos"))]
{
None
}
None
};

let options = RendererOptions {
surface_format: Some(surface.config.format),
antialiasing_support: AaSupport::all(),
use_cpu: false,
num_init_threads: default_threads(),
num_init_threads: DEFAULT_THREADS,
};

let renderer =
Expand Down
22 changes: 2 additions & 20 deletions packages/blitz/src/viewport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use style::{
media_queries::{Device, MediaType},
servo::media_queries::FontMetricsProvider,
};
use blitz_dom::document::DummyFontMetricsProvider;
use style::media_queries::{Device, MediaType};

#[derive(Default, Debug)]
pub struct Viewport {
Expand All @@ -14,22 +12,6 @@ pub struct Viewport {
pub font_size: f32,
}

// TODO: implement a proper font metrics provider
#[derive(Debug, Clone)]
struct DummyFontMetricsProvider;
impl FontMetricsProvider for DummyFontMetricsProvider {
fn query_font_metrics(
&self,
_vertical: bool,
_font: &style::properties::style_structs::Font,
_base_size: style::values::computed::CSSPixelLength,
_in_media_query: bool,
_retrieve_math_scales: bool,
) -> style::font_metrics::FontMetrics {
Default::default()
}
}

impl Viewport {
pub fn new(window_size: (u32, u32)) -> Self {
Self {
Expand Down
35 changes: 17 additions & 18 deletions packages/dioxus-blitz/src/documents/dioxus_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,29 @@ impl AsMut<Document> for DioxusDocument {
&mut self.inner
}
}
impl Into<Document> for DioxusDocument {
fn into(self) -> Document {
self.inner
impl From<DioxusDocument> for Document {
fn from(doc: DioxusDocument) -> Document {
doc.inner
}
}
impl DocumentLike for DioxusDocument {
fn poll(&mut self, mut cx: std::task::Context) -> bool {
loop {
{
let fut = self.vdom.wait_for_work();
pin_mut!(fut);

match fut.poll_unpin(&mut cx) {
std::task::Poll::Ready(_) => {}
std::task::Poll::Pending => return false,
}
}
{
let fut = self.vdom.wait_for_work();
pin_mut!(fut);

self.vdom.render_immediate(&mut MutationWriter {
doc: &mut self.inner,
state: &mut self.vdom_state,
});
return true;
match fut.poll_unpin(&mut cx) {
std::task::Poll::Ready(_) => {}
std::task::Poll::Pending => return false,
}
}

self.vdom.render_immediate(&mut MutationWriter {
doc: &mut self.inner,
state: &mut self.vdom_state,
});

true
}

fn handle_event(&mut self, event: blitz_dom::events::RendererEvent) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions packages/dioxus-blitz/src/documents/html_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ impl AsMut<Document> for HtmlDocument {
&mut self.inner
}
}
impl Into<Document> for HtmlDocument {
fn into(self) -> Document {
self.inner
impl From<HtmlDocument> for Document {
fn from(doc: HtmlDocument) -> Document {
doc.inner
}
}
impl DocumentLike for HtmlDocument {}
Expand Down
8 changes: 5 additions & 3 deletions packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {
}
#[cfg(target_os = "linux")]
{
build_menu().init_for_gtk_window(window.gtk_window(), window.default_vbox());
build_menu()
.init_for_gtk_window(window.gtk_window(), window.default_vbox())
.unwrap();
}

// !TODO - this may not be the right way to do this, but it's a start
Expand Down Expand Up @@ -331,10 +333,10 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {

#[cfg(not(target_os = "macos"))]
fn build_menu() -> Menu {
let mut menu = Menu::new();
let menu = Menu::new();

// Build the about section
let mut about = Submenu::new("About", true);
let about = Submenu::new("About", true);

about
.append_items(&[
Expand Down
17 changes: 17 additions & 0 deletions packages/dom/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use slab::Slab;
use std::collections::HashMap;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::selector_parser::ServoElementSnapshot;
use style::servo::media_queries::FontMetricsProvider;
use style::servo_arc::Arc as ServoArc;
use style::{
dom::{TDocument, TNode},
Expand All @@ -20,6 +21,22 @@ use style_traits::dom::ElementState;
use taffy::AvailableSpace;
use url::Url;

// TODO: implement a proper font metrics provider
#[derive(Debug, Clone)]
pub struct DummyFontMetricsProvider;
impl FontMetricsProvider for DummyFontMetricsProvider {
fn query_font_metrics(
&self,
_vertical: bool,
_font: &style::properties::style_structs::Font,
_base_size: style::values::computed::CSSPixelLength,
_in_media_query: bool,
_retrieve_math_scales: bool,
) -> style::font_metrics::FontMetrics {
Default::default()
}
}

pub trait DocumentLike: AsRef<Document> + AsMut<Document> + Into<Document> {
fn poll(&mut self, _cx: std::task::Context) -> bool {
// Default implementation does nothing
Expand Down
5 changes: 3 additions & 2 deletions packages/dom/src/htmlsink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> {
if has_appended {
return;
} else {
let id = self.create_text_node(&text);
id
self.create_text_node(&text)
}
}
NodeOrText::AppendNode(id) => id,
Expand Down Expand Up @@ -366,6 +365,7 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> {

#[test]
fn parses_some_html() {
use crate::document::DummyFontMetricsProvider;
use euclid::{Scale, Size2D};
use style::media_queries::{Device, MediaType};

Expand All @@ -378,6 +378,7 @@ fn parses_some_html() {
selectors::matching::QuirksMode::NoQuirks,
viewport_size,
device_pixel_ratio,
Box::new(DummyFontMetricsProvider),
);
let mut doc = Document::new(device);
let sink = DocumentHtmlParser::new(&mut doc);
Expand Down
14 changes: 7 additions & 7 deletions packages/dom/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ impl PrintTree for Document {
}
}

pub struct ChildIter<'a>(std::slice::Iter<'a, usize>);
impl<'a> Iterator for ChildIter<'a> {
type Item = NodeId;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().copied().map(NodeId::from)
}
}
// pub struct ChildIter<'a>(std::slice::Iter<'a, usize>);
// impl<'a> Iterator for ChildIter<'a> {
// type Item = NodeId;
// fn next(&mut self) -> Option<Self::Item> {
// self.0.next().copied().map(NodeId::from)
// }
// }

pub struct RefCellChildIter<'a> {
items: Ref<'a, [usize]>,
Expand Down
3 changes: 1 addition & 2 deletions packages/dom/src/stylo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,7 @@ impl<'a> TElement for BlitzNode<'a> {
let root_element = TDocument::as_node(&root_node)
.first_element_child()
.unwrap();
let is_child_of_root_element = root_element.children.contains(&self.id);
is_child_of_root_element
root_element.children.contains(&self.id)
}

fn synthesize_presentational_hints_for_legacy_attributes<V>(
Expand Down
2 changes: 1 addition & 1 deletion packages/dom/src/stylo_to_parley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) fn style(style: &stylo::ComputedValues) -> parley::TextStyle<'static,
}

// TODO: fix leak!
parley::FontFamily::Named(name.to_string().leak())
break 'ret parley::FontFamily::Named(name.to_string().leak());
}
}
stylo::SingleFontFamily::Generic(generic) => {
Expand Down
18 changes: 11 additions & 7 deletions packages/dom/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ use image::DynamicImage;
const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0";
const FILE_SIZE_LIMIT: u64 = 1_000_000_000; // 1GB

pub(crate) fn fetch_blob(url: &str) -> Result<Vec<u8>, ureq::Error> {
pub(crate) fn fetch_blob(url: &str) -> Result<Vec<u8>, Box<ureq::Error>> {
if url.starts_with("data:") {
let data_url = data_url::DataUrl::process(url).unwrap();
let decoded = data_url.decode_to_vec().expect("Invalid data url");
return Ok(decoded.0);
}

let resp = ureq::get(url).set("User-Agent", USER_AGENT).call()?;
let resp = ureq::get(url)
.set("User-Agent", USER_AGENT)
.call()
.map_err(Box::new)?;

let len: usize = resp
.header("Content-Length")
Expand All @@ -23,12 +26,13 @@ pub(crate) fn fetch_blob(url: &str) -> Result<Vec<u8>, ureq::Error> {

resp.into_reader()
.take(FILE_SIZE_LIMIT)
.read_to_end(&mut bytes)?;
.read_to_end(&mut bytes)
.unwrap();

Ok(bytes)
}

pub(crate) fn fetch_string(url: &str) -> Result<String, ureq::Error> {
pub(crate) fn fetch_string(url: &str) -> Result<String, Box<ureq::Error>> {
fetch_blob(url).map(|vec| String::from_utf8(vec).expect("Invalid UTF8"))
}

Expand All @@ -41,11 +45,11 @@ pub(crate) fn fetch_string(url: &str) -> Result<String, ureq::Error> {

#[allow(unused)]
pub(crate) enum ImageFetchErr {
FetchErr(ureq::Error),
FetchErr(Box<ureq::Error>),
ImageError(image::error::ImageError),
}
impl From<ureq::Error> for ImageFetchErr {
fn from(value: ureq::Error) -> Self {
impl From<Box<ureq::Error>> for ImageFetchErr {
fn from(value: Box<ureq::Error>) -> Self {
Self::FetchErr(value)
}
}
Expand Down
Loading