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

ci: improve test #7

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
rustflags = [
"--cfg=web_sys_unstable_apis"
]
27 changes: 0 additions & 27 deletions .github/workflows/test-wgpu.yml

This file was deleted.

183 changes: 183 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Refer https://github.com/gfx-rs/wgpu/blob/757245cdfc97e4d4dce110ef1bb333787a6c25bd/.github/workflows/ci.yml
name: Test

on:
push:
paths:
- "**/*.rs"
- ".github/**"

env:
CARGO_INCREMENTAL: false
CARGO_TERM_COLOR: always
RUST_LOG: info
RUST_BACKTRACE: full
MSRV: 1.70
PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
RUSTDOCFLAGS: -Dwarnings
CACHE_SUFFIX: b # cache busting

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install MSRV toolchain
run: |
rustup update stable
rustup default stable
rustup component add clippy
rustup component add rustfmt
- name: caching
uses: Swatinem/rust-cache@v2
with:
key: check-${{ env.CACHE_SUFFIX }}

- name: Run fmt
run: cargo fmt --all -- --check

- name: Run clippy
run: cargo clippy --all-targets -- -D warnings

- name: run doctest
run: cargo test --doc

build:
strategy:
matrix:
include:
# Windows
- name: Windows x86_64
os: windows-2022
target: x86_64-pc-windows-msvc

# MacOS
- name: MacOS x86_64
os: macos-12
target: x86_64-apple-darwin

- name: MacOS aarch64
os: macos-12
target: aarch64-apple-darwin

# IOS
- name: IOS aarch64
os: macos-12
target: aarch64-apple-ios

# Linux
- name: Linux x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu

- name: Linux aarch64
os: ubuntu-22.04
target: aarch64-unknown-linux-gnu

# Android
# - name: Android aarch64
# os: ubuntu-22.04
# target: aarch64-linux-android

# WebGPU/WebGL
- name: WebAssembly
os: ubuntu-22.04
target: wasm32-unknown-unknown

name: Build ${{ matrix.name }}

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Install MSRV toolchain
run: |
rustup update stable
rustup default stable
rustup target add ${{ matrix.target }}
rustc --version
- name: install aarch64-linux-gnu
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
set -e
sudo apt-get update -y -qq
sudo apt-get install g++-aarch64-linux-gnu

- name: caching
uses: Swatinem/rust-cache@v2
with:
key: build-${{ matrix.target }}-${{ env.CACHE_SUFFIX }}

- name: Build
run: cargo build --verbose --target ${{ matrix.target }}

test:
strategy:
matrix:
include:
# Windows
- name: Windows x86_64
os: windows-2022
backends: dx12

# MacOS
# - name: MacOS aarch64
# os: macos-12
# target: aarch64-apple-darwin
# backends: metal

# Linux
# - name: Linux x86_64
# os: ubuntu-22.04
# backends: vulkan gl

name: Test ${{ matrix.name }}

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest
- name: install swiftshader
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
set -e

mkdir -p swiftshader
curl -LsSf https://github.com/gfx-rs/ci-build/releases/latest/download/swiftshader-linux-x86_64.tar.xz | tar -xf - -C swiftshader

echo "VK_ICD_FILENAMES=$PWD/swiftshader/vk_swiftshader_icd.json" >> $GITHUB_ENV
- name: install llvmpipe, vulkan sdk
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
set -e

sudo apt-get update -y -qq

# vulkan sdk
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list

sudo apt-get update
sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev vulkan-sdk

- name: caching
uses: Swatinem/rust-cache@v2
with:
key: build-${{ matrix.os }}-${{ env.CACHE_SUFFIX }}

- name: run tests
shell: bash
run: |
set -e

