Skip to content

Commit

Permalink
Cleanup matrix and run tests in CI (#323)
Browse files Browse the repository at this point in the history
* Cleanup matrix and run tests in CI

Signed-off-by: sagudev <[email protected]>

* Ignore some failures on angle

Signed-off-by: sagudev <[email protected]>

---------

Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev authored Nov 27, 2024
1 parent c8d6b4b commit 0a468c8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 96 deletions.
113 changes: 58 additions & 55 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,77 @@ env:

jobs:
Build:
runs-on: ${{ matrix.os }}
name: ${{ format('{0} {1}', matrix.platform.target, matrix.features)}}
runs-on: ${{ matrix.platform.os }}
env:
RUST_BACKTRACE: 1
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-22.04, windows-latest]
rust: [stable]
features: ["", "--features 'chains sm-raw-window-handle-06'", "--features 'chains sm-raw-window-handle-05'"]
target: ["default"]
platform:
- { target: aarch64-apple-darwin, os: macos-14, test: true }
- { target: x86_64-apple-darwin, os: macos-13, test: true }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-24.04, test: true }
- { target: x86_64-pc-windows-msvc, os: windows-latest, test: true }
- { target: i686-pc-windows-msvc, os: windows-latest, test: false }
- { target: aarch64-pc-windows-msvc, os: windows-latest, test: false }
- {
target: aarch64-unknown-linux-ohos,
os: ubuntu-24.04,
test: false,
}
- { target: arm-linux-androideabi, os: ubuntu-24.04, test: false }
features:
[
"",
"chains sm-raw-window-handle-06",
"chains sm-raw-window-handle-05",
]
include:
# rust stable
- os: ubuntu-22.04
features: "--features 'sm-x11 sm-wayland-default'"
rust: stable
target: "default"
- os: ubuntu-22.04
target: "arm-linux-androideabi"
rust: stable
- os: windows-latest
features: "--features 'chains sm-angle-builtin'"
rust: stable
target: "default"
- os: windows-latest
features: "--features 'chains sm-no-wgl sm-angle-builtin'"
rust: stable
target: "default"
- os: windows-latest
target: "aarch64-pc-windows-msvc"
rust: stable
- os: ubuntu-22.04
target: "aarch64-unknown-linux-ohos"
rust: stable
- features: "sm-x11 sm-wayland-default"
platform:
{ target: x86_64-unknown-linux-gnu, os: ubuntu-24.04, test: true }
- features: "chains sm-angle-builtin"
platform:
{ target: x86_64-pc-windows-msvc, os: windows-latest, test: true }
- features: "chains sm-no-wgl sm-angle-builtin"
platform:
{ target: x86_64-pc-windows-msvc, os: windows-latest, test: true }
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt update
sudo apt install gcc libxxf86vm-dev libosmesa6-dev libgles2-mesa-dev -y
- name: Install rust
id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Build target
if: matrix.target != 'default' && startsWith(matrix.target, 'aarch64-uwp-windows-msvc') != true
run: |
rustup +${{steps.toolchain.outputs.name}} target add ${{ matrix.target }}
cargo +${{steps.toolchain.outputs.name}} build --verbose ${{ matrix.features }} --target=${{ matrix.target }}
- name: Build
if: matrix.target == 'default'
run: |
cargo +${{steps.toolchain.outputs.name}} build --verbose ${{ matrix.features }}
- name: Build Windows
if: startsWith(matrix.target, 'aarch64-uwp-windows-msvc')
shell: cmd
run: |
rustup +${{steps.toolchain.outputs.name}} component add rust-src --target=aarch64-uwp-windows-msvc
cargo +${{steps.toolchain.outputs.name}} build -Z build-std --verbose --target=aarch64-uwp-windows-msvc
- uses: actions/checkout@v4
- name: Install dependencies (Linux)
if: startsWith(matrix.platform.os, 'ubuntu')
run: |
sudo apt update
sudo apt install gcc libxxf86vm-dev libosmesa6-dev libgles2-mesa-dev xvfb weston -y
- name: Install rust
id: toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Build
run: |
rustup target add ${{ matrix.platform.target }}
cargo build --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
- name: Test
if: ${{ matrix.platform.test && startsWith(matrix.platform.os, 'ubuntu') }}
run: |
weston --no-config --socket=wl-test-env --backend=headless &
WAYLAND_DISPLAY=wl-test-env xvfb-run cargo test --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
- name: Test
if: ${{ matrix.platform.test && !startsWith(matrix.platform.os, 'ubuntu') }}
run: |
cargo test --features "${{ matrix.features }}" --target ${{ matrix.platform.target }}
Format:
name: Run `rustfmt`
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: mkroening/rust-toolchain-toml@main
- run: cargo fmt --check
build_result:
name: Result
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: ["Build", "Format"]
if: always()
steps:
Expand Down
32 changes: 19 additions & 13 deletions examples/chaos_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
//
//! Demonstrates how to use `surfman` to draw to a window surface via the CPU.
use euclid::default::Point2D;
use euclid::default::{Point2D, Size2D};
use rand::{self, Rng};
use surfman::{SurfaceAccess, SurfaceType};
use winit::dpi::PhysicalSize;
use winit::event::WindowEvent::KeyboardInput;
use winit::event::{DeviceEvent, Event, WindowEvent};
use winit::event::{DeviceEvent, ElementState, Event, KeyEvent, RawKeyEvent, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::keyboard::{Key, NamedKey, PhysicalKey};
use winit::raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, HasWindowHandle};
use winit::window::WindowBuilder;

