diff --git a/.github/workflows/publish-agb-fixnum.yml b/.github/workflows/publish-agb-fixnum.yml new file mode 100644 index 00000000..3ff76916 --- /dev/null +++ b/.github/workflows/publish-agb-fixnum.yml @@ -0,0 +1,20 @@ +name: Publish agb-fixnum + +on: + push: + tags: + - agb-fixnum/v* + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Install build tools + run: sudo apt-get update && sudo apt-get install build-essential binutils-arm-none-eabi -y + - name: Check out repository + uses: actions/checkout@v2 + - name: Login to crates.io + run: cargo login ${{ secrets.CRATE_API }} + - name: Publish agb-fixnum + run: cargo publish + working-directory: ./agb-fixnum \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 87d522cf..aa5c65e1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,6 +46,12 @@ jobs: - name: Run Clippy on agb macros working-directory: agb-macros run: cargo clippy --verbose + - name: Run Clippy on agb fixnum + working-directory: agb-fixnum + run: cargo clippy --verbose + - name: Run Tests for fixnum + working-directory: agb-fixnum + run: cargo test --verbose - name: Run Tests for agb in debug mode working-directory: agb run: cargo test --verbose diff --git a/agb-fixnum/Cargo.lock b/agb-fixnum/Cargo.lock new file mode 100644 index 00000000..2eeb5cf7 --- /dev/null +++ b/agb-fixnum/Cargo.lock @@ -0,0 +1,130 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "agb_fixnum" +version = "0.1.0" +dependencies = [ + "agb_macros", +] + +[[package]] +name = "agb_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "rand", + "syn", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "syn" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff --git a/agb-fixnum/Cargo.toml b/agb-fixnum/Cargo.toml new file mode 100644 index 00000000..96031bdd --- /dev/null +++ b/agb-fixnum/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "agb_fixnum" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +agb_macros = { version = "0.1.0", path = "../agb-macros" } diff --git a/agb/src/number.rs b/agb-fixnum/src/lib.rs similarity index 91% rename from agb/src/number.rs rename to agb-fixnum/src/lib.rs index f85f344c..d093dba3 100644 --- a/agb/src/number.rs +++ b/agb-fixnum/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use core::{ cmp::{Eq, Ord, PartialEq, PartialOrd}, fmt::{Debug, Display}, @@ -10,7 +12,7 @@ use core::{ #[macro_export] macro_rules! num { ($value:literal) => {{ - $crate::number::Num::new_from_parts(agb_macros::num!($value)) + $crate::Num::new_from_parts(agb_macros::num!($value)) }}; } @@ -471,34 +473,6 @@ where } } -#[cfg(feature = "alloc")] -#[cfg(test)] -mod formatting_tests { - use super::Num; - use alloc::format; - - #[test_case] - fn formats_whole_numbers_correctly(_gba: &mut crate::Gba) { - let a = Num::::new(-4i32); - - assert_eq!(format!("{}", a), "-4"); - } - - #[test_case] - fn formats_fractions_correctly(_gba: &mut crate::Gba) { - let a = Num::::new(5); - let two = Num::::new(4); - let minus_one = Num::::new(-1); - - let b: Num = a / two; - let c: Num = b * minus_one; - - assert_eq!(b + c, 0.into()); - assert_eq!(format!("{}", b), "1.25"); - assert_eq!(format!("{}", c), "-1.25"); - } -} - impl AddAssign for Vector2D { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; @@ -691,33 +665,6 @@ impl Rect { } } -#[cfg(test)] -#[test_case] -fn test_rect_iter(_gba: &mut crate::Gba) { - let rect: Rect = Rect::new((5_i32, 5_i32).into(), (3_i32, 3_i32).into()); - assert_eq!( - rect.iter().collect::>(), - &[ - (5, 5), - (6, 5), - (7, 5), - (8, 5), - (5, 6), - (6, 6), - (7, 6), - (8, 6), - (5, 7), - (6, 7), - (7, 7), - (8, 7), - (5, 8), - (6, 8), - (7, 8), - (8, 8), - ] - ); -} - impl Vector2D { pub fn new(x: T, y: T) -> Self { Vector2D { x, y } @@ -746,18 +693,43 @@ impl Vector2D { #[cfg(test)] mod tests { - use super::*; - #[test_case] - fn sqrt(_gba: &mut crate::Gba) { + extern crate alloc; + + use super::*; + use alloc::format; + + #[test] + fn formats_whole_numbers_correctly() { + let a = Num::::new(-4i32); + + assert_eq!(format!("{}", a), "-4"); + } + + #[test] + fn formats_fractions_correctly() { + let a = Num::::new(5); + let two = Num::::new(4); + let minus_one = Num::::new(-1); + + let b: Num = a / two; + let c: Num = b * minus_one; + + assert_eq!(b + c, 0.into()); + assert_eq!(format!("{}", b), "1.25"); + assert_eq!(format!("{}", c), "-1.25"); + } + + #[test] + fn sqrt() { for x in 1..1024 { let n: Num = Num::new(x * x); assert_eq!(n.sqrt(), x.into()); } } - #[test_case] - fn test_macro_conversion(_gba: &mut crate::Gba) { + #[test] + fn test_macro_conversion() { fn test_positive() { let a: Num = num!(1.5); let one = A::one() << B; @@ -797,8 +769,8 @@ mod tests { test_base::<11>(); } - #[test_case] - fn test_numbers(_gba: &mut crate::Gba) { + #[test] + fn test_numbers() { // test addition let n: Num = 1.into(); assert_eq!(n + 2, 3.into(), "testing that 1 + 2 == 3"); @@ -815,8 +787,8 @@ mod tests { assert_ne!(n, p, "testing that 30 != 3"); } - #[test_case] - fn test_division_by_one(_gba: &mut crate::Gba) { + #[test] + fn test_division_by_one() { let one: Num = 1.into(); for i in -40..40 { @@ -825,8 +797,8 @@ mod tests { } } - #[test_case] - fn test_division_and_multiplication_by_16(_gba: &mut crate::Gba) { + #[test] + fn test_division_and_multiplication_by_16() { let sixteen: Num = 16.into(); for i in -40..40 { @@ -837,8 +809,8 @@ mod tests { } } - #[test_case] - fn test_division_by_2_and_15(_gba: &mut crate::Gba) { + #[test] + fn test_division_by_2_and_15() { let two: Num = 2.into(); let fifteen: Num = 15.into(); let thirty: Num = 30.into(); @@ -851,8 +823,8 @@ mod tests { } } - #[test_case] - fn test_change_base(_gba: &mut crate::Gba) { + #[test] + fn test_change_base() { let two: Num = 2.into(); let three: Num = 3.into(); @@ -860,8 +832,8 @@ mod tests { assert_eq!(three + two.change_base(), 5.into()); } - #[test_case] - fn test_rem_returns_sensible_values_for_integers(_gba: &mut crate::Gba) { + #[test] + fn test_rem_returns_sensible_values_for_integers() { for i in -50..50 { for j in -50..50 { if j == 0 { @@ -876,8 +848,8 @@ mod tests { } } - #[test_case] - fn test_rem_returns_sensible_values_for_non_integers(_gba: &mut crate::Gba) { + #[test] + fn test_rem_returns_sensible_values_for_non_integers() { let one: Num = 1.into(); let third = one / 3; @@ -900,8 +872,8 @@ mod tests { } } - #[test_case] - fn test_rem_euclid_is_always_positive_and_sensible(_gba: &mut crate::Gba) { + #[test] + fn test_rem_euclid_is_always_positive_and_sensible() { let one: Num = 1.into(); let third = one / 3; @@ -920,8 +892,8 @@ mod tests { } } - #[test_case] - fn test_vector_multiplication_and_division(_gba: &mut crate::Gba) { + #[test] + fn test_vector_multiplication_and_division() { let a: Vector2D = (1, 2).into(); let b = a * 5; let c = b / 5; @@ -929,8 +901,8 @@ mod tests { assert_eq!(a, c); } - #[test_case] - fn magnitude_accuracy(_gba: &mut crate::Gba) { + #[test] + fn magnitude_accuracy() { let n: Vector2D> = (3, 4).into(); assert!((n.magnitude() - 5).abs() < num!(0.1)); @@ -938,8 +910,8 @@ mod tests { assert!((n.magnitude() - 5).abs() < num!(0.1)); } - #[test_case] - fn test_vector_changing(_gba: &mut crate::Gba) { + #[test] + fn test_vector_changing() { let v1: Vector2D> = Vector2D::new(1.into(), 2.into()); let v2 = v1.trunc(); @@ -947,4 +919,30 @@ mod tests { assert_eq!(v1 + v1, (v2 + v2).into()); } + + #[test] + fn test_rect_iter() { + let rect: Rect = Rect::new((5_i32, 5_i32).into(), (3_i32, 3_i32).into()); + assert_eq!( + rect.iter().collect::>(), + &[ + (5, 5), + (6, 5), + (7, 5), + (8, 5), + (5, 6), + (6, 6), + (7, 6), + (8, 6), + (5, 7), + (6, 7), + (7, 7), + (8, 7), + (5, 8), + (6, 8), + (7, 8), + (8, 8), + ] + ); + } } diff --git a/agb/Cargo.lock b/agb/Cargo.lock index 5761bf0a..ace78990 100644 --- a/agb/Cargo.lock +++ b/agb/Cargo.lock @@ -12,12 +12,20 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" name = "agb" version = "0.8.0" dependencies = [ + "agb_fixnum", "agb_image_converter", "agb_macros", "agb_sound_converter", "bitflags", ] +[[package]] +name = "agb_fixnum" +version = "0.1.0" +dependencies = [ + "agb_macros", +] + [[package]] name = "agb_image_converter" version = "0.6.0" diff --git a/agb/Cargo.toml b/agb/Cargo.toml index 22c50f9a..627bfc96 100644 --- a/agb/Cargo.toml +++ b/agb/Cargo.toml @@ -24,6 +24,7 @@ bitflags = "1.3" agb_image_converter = { version = "0.6.0", path = "../agb-image-converter" } agb_sound_converter = { version = "0.1.0", path = "../agb-sound-converter" } agb_macros = { version = "0.1.0", path = "../agb-macros" } +agb_fixnum = { version = "0.1.0", path = "../agb-fixnum" } [package.metadata.docs.rs] default-target = "thumbv6m-none-eabi" diff --git a/agb/examples/mixer_basic.rs b/agb/examples/mixer_basic.rs index c4780753..fdb39b15 100644 --- a/agb/examples/mixer_basic.rs +++ b/agb/examples/mixer_basic.rs @@ -1,8 +1,8 @@ #![no_std] #![no_main] +use agb::fixnum::Num; use agb::input::{Button, ButtonController, Tri}; -use agb::number::Num; use agb::sound::mixer::SoundChannel; use agb::{include_wav, Gba}; diff --git a/agb/examples/wave.rs b/agb/examples/wave.rs index 3e8264bb..239f60c8 100644 --- a/agb/examples/wave.rs +++ b/agb/examples/wave.rs @@ -3,8 +3,8 @@ use agb::{ display::example_logo, + fixnum::FixedNum, interrupt::{Interrupt, Mutex}, - number::FixedNum, }; struct BackCosines { diff --git a/agb/src/display/background.rs b/agb/src/display/background.rs index 7418dc41..4f6ab336 100644 --- a/agb/src/display/background.rs +++ b/agb/src/display/background.rs @@ -1,8 +1,8 @@ use core::ops::Index; use crate::{ + fixnum::{Rect, Vector2D}, memory_mapped::{MemoryMapped, MemoryMapped1DArray}, - number::{Rect, Vector2D}, }; use super::{ diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 2fbd2329..4dea6e6f 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -2,8 +2,8 @@ use core::cell::RefCell; use super::{palette16, Priority, DISPLAY_CONTROL}; use crate::bitarray::Bitarray; +use crate::fixnum::Vector2D; use crate::memory_mapped::MemoryMapped1DArray; -use crate::number::Vector2D; type AffineLoan<'a> = crate::arena::Loan<'a, 32>; type AffineArena = crate::arena::Arena<32>; diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 7e46321a..d5204c45 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -152,7 +152,7 @@ mod memory_mapped; /// Implements logging to the mgba emulator. pub mod mgba; /// Implementation of fixnums for working with non-integer values. -pub mod number; +pub use agb_fixnum as fixnum; mod single; /// Implements sound output. pub mod sound; diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 80a009d6..7b26c03a 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -4,7 +4,7 @@ mod sw_mixer; pub use sw_mixer::ChannelId; pub use sw_mixer::Mixer; -use crate::number::Num; +use crate::fixnum::Num; use crate::timer::Timer; #[non_exhaustive] diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index c9da82ab..a6db9460 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -1,7 +1,7 @@ use super::hw; use super::hw::LeftOrRight; use super::{SoundChannel, SoundPriority}; -use crate::number::Num; +use crate::fixnum::Num; use crate::timer::Timer; // Defined in mixer.s diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index ddeed8f0..bf271981 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -1,7 +1,7 @@ use core::arch::asm; use crate::display::object::AffineMatrixAttributes; -use crate::number::Num; +use crate::fixnum::Num; #[allow(non_snake_case)] diff --git a/book/games/pong/Cargo.lock b/book/games/pong/Cargo.lock index 2582c2b3..4e1b6357 100644 --- a/book/games/pong/Cargo.lock +++ b/book/games/pong/Cargo.lock @@ -12,12 +12,20 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" name = "agb" version = "0.8.0" dependencies = [ + "agb_fixnum", "agb_image_converter", "agb_macros", "agb_sound_converter", "bitflags", ] +[[package]] +name = "agb_fixnum" +version = "0.1.0" +dependencies = [ + "agb_macros", +] + [[package]] name = "agb_image_converter" version = "0.6.0" diff --git a/examples/the-hat-chooses-the-wizard/Cargo.lock b/examples/the-hat-chooses-the-wizard/Cargo.lock index 8a6e299e..96ef9a2e 100644 --- a/examples/the-hat-chooses-the-wizard/Cargo.lock +++ b/examples/the-hat-chooses-the-wizard/Cargo.lock @@ -12,12 +12,20 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" name = "agb" version = "0.8.0" dependencies = [ + "agb_fixnum", "agb_image_converter", "agb_macros", "agb_sound_converter", "bitflags", ] +[[package]] +name = "agb_fixnum" +version = "0.1.0" +dependencies = [ + "agb_macros", +] + [[package]] name = "agb_image_converter" version = "0.6.0" diff --git a/examples/the-hat-chooses-the-wizard/build.rs b/examples/the-hat-chooses-the-wizard/build.rs index 7df6d9dd..5b385333 100644 --- a/examples/the-hat-chooses-the-wizard/build.rs +++ b/examples/the-hat-chooses-the-wizard/build.rs @@ -170,7 +170,7 @@ mod tiled_export { &mut writer, r#" use crate::Level; - use agb::number::Vector2D; + use agb::fixnum::Vector2D; pub const fn get_level() -> Level {{ Level {{ diff --git a/examples/the-hat-chooses-the-wizard/src/enemies.rs b/examples/the-hat-chooses-the-wizard/src/enemies.rs index 799080c4..399474f3 100644 --- a/examples/the-hat-chooses-the-wizard/src/enemies.rs +++ b/examples/the-hat-chooses-the-wizard/src/enemies.rs @@ -1,7 +1,7 @@ use super::{object_tiles, sfx::SfxPlayer, Entity, FixedNumberType, HatState, Level}; use agb::{ display::object::{ObjectControl, Size}, - number::Vector2D, + fixnum::Vector2D, }; enum UpdateState { diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index aa5c9292..d4aa6574 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -109,8 +109,8 @@ use agb::{ object::{ObjectControl, ObjectStandard, Size}, Priority, HEIGHT, WIDTH, }, + fixnum::{FixedNum, Vector2D}, input::{self, Button, ButtonController}, - number::{FixedNum, Vector2D}, }; type FixedNumberType = FixedNum<10>; diff --git a/examples/the-purple-night/Cargo.lock b/examples/the-purple-night/Cargo.lock index 6d89970f..bebc8bad 100644 --- a/examples/the-purple-night/Cargo.lock +++ b/examples/the-purple-night/Cargo.lock @@ -12,12 +12,20 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" name = "agb" version = "0.8.0" dependencies = [ + "agb_fixnum", "agb_image_converter", "agb_macros", "agb_sound_converter", "bitflags", ] +[[package]] +name = "agb_fixnum" +version = "0.1.0" +dependencies = [ + "agb_macros", +] + [[package]] name = "agb_image_converter" version = "0.6.0" diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index 3ce4b92a..4d5df465 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -16,8 +16,8 @@ use agb::{ object::{ObjectControl, ObjectStandard}, Priority, HEIGHT, WIDTH, }, + fixnum::{FixedNum, Rect, Vector2D}, input::{Button, ButtonController, Tri}, - number::{FixedNum, Rect, Vector2D}, }; use generational_arena::Arena; diff --git a/examples/the-purple-night/src/sfx.rs b/examples/the-purple-night/src/sfx.rs index 400e5aaa..4fe33d75 100644 --- a/examples/the-purple-night/src/sfx.rs +++ b/examples/the-purple-night/src/sfx.rs @@ -1,5 +1,5 @@ use super::rng::get_random; -use agb::number::Num; +use agb::fixnum::Num; use agb::sound::mixer::{ChannelId, Mixer, SoundChannel}; const BAT_DEATH: &[u8] = agb::include_wav!("sfx/BatDeath.wav"); diff --git a/release.sh b/release.sh index 599985db..9e90d56c 100755 --- a/release.sh +++ b/release.sh @@ -47,7 +47,10 @@ case "$PROJECT" in DIRECTORY="mgba-test-runner" TAGNAME="mgba-test-runner/v$VERSION" ;; - + agb-fixnum) + DIRECTORY="agb-fixnum" + TAGNAME="agb-fixnum/v$VERSION" + ;; *) echo "Unknown project name $PROJECT" exit 1 @@ -78,25 +81,30 @@ if [ "$PROJECT" = "agb" ]; then sed -i -e "s/^agb = \".*\"/agb = \"$VERSION\"/" template/Cargo.toml git add template/Cargo.toml - for EXAMPLE_DIR in examples/*/ book/games/*/; do + for EXAMPLE_TOML_FILE in examples/*/Cargo.toml book/games/*/Cargo.toml; do + EXAMPLE_DIR=$(dirname "$EXAMPLE_TOML_FILE") sed -E -i -e "/agb =/ s/version = \"[^\"]+\"/version = \"$VERSION\"/" "$EXAMPLE_DIR/Cargo.toml" (cd "$EXAMPLE_DIR" && cargo update) git add "$EXAMPLE_DIR"/{Cargo.toml,Cargo.lock} done else PROJECT_NAME_WITH_UNDERSCORES=$(echo -n "$PROJECT" | tr - _) - sed -i -E -e "s/($PROJECT_NAME_WITH_UNDERSCORES = .*version = \")[^\"]+(\".*)/\1$VERSION\2/" agb/Cargo.toml - - (cd agb && cargo update) - git add agb/Cargo.toml agb/Cargo.lock + + for CARGO_TOML_FILE in agb-*/Cargo.toml agb/Cargo.toml examples/*/Cargo.toml book/games/*/Cargo.toml; do + sed -i -E -e "s/($PROJECT_NAME_WITH_UNDERSCORES = .*version = \")[^\"]+(\".*)/\1$VERSION\2/" "$CARGO_TOML_FILE" + (cd "$(dirname "$CARGO_TOML_FILE")" && cargo generate-lockfile) + + git add "$CARGO_TOML_FILE" "${CARGO_TOML_FILE/.toml/.lock}" + done fi # Sanity check to make sure the build works -(cd agb && cargo test) -(cd agb-image-converter && cargo test) -(cd agb-sound-converter && cargo test) -(cd agb-macros && cargo test) -for EXAMPLE_DIR in examples/*/; do +for CARGO_TOML_FILE in agb-*/Cargo.toml agb/Cargo.toml; do + (cd "$(dirname "$CARGO_TOML_FILE")" && cargo test) +done + +for EXAMPLE_TOML_FILE in examples/*/Cargo.toml book/games/*/Cargo.toml; do + EXAMPLE_DIR=$(dirname "$EXAMPLE_TOML_FILE") (cd "$EXAMPLE_DIR" && cargo check --release) done