for backend in ${{ matrix.backends }}; do
echo "======= NATIVE TESTS $backend ======";
WGPU_BACKEND=$backend cargo nextest run
done
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use threerender::{CameraStyle, LightBaseStyle, LightStyle, RendererBuilder, Hemi

fn main() {
let (width, height) = (2000, 1500);
let mut renderer_builder = RendererBuilder::new();
let mut renderer_builder = pollster::block_on(RendererBuilder::new());
renderer_builder.set_width(width);
renderer_builder.set_height(height);
renderer_builder.set_background(RGBA::new(0, 0, 0, 1));
Expand Down
5 changes: 5 additions & 0 deletions examples/camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name="camera"
path="src/main.rs"

[features]
default = ["wgpu"]

Expand All @@ -15,3 +19,4 @@ examples_common = { path = "../common" }
wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true }
winit = "0.27.5"
image = "0.24.5"
pollster = "0.2.5"
5 changes: 3 additions & 2 deletions examples/camera/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ fn main() {
#[test]
fn test_image() {
let renderer_builder = build();
let mut renderer =
threerender::renderer::Renderer::new::<winit::window::Window>(renderer_builder, None);
let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::<
winit::window::Window,
>(renderer_builder, None));
renderer.render();
let buf = renderer.load_as_image();
let mut file = std::fs::File::create("./test.png").unwrap();
Expand Down
12 changes: 12 additions & 0 deletions examples/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]

[dependencies]
threerender = { path = "../../threerender" }
env_logger = "0.10.0"
winit = "0.27.5"
pollster = "0.2.5"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
console_log = "0.2"
js-sys = "0.3.63"
wasm-bindgen = "0.2.86"
wasm-bindgen-futures = "0.4.34"
wasm-bindgen-test = "0.3"
web-sys = "0.3.61"
6 changes: 3 additions & 3 deletions examples/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pub enum CustomEvent {

type StaticUpdater = Box<dyn Updater<Event = CustomEvent>>;

fn run(
async fn run(
event_loop: EventLoop<()>,
window: Window,
renderer_builder: RendererBuilder,
mut updater: StaticUpdater,
) {
let mut renderer = Renderer::new(renderer_builder, Some(&window));
let mut renderer = Renderer::new(renderer_builder, Some(&window)).await;
let mut cur_event = CustomEvent::ReDraw;

event_loop.run(move |event, _, control_flow| {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn start(renderer_builder: RendererBuilder, updater: StaticUpdater) {
{
env_logger::init();
// Temporarily avoid srgb formats for the swapchain on the web
run(event_loop, window, renderer_builder, updater);
pollster::block_on(run(event_loop, window, renderer_builder, updater));
}
#[cfg(target_arch = "wasm32")]
{
Expand Down
5 changes: 5 additions & 0 deletions examples/draw_lines/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name="draw_lines"
path="src/main.rs"

[dependencies]
threerender = { path = "../../threerender" }
examples_common = { path = "../common" }
winit = "0.27.5"
image = "0.24.5"
pollster = "0.2.5"
5 changes: 3 additions & 2 deletions examples/draw_lines/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ fn main() {
#[test]
fn test_image() {
let renderer_builder = build();
let mut renderer =
threerender::renderer::Renderer::new::<winit::window::Window>(renderer_builder, None);
let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::<
winit::window::Window,
>(renderer_builder, None));
renderer.render();
let buf = renderer.load_as_image();
let mut file = std::fs::File::create("./test.png").unwrap();
Expand Down
5 changes: 5 additions & 0 deletions examples/dynamic_entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name="dynamic_entity"
path="src/main.rs"

[features]
default = ["wgpu"]

Expand All @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true }
image = "0.24.5"
rand = "0.8.5"
winit = "0.27.5"
pollster = "0.2.5"
5 changes: 3 additions & 2 deletions examples/dynamic_entity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ fn test_image() {
sphere,
rand: Box::new(Rand { cnt: 0. }),
};
let mut renderer =
threerender::renderer::Renderer::new::<winit::window::Window>(renderer_builder, None);
let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::<
winit::window::Window,
>(renderer_builder, None));

app.update(&mut renderer, CustomEvent::MouseDown);
app.update(&mut renderer, CustomEvent::MouseDown);
Expand Down
5 changes: 5 additions & 0 deletions examples/gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name="gltf"
path="src/main.rs"

[features]
default = ["wgpu", "duck"]
duck = []
Expand All @@ -20,3 +24,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true }
gltf = { version = "1.1.0" }
winit = "0.27.5"
image = "0.24.5"
pollster = "0.2.5"
5 changes: 3 additions & 2 deletions examples/gltf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ fn main() {
#[test]
fn test_image() {
let renderer_builder = build();
let mut renderer =
threerender::renderer::Renderer::new::<winit::window::Window>(renderer_builder, None);
let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::<
winit::window::Window,
>(renderer_builder, None));
renderer.render();
let buf = renderer.load_as_image();
let mut file = std::fs::File::create("./test.png").unwrap();
Expand Down
5 changes: 5 additions & 0 deletions examples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name="hello_world"
path="src/main.rs"

[features]
default = ["wgpu"]

Expand All @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true }
glam = "0.22.0"
winit = "0.27.5"
image = "0.24.5"
pollster = "0.2.5"
Loading