From 76d41b235997628cd530755af5152e90859f3f45 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Sat, 29 Oct 2022 07:51:01 +0100 Subject: [PATCH] Separated `decl_static` macro to it's own crate. Rust crates are now built as `lib`s. --- rust/Cargo.lock | 10 ++++++++++ rust/Cargo.toml | 2 +- rust/dw2003_exe_data/Cargo.toml | 4 +++- rust/dw2003_exe_data/src/data.rs | 12 ++---------- rust/dw2003_exe_data/src/lib.rs | 13 ------------- rust/dw2003_exe_data/src/util.rs | 1 - rust/dw2003_exe_digimon_profiles/Cargo.toml | 4 +++- rust/dw2003_exe_digimon_profiles/src/lib.rs | 12 ------------ rust/util/Cargo.toml | 6 ++++++ rust/util/src/lib.rs | 13 +++++++++++++ 10 files changed, 38 insertions(+), 39 deletions(-) delete mode 100644 rust/dw2003_exe_data/src/util.rs create mode 100644 rust/util/Cargo.toml create mode 100644 rust/util/src/lib.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c1100e2cf..9f8592f22 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -5,7 +5,17 @@ version = 3 [[package]] name = "dw2003_exe_data" version = "0.1.0" +dependencies = [ + "util", +] [[package]] name = "dw2003_exe_digimon_profiles" version = "0.1.0" +dependencies = [ + "util", +] + +[[package]] +name = "util" +version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ac88f1b17..7575cf981 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["dw2003_exe_data", "dw2003_exe_digimon_profiles"] +members = ["dw2003_exe_data", "dw2003_exe_digimon_profiles", "util"] diff --git a/rust/dw2003_exe_data/Cargo.toml b/rust/dw2003_exe_data/Cargo.toml index 2ede15bc5..18a54e1a3 100644 --- a/rust/dw2003_exe_data/Cargo.toml +++ b/rust/dw2003_exe_data/Cargo.toml @@ -4,6 +4,8 @@ name = "dw2003_exe_data" version = "0.1.0" [lib] -crate-type = ["staticlib"] +crate-type = ["lib"] [dependencies] + +util = { path = "../util" } diff --git a/rust/dw2003_exe_data/src/data.rs b/rust/dw2003_exe_data/src/data.rs index 195e8d0d8..7b2e429ab 100644 --- a/rust/dw2003_exe_data/src/data.rs +++ b/rust/dw2003_exe_data/src/data.rs @@ -1,14 +1,6 @@ //! Data; -pub macro decl_static($section:literal, $($vis:vis static mut $NAME:ident: $T:ty = $value:expr; )*) { - $( - #[no_mangle] - #[link_section = $section] - $vis static mut $NAME: $T = $value; - )* -} - -decl_static! { "dw2003_exe_data0", +util::decl_static! { "dw2003_exe_data0", pub static mut D0x8003edcc: u32 = 0x0000020a; pub static mut D0x8003edd0: u32 = 0x00080001; pub static mut D0x8003edd4: u32 = 0x00000223; @@ -111,7 +103,7 @@ decl_static! { "dw2003_exe_data0", pub static mut D0x8003ef58: u32 = 0x00000022; } -decl_static! { "dw2003_exe_data1", +util::decl_static! { "dw2003_exe_data1", pub static mut D0x80040244: u32 = 0x0003000f; pub static mut D0x80040248: u32 = 0x00000001; pub static mut D0x8004024c: u32 = 0x000e0000; diff --git a/rust/dw2003_exe_data/src/lib.rs b/rust/dw2003_exe_data/src/lib.rs index 384dcc0be..1ccafb0d9 100644 --- a/rust/dw2003_exe_data/src/lib.rs +++ b/rust/dw2003_exe_data/src/lib.rs @@ -6,16 +6,3 @@ // Modules mod data; -mod util; - -// Dummy panic handler -#[panic_handler] -#[inline(never)] -fn _panic_handler(_info: &core::panic::PanicInfo) -> ! { - // SAFETY: This function will not make it to the final binary - // due to our linker script discarding it and being - // annotated with `inline(never)` - unsafe { - core::hint::unreachable_unchecked(); - } -} diff --git a/rust/dw2003_exe_data/src/util.rs b/rust/dw2003_exe_data/src/util.rs deleted file mode 100644 index 112da6c64..000000000 --- a/rust/dw2003_exe_data/src/util.rs +++ /dev/null @@ -1 +0,0 @@ -//! Utilities diff --git a/rust/dw2003_exe_digimon_profiles/Cargo.toml b/rust/dw2003_exe_digimon_profiles/Cargo.toml index 649856221..c7730e900 100644 --- a/rust/dw2003_exe_digimon_profiles/Cargo.toml +++ b/rust/dw2003_exe_digimon_profiles/Cargo.toml @@ -4,6 +4,8 @@ name = "dw2003_exe_digimon_profiles" version = "0.1.0" [lib] -crate-type = ["staticlib"] +crate-type = ["lib"] [dependencies] + +util = { path = "../util" } diff --git a/rust/dw2003_exe_digimon_profiles/src/lib.rs b/rust/dw2003_exe_digimon_profiles/src/lib.rs index 830f3f8b6..b61e132b8 100644 --- a/rust/dw2003_exe_digimon_profiles/src/lib.rs +++ b/rust/dw2003_exe_digimon_profiles/src/lib.rs @@ -2434,15 +2434,3 @@ pub static mut DIGIMON_PROFILES: [DigimonProfile; 55] = [ unknown2: [0x1, 0x0], }, ]; - -// Dummy panic handler -#[panic_handler] -#[inline(never)] -fn _panic_handler(_info: &core::panic::PanicInfo) -> ! { - // SAFETY: This function will not make it to the final binary - // due to our linker script discarding it and being - // annotated with `inline(never)` - unsafe { - core::hint::unreachable_unchecked(); - } -} diff --git a/rust/util/Cargo.toml b/rust/util/Cargo.toml new file mode 100644 index 000000000..a936e424f --- /dev/null +++ b/rust/util/Cargo.toml @@ -0,0 +1,6 @@ +[package] +edition = "2021" +name = "util" +version = "0.1.0" + +[dependencies] diff --git a/rust/util/src/lib.rs b/rust/util/src/lib.rs new file mode 100644 index 000000000..ed04f629f --- /dev/null +++ b/rust/util/src/lib.rs @@ -0,0 +1,13 @@ +//! Utilities + +// Features +#![feature(decl_macro)] +#![no_std] + +pub macro decl_static($section:literal, $($vis:vis static mut $NAME:ident: $T:ty = $value:expr; )*) { + $( + #[no_mangle] + #[link_section = $section] + $vis static mut $NAME: $T = $value; + )* +}