main()1 fn main() {
2     use std::process::Command;
3 
4     let project_root = std::env::current_dir()
5         .unwrap()
6         .parent()  // flatbuffers/tests/rust_usage test
7         .unwrap()
8         .parent()  // flatbuffers/tests
9         .unwrap()
10         .parent()  // flatbuffers/
11         .unwrap()
12         .to_path_buf();
13 
14     let sample_schema = {
15         let mut s = project_root.to_path_buf();
16         s.push("samples");
17         s.push("monster.fbs");
18         s
19     };
20 
21     let flatc = {
22         let mut f = project_root.to_path_buf();
23         f.push("flatc");
24         f
25     };
26 
27     let out_dir = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf();
28 
29     Command::new(&flatc)
30         .arg("--rust")
31         .arg(&sample_schema)
32         .arg("--filename-suffix")
33         .arg("_gen")
34         .output()
35         .expect("Failed to generate file");
36 
37     let genfile = "monster_gen.rs";
38     std::fs::rename(&genfile, out_dir.join("monster_generated.rs")).unwrap();
39 }
40