From 13886a5949d31735289129c2158ee65c8d977913 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 30 Dec 2024 13:00:57 +0000 Subject: [PATCH 1/3] Actually run tests on PowerPC instead of just building on big-endian and calling it a day --- .github/workflows/rust.yml | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c92ebd52..ab29903d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,13 +47,31 @@ jobs: env: FEATURES: ${{ matrix.features }} powerpc_cross: + # github actions does not support big endian systems directly, but it does support QEMU. + # so we install qemu, then build and run the tests in an emulated powerpc system. + # note: you can also use this approach to test for big endian locally. runs-on: ubuntu-latest + + # we are using the cross project for cross compilation: + # https://github.com/cross-rs/cross steps: - - uses: actions/checkout@v4 - - name: add_cross_target - run: | - rustup target add powerpc-unknown-linux-gnu - cargo build --target powerpc-unknown-linux-gnu + - uses: actions/checkout@v4 + + - name: Install or use cached cross-rs/cross + uses: baptiste0928/cargo-install@v1 + with: + crate: cross + + - name: Cache Cargo Dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Start Docker (required for cross-rs) + run: sudo systemctl start docker + + - name: Cross-Run Tests in powerpc-unknown-linux-gnu using Qemu + run: cross test --release --target powerpc-unknown-linux-gnu --verbose -v test_all: strategy: matrix: From ab3b6e13a0c9cd125a2497974cbfbe1fe4746a2e Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 30 Dec 2024 21:39:12 +0000 Subject: [PATCH 2/3] Delete the show.rs example and the associated dev-dependencies --- Cargo.toml | 3 - examples/show.rs | 198 ----------------------------------------------- 2 files changed, 201 deletions(-) delete mode 100644 examples/show.rs diff --git a/Cargo.toml b/Cargo.toml index 7bc7e240..6218012d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,11 +32,8 @@ approx = "0.5.1" byteorder = "1.5.0" clap = { version = "3.0", features = ["derive"] } criterion = "0.4.0" -getopts = "0.2.14" -glium = { version = "0.32", features = ["glutin"], default-features = false } glob = "0.3" rand = "0.8.4" -term = "1.0.1" [features] unstable = ["crc32fast/nightly"] diff --git a/examples/show.rs b/examples/show.rs deleted file mode 100644 index 7e2b2798..00000000 --- a/examples/show.rs +++ /dev/null @@ -1,198 +0,0 @@ -use glium::{ - backend::glutin::Display, - glutin::{ - self, dpi, - event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, - event_loop::ControlFlow, - }, - texture::{ClientFormat, RawImage2d}, - BlitTarget, Rect, Surface, -}; -use std::{borrow::Cow, env, fs::File, io, path}; - -/// Load the image using `png` -fn load_image(path: &path::PathBuf) -> io::Result> { - use png::ColorType::*; - let mut decoder = png::Decoder::new(File::open(path)?); - decoder.set_transformations(png::Transformations::normalize_to_color8()); - let mut reader = decoder.read_info()?; - let mut img_data = vec![0; reader.output_buffer_size()]; - let info = reader.next_frame(&mut img_data)?; - - let (data, format) = match info.color_type { - Rgb => (img_data, ClientFormat::U8U8U8), - Rgba => (img_data, ClientFormat::U8U8U8U8), - Grayscale => ( - { - let mut vec = Vec::with_capacity(img_data.len() * 3); - for g in img_data { - vec.extend([g, g, g].iter().cloned()) - } - vec - }, - ClientFormat::U8U8U8, - ), - GrayscaleAlpha => ( - { - let mut vec = Vec::with_capacity(img_data.len() * 3); - for ga in img_data.chunks(2) { - let g = ga[0]; - let a = ga[1]; - vec.extend([g, g, g, a].iter().cloned()) - } - vec - }, - ClientFormat::U8U8U8U8, - ), - _ => unreachable!("uncovered color type"), - }; - - Ok(RawImage2d { - data: Cow::Owned(data), - width: info.width, - height: info.height, - format, - }) -} - -fn main_loop(files: Vec) -> io::Result<()> { - let mut files = files.into_iter(); - let image = load_image(&files.next().unwrap())?; - - let event_loop = glutin::event_loop::EventLoop::new(); - let window_builder = glutin::window::WindowBuilder::new().with_title("Show Example"); - let context_builder = glutin::ContextBuilder::new().with_vsync(true); - let display = glium::Display::new(window_builder, context_builder, &event_loop) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - resize_window(&display, &image); - let mut texture = glium::Texture2d::new(&display, image).unwrap(); - draw(&display, &texture); - - event_loop.run(move |event, _, control_flow| match event { - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => exit(control_flow), - Event::WindowEvent { - event: - WindowEvent::KeyboardInput { - input: - KeyboardInput { - state: ElementState::Pressed, - virtual_keycode: code, - .. - }, - .. - }, - .. - } => match code { - Some(VirtualKeyCode::Escape) => exit(control_flow), - Some(VirtualKeyCode::Right) => match &files.next() { - Some(path) => { - match load_image(path) { - Ok(image) => { - resize_window(&display, &image); - texture = glium::Texture2d::new(&display, image).unwrap(); - draw(&display, &texture); - } - Err(err) => { - println!("Error: {}", err); - exit(control_flow); - } - }; - } - None => exit(control_flow), - }, - _ => {} - }, - Event::RedrawRequested(_) => draw(&display, &texture), - _ => {} - }); -} - -fn draw(display: &glium::Display, texture: &glium::Texture2d) { - let frame = display.draw(); - fill_v_flipped( - &texture.as_surface(), - &frame, - glium::uniforms::MagnifySamplerFilter::Linear, - ); - frame.finish().unwrap(); -} - -fn exit(control_flow: &mut ControlFlow) { - *control_flow = ControlFlow::Exit; -} - -fn fill_v_flipped(src: &S1, target: &S2, filter: glium::uniforms::MagnifySamplerFilter) -where - S1: Surface, - S2: Surface, -{ - let src_dim = src.get_dimensions(); - let src_rect = Rect { - left: 0, - bottom: 0, - width: src_dim.0, - height: src_dim.1, - }; - let target_dim = target.get_dimensions(); - let target_rect = BlitTarget { - left: 0, - bottom: target_dim.1, - width: target_dim.0 as i32, - height: -(target_dim.1 as i32), - }; - src.blit_color(&src_rect, target, &target_rect, filter); -} - -fn resize_window(display: &Display, image: &RawImage2d<'static, u8>) { - let mut width = image.width; - let mut height = image.height; - if width < 50 && height < 50 { - width *= 10; - height *= 10; - } - display - .gl_window() - .window() - .set_inner_size(dpi::LogicalSize::new(f64::from(width), f64::from(height))); -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() < 2 { - println!("Usage: show files [...]"); - } else { - let mut files = vec![]; - for file in args.iter().skip(1) { - match if file.contains('*') { - (|| -> io::Result<_> { - for entry in glob::glob(file) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err.msg))? - { - files.push( - entry - .map_err(|_| io::Error::new(io::ErrorKind::Other, "glob error"))?, - ) - } - Ok(()) - })() - } else { - files.push(path::PathBuf::from(file)); - Ok(()) - } { - Ok(_) => (), - Err(err) => { - println!("{}: {}", file, err); - break; - } - } - } - // "tests/pngsuite/pngsuite.png" - match main_loop(files) { - Ok(_) => (), - Err(err) => println!("Error: {}", err), - } - } -} From 434f10815e4e575c96cbfd071e45354fca4324f5 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 30 Dec 2024 21:42:23 +0000 Subject: [PATCH 3/3] Re-add dependencies needed by tests that `cargo check --tests` didn't show --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 6218012d..65ff0424 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,10 @@ approx = "0.5.1" byteorder = "1.5.0" clap = { version = "3.0", features = ["derive"] } criterion = "0.4.0" +getopts = "0.2.14" glob = "0.3" rand = "0.8.4" +term = "1.0.1" [features] unstable = ["crc32fast/nightly"]