antlr-runtime-sys 0.2.0

antlr-runtime library.
Documentation
use std::path::PathBuf;

fn main() {
    let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
    let include_dir = out_dir.join("include/antlr4-runtime");
    std::fs::create_dir_all(&include_dir).unwrap();
    let mut source_files = Vec::new();
    for dir in &[
        "antlr4/runtime/Cpp/runtime/src",
        "antlr4/runtime/Cpp/runtime/src/atn",
        "antlr4/runtime/Cpp/runtime/src/dfa",
        "antlr4/runtime/Cpp/runtime/src/internal",
        "antlr4/runtime/Cpp/runtime/src/misc",
        "antlr4/runtime/Cpp/runtime/src/support",
        "antlr4/runtime/Cpp/runtime/src/tree",
        "antlr4/runtime/Cpp/runtime/src/tree/pattern",
        "antlr4/runtime/Cpp/runtime/src/tree/xpath",
    ] {
        if let Some(p) = dir.strip_prefix("antlr4/runtime/Cpp/runtime/src/") {
            std::fs::create_dir_all(include_dir.join(p)).unwrap();
        }
        for r in std::fs::read_dir(dir).unwrap() {
            let path = r.unwrap().path();
            if let Some(ext) = path.extension() {
                if ext == "h" {
                    let to = include_dir
                        .join(path.strip_prefix("antlr4/runtime/Cpp/runtime/src").unwrap());
                    std::fs::copy(&path, &to).unwrap();
                } else if ext == "cpp" {
                    source_files.push(path);
                }
            }
        }
    }

    let mut cfg = cc::Build::new();

    cfg.cpp(true)
        .std("c++17")
        .include("antlr4/runtime/Cpp/runtime/src")
        .files(&source_files)
        .compile("antlr-runtime");

    println!("cargo:include={}/include/antlr4-runtime", out_dir.display());
    println!("cargo:rustc-link-search=native={}", out_dir.display());
    println!("cargo:rustc-link-lib=static=antlr-runtime");
}