#[cfg(target_os = "macos")]
Expand All @@ -29,18 +31,18 @@ static TRIANGLE_POINTS: [(f32, f32); 3] = [
(400.0 - 259.81, 300.0 + 75.0 - 300.0),
];

#[cfg(not(target_os = "macos"))]
#[cfg(not(all(target_os = "macos", feature = "sm-raw-window-handle-06")))]
fn main() {
println!("The `chaos_game` demo is not yet supported on this platform.");
}

#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", feature = "sm-raw-window-handle-06"))]
fn main() {
let connection = SystemConnection::new().unwrap();
let adapter = connection.create_adapter().unwrap();
let mut device = connection.create_device(&adapter).unwrap();

let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let physical_size = PhysicalSize::new(WINDOW_WIDTH, WINDOW_HEIGHT);
let window = WindowBuilder::new()
.with_title("Chaos game example")
Expand All @@ -54,7 +56,7 @@ fn main() {
let window_size = Size2D::new(window_size.width as i32, window_size.height as i32);
let handle = window.window_handle().unwrap();
let native_widget = connection
.create_native_widget_from_raw_window_handle(handle.as_raw(), window_size)
.create_native_widget_from_window_handle(handle, window_size)
.unwrap();

let surface_type = SurfaceType::Widget { native_widget };
Expand All @@ -66,20 +68,25 @@ fn main() {
let mut point = Point2D::new(WINDOW_WIDTH as f32 * 0.5, WINDOW_HEIGHT as f32 * 0.5);
let mut data = vec![0; WINDOW_WIDTH as usize * WINDOW_HEIGHT as usize * 4];

event_loop.run(move |event, _, control_flow| {
event_loop.run(move |event, event_loop| {
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
}
| Event::DeviceEvent {
| Event::WindowEvent {
event:
DeviceEvent::Key(KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
WindowEvent::KeyboardInput {
event:
KeyEvent {
state: ElementState::Pressed,
logical_key: Key::Named(NamedKey::Escape),
..
},
..
}),
},
..
} => *control_flow = ControlFlow::Exit,
} => event_loop.exit(),
_ => {
for _ in 0..ITERATIONS_PER_FRAME {
let (dest_x, dest_y) = TRIANGLE_POINTS[rng.gen_range(0..3)];
Expand All @@ -93,7 +100,6 @@ fn main() {
.data()
.copy_from_slice(&data);
device.present_surface(&mut surface).unwrap();
*control_flow = ControlFlow::Poll;
}
};
});
Expand Down
27 changes: 2 additions & 25 deletions examples/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// This example demonstrates how to create a multithreaded OpenGL application using `surfman`.

#![cfg(feature = "sm-raw-window-handle-06")]

use self::common::{ck, Buffer, Program, ResourceLoader, Shader, ShaderKind};

use euclid::default::{Point2D, Rect, Size2D, Vector2D};
Expand All @@ -24,9 +26,6 @@ use winit::{
window::WindowBuilder,
};

#[cfg(feature = "sm-raw-window-handle-05")]
use rwh_05::{HasRawDisplayHandle, HasRawWindowHandle};
#[cfg(not(feature = "sm-raw-window-handle-05"))]
use rwh_06::{HasDisplayHandle, HasWindowHandle};

pub mod common;
Expand Down Expand Up @@ -90,14 +89,6 @@ static BACKGROUND_COLOR: [f32; 4] = [
1.0,
];

#[cfg(feature = "sm-raw-window-handle-05")]
fn make_connection(window: &winit::window::Window) -> surfman::Connection {
let raw_display_handle = window.raw_display_handle();
let connection = Connection::from_raw_display_handle(raw_display_handle).unwrap();
connection
}

#[cfg(not(feature = "sm-raw-window-handle-05"))]
fn make_connection(window: &winit::window::Window) -> surfman::Connection {
let display_handle = window
.display_handle()
Expand All @@ -106,20 +97,6 @@ fn make_connection(window: &winit::window::Window) -> surfman::Connection {
connection
}

#[cfg(feature = "sm-raw-window-handle-05")]
fn make_native_widget(
window: &winit::window::Window,
connection: &surfman::Connection,
window_size: Size2D<i32>,
) -> surfman::NativeWidget {
let raw_window_handle = window.raw_window_handle();
let native_widget = connection
.create_native_widget_from_raw_window_handle(raw_window_handle, window_size)
.unwrap();
native_widget
}

#[cfg(not(feature = "sm-raw-window-handle-05"))]
fn make_native_widget(
window: &winit::window::Window,
connection: &surfman::Connection,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/egl/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Connection {
raw_handle: rwh_05::RawWindowHandle,
_size: Size2D<i32>,
) -> Result<NativeWidget, Error> {
create_native_widget_from_rwh_05_handle(raw_handle)
Self::create_native_widget_from_rwh_05_handle(raw_handle)
}

#[cfg(all(feature = "sm-raw-window-handle-06", android_platform))]
Expand Down
13 changes: 11 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,19 @@ pub fn test_context_creation() {
// requested GL version.
}
Err(error) => {
panic!(
let error = format!(
"Failed to create context ({:?}/{:?}): {:?}",
version, flags, error
)
);
// This fail on angle
if cfg!(all(feature = "sm-no-wgl", feature = "sm-angle"))
&& (flags.contains(ContextAttributeFlags::COMPATIBILITY_PROFILE)
|| version == *GL_ES_VERSIONS.last().unwrap())
{
println!("{error}");
} else {
panic!("{error}");
}
}
}
}
Expand Down

0 comments on commit 0a468c8

Please sign in to comment.