Port strinova proto debug feature
This commit is contained in:
parent
81073a2a28
commit
316e3ee06f
4 changed files with 84 additions and 46 deletions
19
Cargo.toml
19
Cargo.toml
|
@ -7,4 +7,23 @@ edition = "2024"
|
|||
version = "0.1.0"
|
||||
|
||||
[workspace.dependencies]
|
||||
byteorder = "1.5.0"
|
||||
crc32fast = "1.4.2"
|
||||
prettyplease = "0.2.32"
|
||||
proc-macro2 = "1.0.95"
|
||||
prost = "0.13.5"
|
||||
prost-build = "0.13.5"
|
||||
quote = "1.0.40" #
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
syn = "2.0.101" #
|
||||
thiserror = "2.0.12"
|
||||
|
||||
# Internal
|
||||
wicked-waifus-protocol-derive = { path = "wicked-waifus-protocol-derive" }
|
||||
|
||||
[profile.release]
|
||||
strip = true # Automatically strip symbols from the binary.
|
||||
lto = true # Link-time optimization.
|
||||
opt-level = 3 # Optimization level 3.
|
||||
codegen-units = 1 # Maximum size reduction optimizations.
|
||||
|
|
|
@ -4,9 +4,9 @@ edition.workspace = true
|
|||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
syn = "2.0.100"
|
||||
quote = "1.0.40"
|
||||
proc-macro2 = "1.0.94"
|
||||
syn.workspace = true
|
||||
quote.workspace = true
|
||||
proc-macro2.workspace = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
|
|
@ -3,17 +3,20 @@ name = "wicked-waifus-protocol"
|
|||
edition.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[features]
|
||||
debug = ["dep:serde", "dep:serde_json"]
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.5.0"
|
||||
crc32fast = "1.4.2"
|
||||
thiserror = "2.0.12"
|
||||
prost = "0.13.5"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
byteorder.workspace = true
|
||||
crc32fast.workspace = true
|
||||
prost.workspace = true
|
||||
serde = { workspace = true, optional = true }
|
||||
serde_json = { workspace = true, optional = true }
|
||||
thiserror.workspace = true
|
||||
wicked-waifus-protocol-derive.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
prost-build = "0.13.5"
|
||||
quote = "1.0.40"
|
||||
syn = "2.0.100"
|
||||
prettyplease = "0.2.31"
|
||||
prettyplease.workspace = true
|
||||
prost-build.workspace = true
|
||||
quote.workspace = true
|
||||
syn.workspace = true
|
|
@ -24,15 +24,28 @@ pub fn main() {
|
|||
if Path::new(&proto_file).exists() {
|
||||
println!("cargo:rerun-if-changed={proto_file}");
|
||||
|
||||
prost_build::Config::new()
|
||||
.out_dir(CODEGEN_OUT_DIR)
|
||||
.default_package_filename("wicked-waifus")
|
||||
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
||||
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
|
||||
.compile_protos(&[proto_file], &["wicked-waifus"])
|
||||
.unwrap();
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
prost_build::Config::new()
|
||||
.out_dir(CODEGEN_OUT_DIR)
|
||||
.default_package_filename("wicked-waifus")
|
||||
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
||||
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
|
||||
.compile_protos(&[proto_file], &["wicked-waifus"])
|
||||
.unwrap();
|
||||
|
||||
impl_dumper(Path::new("generated/wicked-waifus.rs")).unwrap();
|
||||
}
|
||||
#[cfg(not(feature = "debug"))]
|
||||
{
|
||||
prost_build::Config::new()
|
||||
.out_dir(CODEGEN_OUT_DIR)
|
||||
.default_package_filename("wicked-waifus")
|
||||
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
||||
.compile_protos(&[proto_file], &["wicked-waifus"])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
impl_dumper(Path::new("generated/wicked-waifus.rs")).unwrap();
|
||||
impl_message_id(Path::new("generated/wicked-waifus.rs")).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -134,35 +147,38 @@ pub fn impl_dumper(codegen_path: &Path) -> io::Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
let generated_code = quote! {
|
||||
pub mod proto_dumper {
|
||||
use prost::Message;
|
||||
use crate::*;
|
||||
use crate::ai::*;
|
||||
use crate::combat_message::*;
|
||||
use crate::debug::*;
|
||||
use crate::summon::*;
|
||||
if !match_arms.is_empty() {
|
||||
let generated_code = quote! {
|
||||
pub mod proto_dumper {
|
||||
use prost::Message;
|
||||
use crate::*;
|
||||
use crate::ai::*;
|
||||
use crate::combat_message::*;
|
||||
use crate::debug::*;
|
||||
use crate::summon::*;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("serde_json::Error: {0}")]
|
||||
Json(#[from] serde_json::Error),
|
||||
#[error("serde_json::Error: {0}")]
|
||||
Decode(#[from] prost::DecodeError),
|
||||
}
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("serde_json::Error: {0}")]
|
||||
Json(#[from] serde_json::Error),
|
||||
#[error("serde_json::Error: {0}")]
|
||||
Decode(#[from] prost::DecodeError),
|
||||
}
|
||||
|
||||
pub fn get_debug_info(id: u16, data: &[u8]) -> Result<(&str, String), Error> {
|
||||
match id {
|
||||
#match_arms
|
||||
_ => Ok(("UnknownType", "".to_string())),
|
||||
pub fn get_debug_info(id: u16, data: &[u8]) -> Result<(&str, String), Error> {
|
||||
match id {
|
||||
#match_arms
|
||||
_ => Ok(("UnknownType", "".to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let syntax_tree = syn::parse2(generated_code).unwrap();
|
||||
let formatted = prettyplease::unparse(&syntax_tree);
|
||||
let mut file = fs::OpenOptions::new().append(true).open(codegen_path)?;
|
||||
file.write(formatted.as_bytes())?;
|
||||
}
|
||||
|
||||
let syntax_tree = syn::parse2(generated_code).unwrap();
|
||||
let formatted = prettyplease::unparse(&syntax_tree);
|
||||
let mut file = fs::OpenOptions::new().append(true).open(codegen_path)?;
|
||||
file.write(formatted.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue