Skip to content

Commit 0c634c2

Browse files
committed
Switch to prost, general tp update
1 parent e794899 commit 0c634c2

13 files changed

Lines changed: 654 additions & 576 deletions

Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@ exclude = ["images/"]
1919

2020
[dependencies]
2121
prost = "0.14"
22-
byteorder = "1.5.0"
23-
num_enum = "0.7.3"
24-
log = "0.4.26"
25-
derive_more = { version = "2.0", features = ["display"] }
22+
byteorder = "1"
23+
num_enum = "0.7"
24+
log = "0.4"
25+
derive_more = { version = "2", features = ["display"] }
2626
dfhack-proto = { version = "0.11.0", path = "dfhack-proto" }
2727
thiserror = "2"
2828

2929

3030
[dev-dependencies]
3131
bmp = "0.5.0"
32-
ctor = "0.4.1"
32+
ctor = "0.6"
3333
lazy_static = "1.5.0"
34-
rand = "0.9.0"
35-
env_logger = "0.11.7"
34+
rand = "0.10"
35+
env_logger = "0.11"
3636

3737

3838
[features]
39-
test-with-df = ["reflection"]
40-
reflection = ["dfhack-proto/reflection"]
39+
test-with-df = []

dfhack-proto/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ license = "MIT OR Apache-2.0"
1010
categories = ["api-bindings", "game-development", "games"]
1111

1212
[features]
13-
reflection = []
1413

1514
[dependencies]
1615
prost = "0.14"
16+
serde = { version = "1", features = ["derive"] }
1717

1818
[build-dependencies]
1919
prost = "0.14"

