From 307c9459214846d22b7e5911da00a42ac0672d31 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Mon, 22 Jul 2024 11:24:20 +0300 Subject: [PATCH 1/3] Added sdl+vitagl example --- .github/workflows/ci.yml | 6 ++++ .github/workflows/release.yml | 6 ++++ Cargo.lock | 44 ++++++++++++++++++++++++++++++ crates/4-vitasdk/src/debug/font.rs | 2 -- crates/5-vitasdk-gles/Cargo.toml | 19 +++++++++++++ crates/5-vitasdk-gles/src/main.rs | 43 +++++++++++++++++++++++++++++ northfear-sdl2/VITABUILD | 28 +++++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 crates/5-vitasdk-gles/Cargo.toml create mode 100644 crates/5-vitasdk-gles/src/main.rs create mode 100644 northfear-sdl2/VITABUILD diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c45c2f..cc0e552 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Install Northfear SDL fork + run: | + chown -R 1000:1000 northfear-sdl2 + cd northfear-sdl2 + sudo --preserve-env=VITASDK -u \#1000 vita-makepkg + vdpm sdl2-2.30.2-1-arm.tar.xz - name: Build run: | cargo vita build vpk --release --package vita-std-tests --tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 02e9a8b..c780bad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - name: Install Northfear SDL fork + run: | + chown -R 1000:1000 northfear-sdl2 + cd northfear-sdl2 + sudo --preserve-env=VITASDK -u \#1000 vita-makepkg + vdpm sdl2-2.30.2-1-arm.tar.xz - name: Build run: | cargo vita build vpk --release --package vita-std-tests --tests diff --git a/Cargo.lock b/Cargo.lock index a6e9238..77067ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -248,6 +248,26 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "gl" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81457bb802910ad5b535eb48541c51830a761804aa5b7087adbc9d049aa57aca" +dependencies = [ + "gl_generator", +] + +[[package]] +name = "gl_generator" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + [[package]] name = "h2" version = "0.3.21" @@ -399,6 +419,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "khronos_api" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037ab472c33f67b5fbd3e9163a2645319e5356fcd355efa6d4eb7fff4bbcb554" + [[package]] name = "lazy_static" version = "1.4.0" @@ -1132,6 +1158,15 @@ dependencies = [ "sdl2", ] +[[package]] +name = "vita-example-sdl-gles" +version = "0.1.0" +dependencies = [ + "gl", + "rand", + "sdl2", +] + [[package]] name = "vita-example-vitasdk" version = "0.1.0" @@ -1360,3 +1395,12 @@ dependencies = [ "cfg-if", "windows-sys", ] + +[[package]] +name = "xml-rs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1cb601d29fe2c2ac60a2b2e5e293994d87a1f6fa9687a31a15270f909be9c2" +dependencies = [ + "bitflags 1.3.2", +] diff --git a/crates/4-vitasdk/src/debug/font.rs b/crates/4-vitasdk/src/debug/font.rs index 6ccba7b..eaea6db 100644 --- a/crates/4-vitasdk/src/debug/font.rs +++ b/crates/4-vitasdk/src/debug/font.rs @@ -3,7 +3,6 @@ pub struct DebugFont { pub width: usize, pub height: usize, pub first: u8, - pub last: u8, pub size_w: usize, pub size_h: usize, } @@ -13,7 +12,6 @@ pub const DEBUG_FONT: DebugFont = DebugFont { width: 8, height: 8, first: 0, - last: 255, size_w: 8, size_h: 8, }; diff --git a/crates/5-vitasdk-gles/Cargo.toml b/crates/5-vitasdk-gles/Cargo.toml new file mode 100644 index 0000000..3e791e5 --- /dev/null +++ b/crates/5-vitasdk-gles/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "vita-example-sdl-gles" +version = "0.1.0" +edition = "2021" + +license = "MIT OR Apache-2.0" +repository = "https://github.com/vita-rust/examples" +homepage = "https://github.com/vita-rust/examples/crates/4-vitasdk" + +description = "VITASDK example" + +[dependencies] +rand = "0.8.5" +gl = "0.10.0" +sdl2 = { version = "0.35.2", features = ["use-pkgconfig"] } + +[package.metadata.vita] +title_id = "RUSTTEST5" +title_name = "SDL+GL test" diff --git a/crates/5-vitasdk-gles/src/main.rs b/crates/5-vitasdk-gles/src/main.rs new file mode 100644 index 0000000..9ac44c8 --- /dev/null +++ b/crates/5-vitasdk-gles/src/main.rs @@ -0,0 +1,43 @@ +#[link(name = "SDL2", kind = "static")] +#[link(name = "vitaGL", kind = "static")] +#[link(name = "vitashark", kind = "static")] +#[link(name = "SceShaccCg_stub", kind = "static")] +#[link(name = "mathneon", kind = "static")] +#[link(name = "SceShaccCgExt", kind = "static")] +#[link(name = "taihen_stub", kind = "static")] +#[link(name = "SceKernelDmacMgr_stub", kind = "static")] +#[link(name = "SceIme_stub", kind = "static")] +extern "C" {} + +fn main() { + let sdl = sdl2::init().unwrap(); + let video_subsystem = sdl.video().unwrap(); + let window = video_subsystem + .window("Game", 900, 700) + .opengl() + .build() + .unwrap(); + + let _gl_context = window.gl_create_context().unwrap(); + let _gl = gl::load_with(|s| video_subsystem.gl_get_proc_address(s) as *const std::os::raw::c_void); + + unsafe { + gl::ClearColor(0.3, 0.3, 0.5, 1.0); + } + + let mut event_pump = sdl.event_pump().unwrap(); + 'main: loop { + for event in event_pump.poll_iter() { + match event { + sdl2::event::Event::Quit {..} => break 'main, + _ => {}, + } + } + + unsafe { + gl::Clear(gl::COLOR_BUFFER_BIT); + } + + window.gl_swap_window(); + } +} diff --git a/northfear-sdl2/VITABUILD b/northfear-sdl2/VITABUILD new file mode 100644 index 0000000..8a099c1 --- /dev/null +++ b/northfear-sdl2/VITABUILD @@ -0,0 +1,28 @@ +pkgname=sdl2 +pkgver=2.30.2 +pkgrel=1 +gitrev=0867aceb28a493b489f54a3407a3b820b092206a +url='https://www.libsdl.org' +source=( + "https://github.com/Northfear/SDL/archive/${gitrev}.tar.gz" + ) +sha256sums=( + SKIP +) + +prepare() { + cd "SDL-${gitrev}" +} + +build() { + cd "SDL-${gitrev}" + mkdir build && cd build + cmake .. -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=Release -DSDL_TEST=OFF -DVIDEO_VITA_VGL=ON + make -j$(nproc) +} + +package () { + cd "SDL-${gitrev}" + cd build + make DESTDIR=$pkgdir install +} From 889f04b23ccc0a7f380a75089c2b0e7aa8a7ebac Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Mon, 22 Jul 2024 11:29:31 +0300 Subject: [PATCH 2/3] try_exists was stabilized as ::exists --- crates/0-std-tests/src/lib.rs | 2 -- crates/0-std-tests/src/tests_fs.rs | 6 +++--- crates/3-sdl/src/main.rs | 13 +++++++++++++ crates/4-vitasdk/src/main.rs | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/0-std-tests/src/lib.rs b/crates/0-std-tests/src/lib.rs index dc3b9e2..893f7fd 100644 --- a/crates/0-std-tests/src/lib.rs +++ b/crates/0-std-tests/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(fs_try_exists)] - mod tests_fs; mod tests_pthread; mod tests_tcp; diff --git a/crates/0-std-tests/src/tests_fs.rs b/crates/0-std-tests/src/tests_fs.rs index 3c058d3..9a74a1d 100644 --- a/crates/0-std-tests/src/tests_fs.rs +++ b/crates/0-std-tests/src/tests_fs.rs @@ -6,7 +6,7 @@ mod tests { impl Drop for FsScope { fn drop(&mut self) { - if fs::try_exists("ux0:/data/.rust_test").unwrap_or(false) { + if fs::exists("ux0:/data/.rust_test").unwrap_or(false) { fs::remove_dir_all("ux0:/data/.rust_test").expect("unable to cleanup"); } } @@ -54,7 +54,7 @@ mod tests { assert!(&data == "contents", "invalid file contents"); assert!( - fs::try_exists("ux0:/data/.rust_test/file").unwrap(), + fs::exists("ux0:/data/.rust_test/file").unwrap(), "file does not exist", ); @@ -69,7 +69,7 @@ mod tests { fs::remove_file("ux0:/data/.rust_test/file").expect("unable to delete file"); assert!( - !fs::try_exists("ux0:/data/.rust_test/file").unwrap(), + !fs::exists("ux0:/data/.rust_test/file").unwrap(), "file exists, but should not", ); diff --git a/crates/3-sdl/src/main.rs b/crates/3-sdl/src/main.rs index 5ab4b82..0f559ae 100644 --- a/crates/3-sdl/src/main.rs +++ b/crates/3-sdl/src/main.rs @@ -1,3 +1,16 @@ +// These linker flags are only necessary with Northfear SDL2 fork +#[link(name = "SDL2", kind = "static")] +#[link(name = "vitaGL", kind = "static")] +#[link(name = "vitashark", kind = "static")] +#[link(name = "SceShaccCg_stub", kind = "static")] +#[link(name = "mathneon", kind = "static")] +#[link(name = "SceShaccCgExt", kind = "static")] +#[link(name = "taihen_stub", kind = "static")] +#[link(name = "SceKernelDmacMgr_stub", kind = "static")] +#[link(name = "SceIme_stub", kind = "static")] +extern "C" {} + + use crate::game_of_life::{PLAYGROUND_HEIGHT, PLAYGROUND_WIDTH, SQUARE_SIZE}; use sdl2::keyboard::Keycode; use sdl2::mouse::MouseButton; diff --git a/crates/4-vitasdk/src/main.rs b/crates/4-vitasdk/src/main.rs index fb40137..a67e505 100644 --- a/crates/4-vitasdk/src/main.rs +++ b/crates/4-vitasdk/src/main.rs @@ -1,6 +1,6 @@ use std::backtrace::Backtrace; use std::fmt::Write; -use std::panic::{self, PanicInfo}; +use std::panic::{self, PanicHookInfo}; use std::thread; use std::time::Duration; @@ -25,7 +25,7 @@ pub fn main() { thread::sleep(Duration::from_secs(5)); } -fn custom_panic_hook(info: &PanicInfo<'_>) { +fn custom_panic_hook(info: &PanicHookInfo<'_>) { // The current implementation always returns `Some`. let location = info.location().unwrap(); From cbb8ab6b29970d6d9bc4d85c4782efe3b32173ae Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Tue, 23 Jul 2024 12:05:35 +0300 Subject: [PATCH 3/3] Dynamic version resolution --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 2 +- northfear-sdl2/.gitignore | 4 ++++ northfear-sdl2/VITABUILD | 14 +++++++++++--- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 northfear-sdl2/.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc0e552..87d49e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: chown -R 1000:1000 northfear-sdl2 cd northfear-sdl2 sudo --preserve-env=VITASDK -u \#1000 vita-makepkg - vdpm sdl2-2.30.2-1-arm.tar.xz + vdpm sdl2-*-arm.tar.xz - name: Build run: | cargo vita build vpk --release --package vita-std-tests --tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c780bad..a287ea0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: chown -R 1000:1000 northfear-sdl2 cd northfear-sdl2 sudo --preserve-env=VITASDK -u \#1000 vita-makepkg - vdpm sdl2-2.30.2-1-arm.tar.xz + vdpm sdl2-*-arm.tar.xz - name: Build run: | cargo vita build vpk --release --package vita-std-tests --tests diff --git a/northfear-sdl2/.gitignore b/northfear-sdl2/.gitignore new file mode 100644 index 0000000..0f3bb3b --- /dev/null +++ b/northfear-sdl2/.gitignore @@ -0,0 +1,4 @@ +src +pkg +*gz +*xz diff --git a/northfear-sdl2/VITABUILD b/northfear-sdl2/VITABUILD index 8a099c1..7f1dcfe 100644 --- a/northfear-sdl2/VITABUILD +++ b/northfear-sdl2/VITABUILD @@ -1,5 +1,5 @@ pkgname=sdl2 -pkgver=2.30.2 +pkgver=2.24.0 pkgrel=1 gitrev=0867aceb28a493b489f54a3407a3b820b092206a url='https://www.libsdl.org' @@ -10,14 +10,22 @@ sha256sums=( SKIP ) +pkgver() { + cd "SDL-${gitrev}" + ref_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION *//p' include/SDL_version.h) + ref_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION *//p' include/SDL_version.h) + ref_micro=$(sed -ne 's/^#define SDL_PATCHLEVEL *//p' include/SDL_version.h) + echo "${ref_major}.${ref_minor}.${ref_micro}" +} + prepare() { cd "SDL-${gitrev}" } build() { cd "SDL-${gitrev}" - mkdir build && cd build - cmake .. -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=Release -DSDL_TEST=OFF -DVIDEO_VITA_VGL=ON + rm -rf build; mkdir build && cd build + cmake .. -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=Release -DSDL_TEST=OFF -DVIDEO_VITA_VGL=ON make -j$(nproc) }