File
Blob: src/rust/gen-compile-cache/main.rs
| 1 | use std::fs; |
| 2 | use std::path::Path; |
| 3 | use std::path::PathBuf; |
| 4 | |
| 5 | use clap::Parser; |
| 6 | |
| 7 | /// Generate V8 compile caches |
| 8 | #[derive(Parser, Debug)] |
| 9 | struct Args { |
| 10 | /// Contains `<input_path> <output_path>` lines |
| 11 | file_list: PathBuf, |
| 12 | } |
| 13 | |
| 14 | fn main() { |
| 15 | let args = Args::parse(); |
| 16 | |
| 17 | let file_list = fs::read_to_string(&args.file_list).expect("can't read file list"); |
| 18 | for line in file_list.split('\n').filter(|l| !l.is_empty()) { |
| 19 | let [input_path, output_path] = line |
| 20 | .split(' ') |
| 21 | .collect::<Vec<_>>() |
| 22 | .try_into() |
| 23 | .expect("incorrect input line"); |
| 24 | |
| 25 | let input = fs::read_to_string(input_path).expect("error reading input file"); |
| 26 | let output = ffi::compile(input_path, &input); |
| 27 | |
| 28 | fs::write(Path::new(output_path), output).expect("error writing output file"); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | #[cxx::bridge(namespace = "workerd::rust::gen_compile_cache")] |
| 33 | mod ffi { |
| 34 | unsafe extern "C++" { |
| 35 | include!("workerd/rust/gen-compile-cache/cxx-bridge.h"); |
| 36 | |
| 37 | fn compile(path: &str, source_code: &str) -> Vec<u8>; |
| 38 | } |
| 39 | } |