Workspaces (#626)

We can put everything except 'agb' and the 'agb-tracker' crates in a
workspace for hopefully easier management :)

- [x] no changelog update needed
This commit is contained in:
Gwilym Inzani 2024-04-09 21:45:59 +01:00 committed by GitHub
commit 11b51e0a75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 63 additions and 42 deletions

44
Cargo.toml Normal file
View file

@ -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-debug",
"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",
]

View file

@ -1,6 +0,0 @@
[workspace]
members = [
"mgba",
"mgba-sys",
"test-runner"
]

View file

@ -15,7 +15,6 @@ pub enum LogLevel {
Unknown, Unknown,
} }
#[derive(Debug, Error)] #[derive(Debug, Error)]
#[error("A log level of {provided_log_level} does not match any known log level")] #[error("A log level of {provided_log_level} does not match any known log level")]
pub struct LogLevelIsNotValid { pub struct LogLevelIsNotValid {
@ -34,9 +33,11 @@ impl TryFrom<mgba_sys::mLogLevel> for LogLevel {
mgba_sys::mLogLevel_mLOG_DEBUG => LogLevel::Debug, mgba_sys::mLogLevel_mLOG_DEBUG => LogLevel::Debug,
mgba_sys::mLogLevel_mLOG_STUB => LogLevel::Stub, mgba_sys::mLogLevel_mLOG_STUB => LogLevel::Stub,
mgba_sys::mLogLevel_mLOG_GAME_ERROR => LogLevel::GameError, 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) 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,
);
} }
} }
} }

View file

@ -113,14 +113,14 @@ impl<V: VFile> VFileAlloc<V> {
} }
pub(crate) fn into_mgba(self) -> *mut mgba_sys::VFile { pub(crate) fn into_mgba(self) -> *mut mgba_sys::VFile {
let f = Box::into_raw(self.0) as *mut VFileInner<V>; let f = Box::into_raw(self.0);
f.cast() f.cast()
} }
} }
mod vfile_extern { mod vfile_extern {
use std::io::SeekFrom;
use super::VFileExtensions; use super::VFileExtensions;
use std::io::SeekFrom;
/// Safety: Must be part of a VFileInner /// Safety: Must be part of a VFileInner
pub unsafe fn create_vfile<V: super::VFile>() -> mgba_sys::VFile { pub unsafe fn create_vfile<V: super::VFile>() -> mgba_sys::VFile {

View file

@ -1,20 +1,15 @@
use std::path::Path; use std::path::Path;
use image::{io::Reader, DynamicImage}; use image::io::Reader;
pub struct ComparisonResult { pub struct ComparisonResult {
matches: bool, matches: bool,
image: DynamicImage,
} }
impl ComparisonResult { impl ComparisonResult {
pub fn success(&self) -> bool { pub fn success(&self) -> bool {
self.matches self.matches
} }
pub fn image(&self) -> &DynamicImage {
&self.image
}
} }
const WIDTH: usize = 240; const WIDTH: usize = 240;
@ -36,10 +31,7 @@ pub fn compare_image(
let (exp_dim_x, exp_dim_y) = expected_buffer.dimensions(); let (exp_dim_x, exp_dim_y) = expected_buffer.dimensions();
if exp_dim_x != WIDTH as u32 || exp_dim_y != HEIGHT as u32 { if exp_dim_x != WIDTH as u32 || exp_dim_y != HEIGHT as u32 {
return Ok(ComparisonResult { return Ok(ComparisonResult { matches: false });
matches: false,
image: expected,
});
} }
for y in 0..HEIGHT { 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); let image_pixel = convert_rgba_to_nearest_gba_colour(image_pixel.0);
if image_pixel[0..3] != video_pixel.to_le_bytes()[0..3] { if image_pixel[0..3] != video_pixel.to_le_bytes()[0..3] {
return Ok(ComparisonResult { return Ok(ComparisonResult { matches: false });
matches: false,
image: expected,
});
} }
} }
} }
Ok(ComparisonResult { Ok(ComparisonResult { matches: true })
matches: true,
image: expected,
})
} }

View file

@ -11,21 +11,15 @@ build-release:
just _build-release tracker/agb-tracker just _build-release tracker/agb-tracker
clippy: clippy:
just _all-crates _clippy just _all-crates _clippy
just _clippy tools
test: test:
just _test-debug agb just _test-debug agb
just _test-multiboot just _test-multiboot
just _test-debug agb-fixnum
just _test-debug agb-hashmap
just _test-debug tracker/agb-tracker just _test-debug tracker/agb-tracker
just _test-debug-arm agb just _test-debug-arm agb
just _test-debug tools
just _test-debug emulator
test-release: test-release:
just _test-release agb just _test-release agb
just _test-release agb-fixnum
just _test-release tracker/agb-tracker just _test-release tracker/agb-tracker
just _test-release-arm agb just _test-release-arm agb
@ -35,8 +29,7 @@ doctest-agb:
check-docs: check-docs:
(cd agb && cargo doc --target=thumbv4t-none-eabi --no-deps) (cd agb && cargo doc --target=thumbv4t-none-eabi --no-deps)
(cd tracker/agb-tracker && 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 cargo doc --no-deps
just _build_docs agb-hashmap
_build_docs crate: _build_docs crate:
(cd "{{crate}}" && cargo doc --no-deps) (cd "{{crate}}" && cargo doc --no-deps)
@ -46,10 +39,9 @@ clean:
fmt: fmt:
just _all-crates _fmt just _all-crates _fmt
just _fmt tools
fmt-check: fmt-check:
just _all-crates _fmt-check just _all-crates _fmt-check
just _fmt-check tools
run-example example: run-example example:
just _build-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}}) (cd agb-debug && cargo build --release && cd "{{invocation_directory()}}" && "$CARGO_TARGET_DIR/release/agb-debug" {{args}})
_all-crates target: _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"); \ PROJECT_DIR=$(dirname "$CARGO_PROJECT_FILE"); \
just "{{target}}" "$PROJECT_DIR" || exit $?; \ just "{{target}}" "$PROJECT_DIR" || exit $?; \
done done