James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 1 | fn main() { |
| 2 | use std::process::Command; |
| 3 | let project_root = std::env::current_dir() |
| 4 | .unwrap() |
| 5 | .parent() // flatbuffers/tests/rust_usage test |
| 6 | .unwrap() |
| 7 | .parent() // flatbuffers/tests |
| 8 | .unwrap() |
| 9 | .parent() // flatbuffers/ |
| 10 | .unwrap() |
| 11 | .to_path_buf(); |
| 12 | let sample_schema = { |
| 13 | let mut s = project_root.to_path_buf(); |
| 14 | s.push("samples"); |
| 15 | s.push("monster.fbs"); |
| 16 | s |
| 17 | }; |
| 18 | |
| 19 | let flatc = { |
| 20 | let mut f = project_root.to_path_buf(); |
| 21 | f.push("flatc"); |
| 22 | f |
| 23 | }; |
| 24 | |
| 25 | let out_dir = { |
| 26 | let mut d = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf(); |
| 27 | d.push("flatbuffers"); |
| 28 | d |
| 29 | }; |
| 30 | |
| 31 | Command::new(&flatc) |
| 32 | .arg("-o") |
| 33 | .arg(&out_dir) |
| 34 | .arg("--rust") |
| 35 | .arg(&sample_schema) |
| 36 | .output() |
| 37 | .expect("Failed to generate file"); |
| 38 | |
| 39 | assert!(out_dir.exists()); |
| 40 | |
| 41 | let generated = std::path::Path::new("src/generated"); |
| 42 | #[cfg(target_os = "windows")] |
| 43 | { |
| 44 | if generated.exists() { |
| 45 | std::fs::remove_dir(generated).unwrap(); |
| 46 | } |
| 47 | std::os::windows::fs::symlink_dir(out_dir, generated).unwrap(); |
| 48 | } |
| 49 | #[cfg(not(target_os = "windows"))] |
| 50 | { |
| 51 | if generated.exists() { |
| 52 | std::fs::remove_file(generated).unwrap(); |
| 53 | } |
| 54 | std::os::unix::fs::symlink(out_dir, generated).unwrap(); |
| 55 | } |
| 56 | } |