diff options
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/cli/build.rs b/cli/build.rs index a94f3925b..98fc8dbc0 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,38 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use deno_core::include_crate_modules; -use deno_core::CoreOp; use deno_core::Isolate; -use deno_core::Op; use deno_core::StartupData; -use deno_core::ZeroCopyBuf; use std::collections::HashMap; use std::env; use std::path::PathBuf; -fn op_fetch_asset( - custom_assets: HashMap<String, PathBuf>, -) -> impl Fn(&[u8], Option<ZeroCopyBuf>) -> CoreOp { - move |control: &[u8], zero_copy_buf: Option<ZeroCopyBuf>| -> CoreOp { - assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in this op. - let name = std::str::from_utf8(control).unwrap(); - - let asset_code = if let Some(source_code) = deno_typescript::get_asset(name) - { - source_code.to_string() - } else if let Some(asset_path) = custom_assets.clone().get(name) { - let source_code_vec = - std::fs::read(&asset_path).expect("Asset not found"); - let source_code = std::str::from_utf8(&source_code_vec).unwrap(); - source_code.to_string() - } else { - panic!("op_fetch_asset bad asset {}", name) - }; - - let vec = asset_code.into_bytes(); - Op::Sync(vec.into_boxed_slice()) - } -} - fn main() { // Don't build V8 if "cargo doc" is being run. This is to support docs.rs. if env::var_os("RUSTDOCFLAGS").is_some() { @@ -89,6 +62,17 @@ fn main() { let root_names = vec![c.join("js/compiler.ts")]; let bundle_path = o.join("COMPILER_SNAPSHOT.js"); let snapshot_path = o.join("COMPILER_SNAPSHOT.bin"); + + let main_module_name = deno_typescript::compile_bundle( + &bundle_path, + root_names, + Some(extern_crate_modules), + ) + .expect("Bundle compilation failed"); + assert!(bundle_path.exists()); + + let runtime_isolate = &mut Isolate::new(StartupData::None, true); + let mut custom_libs: HashMap<String, PathBuf> = HashMap::new(); custom_libs.insert( "lib.deno.window.d.ts".to_string(), @@ -106,17 +90,10 @@ fn main() { "lib.deno.ns.d.ts".to_string(), c.join("js/lib.deno.ns.d.ts"), ); - - let main_module_name = deno_typescript::compile_bundle( - &bundle_path, - root_names, - Some(extern_crate_modules), - ) - .expect("Bundle compilation failed"); - assert!(bundle_path.exists()); - - let runtime_isolate = &mut Isolate::new(StartupData::None, true); - runtime_isolate.register_op("fetch_asset", op_fetch_asset(custom_libs)); + runtime_isolate.register_op( + "op_fetch_asset", + deno_typescript::op_fetch_asset(custom_libs), + ); deno_typescript::mksnapshot_bundle_ts( runtime_isolate, |