MCPcopy Create free account
hub / github.com/Botloader/botloader / main

Function main

components/runtime/build.rs:10–45  ·  view source on GitHub ↗

Example custom build script.

()

Source from the content-addressed store, hash-verified

8
9// Example custom build script.
10fn main() {
11 // Tell Cargo that if the given file changes, to rerun this build script.
12 println!("cargo:rerun-if-changed=src/ts");
13
14 // let files = vec!["op_wrappers", "core_util", "jack"];
15
16 let compiled_files = compile_folder(Path::new("./src/ts/"));
17
18 // create a lazy static file with a mapping of all the modules
19 let header = format!(
20 r#"
21 ::lazy_static::lazy_static! {{
22 pub static ref MODULE_MAP: [(::url::Url, &'static str);{}] = [
23 (::url::Url::parse("file:///script_globals.js").unwrap(), "export {{}}"),
24 "#,
25 compiled_files.len() + 1
26 );
27 let footer = r#"];
28 }"#;
29
30 let mut body = String::new();
31
32 for (i, f) in compiled_files.iter().enumerate() {
33 body.push_str(&format!(
34 r#"(::url::Url::parse("file:///{f}.js").unwrap(), include_js!("{f}.js"))"#
35 ));
36 if i != compiled_files.len() - 1 {
37 body.push(',');
38 }
39 body.push('\n');
40 }
41
42 let full = format!("{header}{body}{footer}");
43 let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
44 fs::write(out_dir.join("module_map.rs"), full).unwrap();
45}
46
47// compiles a folder of typescript files recursively, returning a list of files its compiled
48fn compile_folder(path: &Path) -> Vec<String> {

Callers

nothing calls this directly

Calls 1

compile_folderFunction · 0.85

Tested by

no test coverage detected