...

Text file src/github.com/google/flatbuffers/tests/rust_usage_test/outdir/build.rs

Documentation: github.com/google/flatbuffers/tests/rust_usage_test/outdir

     1fn 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("--rust-module-root-file")
    36        .arg(&sample_schema)
    37        .output()
    38        .expect("Failed to generate file");
    39
    40    assert!(out_dir.exists());
    41
    42    let generated = std::path::Path::new("src/generated");
    43    #[cfg(target_os = "windows")]
    44    {
    45        if generated.exists() {
    46            std::fs::remove_dir(generated).unwrap();
    47        }
    48        std::os::windows::fs::symlink_dir(out_dir, generated).unwrap();
    49    }
    50    #[cfg(not(target_os = "windows"))]
    51    {
    52        if generated.exists() {
    53            std::fs::remove_file(generated).unwrap();
    54        }
    55        std::os::unix::fs::symlink(out_dir, generated).unwrap();
    56    }
    57}

View as plain text