aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/build.rs
blob: 0a72a2ae06415edc97c567e51222008f5d3ae32b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use std::env;
use std::path::{Path, PathBuf};

fn main() {
    // copy include! files from script_bindings's OUT_DIR, to script's OUT_DIR
    // this is done to bypass limitation of Rust Analyzer: https://github.com/rust-lang/rust-analyzer/issues/17040
    let script_bindings_out_dir =
        PathBuf::from(env::var_os("DEP_SCRIPT_BINDINGS_CRATE_OUT_DIR").unwrap());
    let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
    // copy concrete files
    [
        "InterfaceTypes.rs",
        "DomTypeHolder.rs",
        "InterfaceObjectMap.rs",
        "ConcreteInheritTypes.rs",
        "UnionTypes.rs",
        "InterfaceObjectMapPhf.rs",
    ]
    .iter()
    .map(Path::new)
    .for_each(|file| {
        println!(
            "cargo::rerun-if-changed={}",
            script_bindings_out_dir.join(file).display()
        );
        std::fs::copy(
            script_bindings_out_dir.join(file),
            out_dir.join(file.file_name().unwrap()),
        )
        .unwrap();
    });
    // copy ConcreteBindings folder
    let _ = std::fs::create_dir(out_dir.join("ConcreteBindings"));
    let script_concrete_bindings_out_dir = script_bindings_out_dir.join("ConcreteBindings");
    println!(
        "cargo::rerun-if-changed={}",
        script_concrete_bindings_out_dir.display()
    );
    std::fs::read_dir(script_concrete_bindings_out_dir)
        .unwrap()
        .filter_map(|res| res.map(|e| e.path()).ok())
        .filter(|path| path.is_file())
        .for_each(|file| {
            std::fs::copy(
                &file,
                out_dir
                    .join("ConcreteBindings")
                    .join(file.file_name().unwrap()),
            )
            .unwrap();
        });
}