Skip to content

Commit cc36666

Browse files
committed
try clean include things
1 parent 0c634c2 commit cc36666

3 files changed

Lines changed: 45 additions & 55 deletions

File tree

dfhack-proto/build.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,11 @@ fn main() {
5959
assert!(!protos.is_empty(), "No protobuf file for code generation.");
6060

6161
// 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
72-
}
73-
Err(_) => PathBuf::from(std::env::var("OUT_DIR").unwrap()),
74-
};
75-
62+
let out_path = PathBuf::from(format!("{}/src/generated", env!("CARGO_MANIFEST_DIR")));
63+
if out_path.exists() {
64+
std::fs::remove_dir_all(&out_path).unwrap();
65+
}
66+
std::fs::create_dir_all(&out_path).unwrap();
7667
// Generate the protobuf message files
7768
generate_messages_rs(&protoc, &protos, proto_include_dir, &out_path);
7869

@@ -101,13 +92,18 @@ fn messages_protoc_codegen(
10192
include_dir: &str,
10293
out_path: &Path,
10394
) {
95+
let mut mod_path = out_path.to_path_buf();
96+
mod_path.push("includes.rs");
97+
println!("{}", mod_path.display());
10498
prost_build::Config::new()
10599
.enable_type_names()
106100
.type_attribute(".", "#[derive(serde::Serialize)]")
107101
.protoc_executable(protoc)
108102
.out_dir(out_path)
103+
.include_file(&mod_path)
109104
.compile_protos(protos, &[include_dir])
110105
.unwrap();
106+
//panic!("{}", mod_path.display());
111107
}
112108

113109
fn generate_stubs_rs(protos: &[PathBuf], out_path: &Path) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This file is @generated by prost-build.
2+
pub mod adventure_control {
3+
include!("adventure_control.rs");
4+
}
5+
pub mod dfproto {
6+
include!("dfproto.rs");
7+
}
8+
pub mod dfstockpiles {
9+
include!("dfstockpiles.rs");
10+
}
11+
pub mod dwarf_control {
12+
include!("dwarf_control.rs");
13+
}
14+
pub mod itemdef_instrument {
15+
include!("itemdef_instrument.rs");
16+
}
17+
pub mod proto {
18+
pub mod enums {
19+
pub mod ui_sidebar_mode {
20+
include!("proto.enums.ui_sidebar_mode.rs");
21+
}
22+
}
23+
}
24+
pub mod remote_fortress_reader {
25+
include!("remote_fortress_reader.rs");
26+
}

dfhack-proto/src/lib.rs

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,19 @@ use std::{fmt::Display, ops::Deref};
77
#[allow(missing_docs)]
88
pub(crate) mod generated {
99
pub(crate) mod stubs;
10-
11-
pub(crate) mod messages {
12-
pub(crate) mod adventure_control;
13-
pub(crate) mod dfproto;
14-
pub(crate) mod dfstockpiles;
15-
pub(crate) mod dwarf_control;
16-
pub(crate) mod itemdef_instrument;
17-
pub(crate) mod remote_fortress_reader;
18-
pub(crate) mod proto {
19-
pub(crate) mod enums {
20-
#[path = "../../proto.enums.ui_sidebar_mode.rs"]
21-
pub(crate) mod ui_sidebar_mode;
22-
}
23-
}
24-
}
2510
}
2611

2712
/// Raw protobuf messages
13+
#[allow(missing_docs)]
2814
pub mod messages {
29-
pub use crate::generated::messages::adventure_control::*;
30-
pub use crate::generated::messages::dfproto::*;
31-
pub use crate::generated::messages::dfstockpiles::*;
32-
pub use crate::generated::messages::dwarf_control::*;
33-
pub use crate::generated::messages::itemdef_instrument::*;
34-
pub use crate::generated::messages::proto::enums::ui_sidebar_mode::*;
35-
pub use crate::generated::messages::remote_fortress_reader::*;
36-
// pub use self::AdventureControl::*;
37-
// mod Basic;
38-
// pub use self::Basic::*;
39-
// mod BasicApi;
40-
// pub use self::BasicApi::*;
41-
// mod CoreProtocol;
42-
// pub use self::CoreProtocol::*;
43-
// mod DwarfControl;
44-
// pub use self::DwarfControl::*;
45-
// mod ItemdefInstrument;
46-
// pub use self::ItemdefInstrument::*;
47-
// mod RemoteFortressReader;
48-
// pub use self::RemoteFortressReader::*;
49-
// mod example;
50-
// pub use self::example::*;
51-
// mod stockpiles;
52-
// pub use self::stockpiles::*;
53-
// mod ui_sidebar_mode;
54-
// pub use self::ui_sidebar_mode::*;
15+
include!("generated/messages/includes.rs");
16+
pub use adventure_control::*;
17+
pub use dfproto::*;
18+
pub use dfstockpiles::*;
19+
pub use dwarf_control::*;
20+
pub use itemdef_instrument::*;
21+
pub use proto::enums::ui_sidebar_mode::*;
22+
pub use remote_fortress_reader::*;
5523
}
5624

5725
/// Stubs exposing the feature of the DFHack remote API.

0 commit comments

Comments
 (0)