From 52ddd97a2e74e76591914c332dd4cd2affbb7db9 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 20:54:12 +0100 Subject: [PATCH 1/6] Switch to cargo workspaces for every crate we support --- Cargo.toml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Cargo.toml diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..78b11380 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,44 @@ +[workspace] + +resolver = "2" + +# unfortunately we can't include 'agb' or anything which compiles to non-native code +# in the workspace here, and they need to be tracked separately. +members = [ + # "agb" + "agb-addr2line", + "agb-fixnum", + "agb-gbafix", + "agb-hashmap", + "agb-image-converter", + "agb-macros", + "agb-sound-converter", + + "tracker/agb-midi", + "tracker/agb-midi-core", + "tracker/agb-tracker-interop", + # "tracker/agb-tracker", + "tracker/agb-xm", + "tracker/agb-xm-core", + + "tools", + + "emulator/mgba", + "emulator/mgba-sys", + "emulator/test-runner", +] + +exclude = [ + "agb", + + "tracker/agb-tracker", + + "examples/amplitude", + "examples/combo", + "examples/hyperspace-roll", + "examples/the-dungeon-puzzlers-lament", + "examples/the-hat-chooses-the-wizard", + "examples/the-purple-night", + + "book/games/pong", +] From 08ad8765de4f28aaab36899d038b1b25261bc30b Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 20:55:21 +0100 Subject: [PATCH 2/6] Fix clippy lint and fmt in the emulator --- emulator/mgba/src/log.rs | 15 ++++++++++----- emulator/mgba/src/vfile.rs | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/emulator/mgba/src/log.rs b/emulator/mgba/src/log.rs index 663a2421..6e7b32f7 100644 --- a/emulator/mgba/src/log.rs +++ b/emulator/mgba/src/log.rs @@ -15,7 +15,6 @@ pub enum LogLevel { Unknown, } - #[derive(Debug, Error)] #[error("A log level of {provided_log_level} does not match any known log level")] pub struct LogLevelIsNotValid { @@ -34,9 +33,11 @@ impl TryFrom for LogLevel { mgba_sys::mLogLevel_mLOG_DEBUG => LogLevel::Debug, mgba_sys::mLogLevel_mLOG_STUB => LogLevel::Stub, mgba_sys::mLogLevel_mLOG_GAME_ERROR => LogLevel::GameError, - _ => return Err(LogLevelIsNotValid { - provided_log_level: value - }) + _ => { + return Err(LogLevelIsNotValid { + provided_log_level: value, + }) + } }) } } @@ -95,7 +96,11 @@ extern "C" fn log_string_wrapper( unsafe { CStr::from_ptr(category_c_name).to_str() }.unwrap_or(UNKNOWN) }; - logger(category_name, LogLevel::try_from(level).unwrap_or(LogLevel::Unknown), s); + logger( + category_name, + LogLevel::try_from(level).unwrap_or(LogLevel::Unknown), + s, + ); } } } diff --git a/emulator/mgba/src/vfile.rs b/emulator/mgba/src/vfile.rs index 97092b3f..0a36b87a 100644 --- a/emulator/mgba/src/vfile.rs +++ b/emulator/mgba/src/vfile.rs @@ -113,14 +113,14 @@ impl VFileAlloc { } pub(crate) fn into_mgba(self) -> *mut mgba_sys::VFile { - let f = Box::into_raw(self.0) as *mut VFileInner; + let f = Box::into_raw(self.0); f.cast() } } mod vfile_extern { - use std::io::SeekFrom; use super::VFileExtensions; + use std::io::SeekFrom; /// Safety: Must be part of a VFileInner pub unsafe fn create_vfile() -> mgba_sys::VFile { From 65388e01f5dcf96a3e901a7302b6d455375e9677 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 20:56:19 +0100 Subject: [PATCH 3/6] Fix more clippy lints in the emulator --- emulator/test-runner/src/image_compare.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/emulator/test-runner/src/image_compare.rs b/emulator/test-runner/src/image_compare.rs index 413d2e00..13a0b027 100644 --- a/emulator/test-runner/src/image_compare.rs +++ b/emulator/test-runner/src/image_compare.rs @@ -1,20 +1,15 @@ use std::path::Path; -use image::{io::Reader, DynamicImage}; +use image::io::Reader; pub struct ComparisonResult { matches: bool, - image: DynamicImage, } impl ComparisonResult { pub fn success(&self) -> bool { self.matches } - - pub fn image(&self) -> &DynamicImage { - &self.image - } } const WIDTH: usize = 240; @@ -36,10 +31,7 @@ pub fn compare_image( let (exp_dim_x, exp_dim_y) = expected_buffer.dimensions(); if exp_dim_x != WIDTH as u32 || exp_dim_y != HEIGHT as u32 { - return Ok(ComparisonResult { - matches: false, - image: expected, - }); + return Ok(ComparisonResult { matches: false }); } for y in 0..HEIGHT { @@ -49,16 +41,10 @@ pub fn compare_image( let image_pixel = convert_rgba_to_nearest_gba_colour(image_pixel.0); if image_pixel[0..3] != video_pixel.to_le_bytes()[0..3] { - return Ok(ComparisonResult { - matches: false, - image: expected, - }); + return Ok(ComparisonResult { matches: false }); } } } - Ok(ComparisonResult { - matches: true, - image: expected, - }) + Ok(ComparisonResult { matches: true }) } From 36cdc9e28d8e8c1d729ebb849e86a9cda1f006da Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 21:06:08 +0100 Subject: [PATCH 4/6] Don't need this workspace any more --- emulator/Cargo.toml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 emulator/Cargo.toml diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml deleted file mode 100644 index ac17e7bb..00000000 --- a/emulator/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[workspace] -members = [ - "mgba", - "mgba-sys", - "test-runner" -] \ No newline at end of file From 7a059b2142417298d55a7ec972601af422a688fc Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 21:06:16 +0100 Subject: [PATCH 5/6] This is called agb-debug --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 78b11380..9334e895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ resolver = "2" # in the workspace here, and they need to be tracked separately. members = [ # "agb" - "agb-addr2line", + "agb-debug", "agb-fixnum", "agb-gbafix", "agb-hashmap", From b963065ad6c6c59eb3ab510b9fa18429e473cabe Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 Apr 2024 21:06:21 +0100 Subject: [PATCH 6/6] Update the justfile --- justfile | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/justfile b/justfile index f04558b5..848cf761 100644 --- a/justfile +++ b/justfile @@ -11,21 +11,15 @@ build-release: just _build-release tracker/agb-tracker clippy: just _all-crates _clippy - just _clippy tools test: just _test-debug agb just _test-multiboot - just _test-debug agb-fixnum - just _test-debug agb-hashmap just _test-debug tracker/agb-tracker just _test-debug-arm agb - just _test-debug tools - just _test-debug emulator test-release: just _test-release agb - just _test-release agb-fixnum just _test-release tracker/agb-tracker just _test-release-arm agb @@ -35,8 +29,7 @@ doctest-agb: check-docs: (cd agb && cargo doc --target=thumbv4t-none-eabi --no-deps) (cd tracker/agb-tracker && cargo doc --target=thumbv4t-none-eabi --no-deps) - just _build_docs agb-fixnum - just _build_docs agb-hashmap + cargo doc --no-deps _build_docs crate: (cd "{{crate}}" && cargo doc --no-deps) @@ -46,10 +39,9 @@ clean: fmt: just _all-crates _fmt - just _fmt tools + fmt-check: just _all-crates _fmt-check - just _fmt-check tools run-example example: just _build-example "{{example}}" @@ -148,7 +140,7 @@ debug *args: (cd agb-debug && cargo build --release && cd "{{invocation_directory()}}" && "$CARGO_TARGET_DIR/release/agb-debug" {{args}}) _all-crates target: - for CARGO_PROJECT_FILE in agb-*/Cargo.toml agb/Cargo.toml tracker/agb-*/Cargo.toml; do \ + for CARGO_PROJECT_FILE in agb/Cargo.toml tracker/agb-tracker/Cargo.toml ./Cargo.toml; do \ PROJECT_DIR=$(dirname "$CARGO_PROJECT_FILE"); \ just "{{target}}" "$PROJECT_DIR" || exit $?; \ done