qjs-ng-sys 0.0.4

quickjs bindings for rquickjs
use std::{
    env, fs,
    io::Write,
    path::Path,
    process::{Command, Stdio},
};

fn main() {
    let out_dir = env::var("OUT_DIR").expect("No OUT_DIR env var is set by cargo");
    let out_dir = Path::new(&out_dir);

    let src_dir = out_dir.join("quickjs");

    if !src_dir.exists() {
        let mut cmd = Command::new("git");
        cmd.args([
            "clone",
            "https://github.com/quickjs-ng/quickjs.git",
            &src_dir.to_string_lossy(),
        ]);
        cmd.output().unwrap();
    }

    let header_files = [
        "libbf.h",
        "libregexp-opcode.h",
        "libregexp.h",
        "libunicode-table.h",
        "libunicode.h",
        "list.h",
        "quickjs-atom.h",
        "quickjs-libc.h",
        "quickjs-opcode.h",
        "quickjs.h",
        "cutils.h",
    ];

    let source_files = [
        "libregexp.c",
        "libunicode.c",
        "cutils.c",
        "quickjs-libc.c",
        "quickjs.c",
        "libbf.c",
    ];

    let mut defines = vec![
        ("_GNU_SOURCE", None),
        ("CONFIG_VERSION", Some("\"2020-01-19\"")),
        ("CONFIG_BIGNUM", None),
    ];

    for file in source_files.iter().chain(header_files.iter()) {
        fs::copy(src_dir.join(file), out_dir.join(file)).expect("Unable to copy source");
    }

    // generating bindings
    // bindgen(out_dir, out_dir.join("quickjs.h"), &defines);

    let mut builder = cc::Build::new();
    builder
        .extra_warnings(false)
        .flag("-Wno-array-bounds")
        .flag("-Wno-format-truncation");

    for (name, value) in &defines {
        builder.define(name, *value);
    }

    for src in &source_files {
        builder.file(out_dir.join(src));
    }

    builder.compile("libquickjs.a");
}