dfhack-proto/build.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,35 @@ fn main() {
5050
println!("cargo:rerun-if-changed=build.rs");
5151
println!("cargo:rerun-if-env-changed=DFHACK_REGEN");
5252

53-
let protoc = get_protoc();
54-
55-
let proto_include_dir = dfhack_proto_srcs::include_dir();
56-
let protos = dfhack_proto_srcs::protos();
57-
58-
assert!(!protos.is_empty(), "No protobuf file for code generation.");
59-
60-
// Generate in the sources if DFHACK_REGEN is set
61-
// in OUT_DIR otherwise.
62-
// TODO It should always be OUT_DIR, then expose macros.
63-
let out_path = match std::env::var("DFHACK_REGEN") {
64-
Ok(_) => {
65-
let dst = PathBuf::from("src/generated");
66-
if dst.exists() {
67-
std::fs::remove_dir_all(&dst).unwrap();
53+
if std::env::var("DFHACK_REGEN").is_ok() {
54+
let protoc = get_protoc();
55+
56+
let proto_include_dir = dfhack_proto_srcs::include_dir();
57+
let protos = dfhack_proto_srcs::protos();
58+
59+
assert!(!protos.is_empty(), "No protobuf file for code generation.");
60+
61+
// Generate in the sources if DFHACK_REGEN is set
62+
// in OUT_DIR otherwise.
63+
// TODO It should always be OUT_DIR, then expose macros.
64+
let out_path = match std::env::var("DFHACK_REGEN") {
65+
Ok(_) => {
66+
let dst = PathBuf::from("src/generated");
67+
if dst.exists() {
68+
std::fs::remove_dir_all(&dst).unwrap();
69+
}
70+
std::fs::create_dir_all(&dst).unwrap();
71+
dst
6872
}
69-
std::fs::create_dir_all(&dst).unwrap();
70-
dst
71-
}
72-
Err(_) => PathBuf::from(std::env::var("OUT_DIR").unwrap()),
73-
};
73+
Err(_) => PathBuf::from(std::env::var("OUT_DIR").unwrap()),
74+
};
7475

75-
// Generate the protobuf message files
76-
generate_messages_rs(&protoc, &protos, proto_include_dir, &out_path);
76+
// Generate the protobuf message files
77+
generate_messages_rs(&protoc, &protos, proto_include_dir, &out_path);
7778

78-
// Generate the plugin stubs
79-
generate_stubs_rs(&protos, &out_path)
79+
// Generate the plugin stubs
80+
generate_stubs_rs(&protos, &out_path)
81+
}
8082
}
8183

8284
fn get_protoc() -> PathBuf {
@@ -101,13 +103,14 @@ fn messages_protoc_codegen(
101103
) {
102104
prost_build::Config::new()
103105
.enable_type_names()
106+
.type_attribute(".", "#[derive(serde::Serialize)]")
104107
.protoc_executable(protoc)
105108
.out_dir(out_path)
106109
.compile_protos(protos, &[include_dir])
107110
.unwrap();
108111
}
109112

110-
fn generate_stubs_rs(protos: &Vec<PathBuf>, out_path: &Path) {
113+
fn generate_stubs_rs(protos: &[PathBuf], out_path: &Path) {
111114
let plugins = read_protos_rpcs(protos);
112115
let mut out_path = out_path.to_path_buf();
113116
out_path.push("stubs");
@@ -173,7 +176,6 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
173176
#plugins_impl
174177
}
175178

176-
#[cfg(feature = "reflection")]
177179
impl<TChannel: crate::Channel> crate::reflection::StubReflection for Stubs<TChannel> {
178180
fn list_methods() -> Vec<crate::reflection::RemoteProcedureDescriptor> {
179181
let mut methods = Vec::new();
@@ -323,7 +325,6 @@ fn generate_stub_rs(plugin: &Plugin, file: &mut TokenStream) {
323325
#plugin_impl
324326
}
325327

326-
#[cfg(feature = "reflection")]
327328
impl<TChannel: crate::Channel> crate::reflection::StubReflection for #struct_ident<'_, TChannel> {
328329
fn list_methods() -> Vec<crate::reflection::RemoteProcedureDescriptor> {
329330
vec![
@@ -334,7 +335,7 @@ fn generate_stub_rs(plugin: &Plugin, file: &mut TokenStream) {
334335
});
335336
}
336337

337-
fn read_protos_rpcs(protos: &Vec<PathBuf>) -> Vec<Plugin> {
338+
fn read_protos_rpcs(protos: &[PathBuf]) -> Vec<Plugin> {
338339
let mut plugins = HashMap::<String, Plugin>::new();
339340

340341
for proto in protos {

dfhack-proto/src/generated/messages/adventure_control.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// This file is @generated by prost-build.
2+
#[derive(serde::Serialize)]
23
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
34
pub struct MoveCommandParams {
45
#[prost(message, optional, tag = "1")]
@@ -14,6 +15,7 @@ impl ::prost::Name for MoveCommandParams {
1415
"/AdventureControl.MoveCommandParams".into()
1516
}
1617
}
18+
#[derive(serde::Serialize)]
1719
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
1820
pub struct MovementOption {
1921
#[prost(message, optional, tag = "1")]
@@ -35,6 +37,7 @@ impl ::prost::Name for MovementOption {
3537
"/AdventureControl.MovementOption".into()
3638
}
3739
}
40+
#[derive(serde::Serialize)]
3841
#[derive(Clone, PartialEq, ::prost::Message)]
3942
pub struct MenuContents {
4043
#[prost(enumeration = "AdvmodeMenu", optional, tag = "1")]
@@ -52,6 +55,7 @@ impl ::prost::Name for MenuContents {
5255
"/AdventureControl.MenuContents".into()
5356
}
5457
}
58+
#[derive(serde::Serialize)]
5559
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
5660
pub struct MiscMoveParams {
5761
#[prost(enumeration = "MiscMoveType", optional, tag = "1")]
@@ -67,6 +71,7 @@ impl ::prost::Name for MiscMoveParams {
6771
"/AdventureControl.MiscMoveParams".into()
6872
}
6973
}
74+
#[derive(serde::Serialize)]
7075
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
7176
#[repr(i32)]
7277
pub enum AdvmodeMenu {
@@ -228,6 +233,7 @@ impl AdvmodeMenu {
228233
}
229234
}
230235
}
236+
#[derive(serde::Serialize)]
231237
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
232238
#[repr(i32)]
233239
pub enum CarefulMovementType {
@@ -287,6 +293,7 @@ impl CarefulMovementType {
287293
}
288294
}
289295
}
296+
#[derive(serde::Serialize)]
290297
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
291298
#[repr(i32)]
292299
pub enum MiscMoveType {

0 commit comments

Comments
 (0)