2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2020-12-13 13:45:53 -05:00
|
|
|
|
2022-07-04 18:12:41 -04:00
|
|
|
use std::env;
|
2023-01-27 10:43:16 -05:00
|
|
|
|
2022-07-04 18:12:41 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
// This is a shim that allows to generate documentation on docs.rs
|
|
|
|
#[cfg(not(feature = "docsrs"))]
|
|
|
|
mod not_docs {
|
2023-01-27 10:43:16 -05:00
|
|
|
use std::path::Path;
|
|
|
|
|
2022-07-04 18:12:41 -04:00
|
|
|
use super::*;
|
2022-09-28 08:11:12 -04:00
|
|
|
use deno_cache::SqliteBackedCache;
|
2022-11-21 08:36:26 -05:00
|
|
|
use deno_core::snapshot_util::*;
|
2022-07-04 18:12:41 -04:00
|
|
|
use deno_core::Extension;
|
|
|
|
|
|
|
|
struct Permissions;
|
|
|
|
|
|
|
|
impl deno_fetch::FetchPermissions for Permissions {
|
|
|
|
fn check_net_url(
|
|
|
|
&mut self,
|
|
|
|
_url: &deno_core::url::Url,
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_read(
|
|
|
|
&mut self,
|
|
|
|
_p: &Path,
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl deno_websocket::WebSocketPermissions for Permissions {
|
|
|
|
fn check_net_url(
|
|
|
|
&mut self,
|
|
|
|
_url: &deno_core::url::Url,
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl deno_web::TimersPermission for Permissions {
|
|
|
|
fn allow_hrtime(&mut self) -> bool {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_unstable(
|
|
|
|
&self,
|
|
|
|
_state: &deno_core::OpState,
|
|
|
|
_api_name: &'static str,
|
|
|
|
) {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl deno_ffi::FfiPermissions for Permissions {
|
|
|
|
fn check(
|
|
|
|
&mut self,
|
|
|
|
_path: Option<&Path>,
|
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 10:06:44 -04:00
|
|
|
impl deno_napi::NapiPermissions for Permissions {
|
|
|
|
fn check(
|
|
|
|
&mut self,
|
|
|
|
_path: Option<&Path>,
|
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 08:05:02 -04:00
|
|
|
impl deno_flash::FlashPermissions for Permissions {
|
|
|
|
fn check_net<T: AsRef<str>>(
|
|
|
|
&mut self,
|
|
|
|
_host: &(T, Option<u16>),
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-08-18 08:05:02 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 12:07:49 -04:00
|
|
|
impl deno_node::NodePermissions for Permissions {
|
|
|
|
fn check_read(
|
|
|
|
&mut self,
|
|
|
|
_p: &Path,
|
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-04 18:12:41 -04:00
|
|
|
impl deno_net::NetPermissions for Permissions {
|
|
|
|
fn check_net<T: AsRef<str>>(
|
|
|
|
&mut self,
|
|
|
|
_host: &(T, Option<u16>),
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_read(
|
|
|
|
&mut self,
|
|
|
|
_p: &Path,
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_write(
|
|
|
|
&mut self,
|
|
|
|
_p: &Path,
|
2022-09-27 16:36:33 -04:00
|
|
|
_api_name: &str,
|
2022-07-04 18:12:41 -04:00
|
|
|
) -> Result<(), deno_core::error::AnyError> {
|
|
|
|
unreachable!("snapshotting!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 08:36:26 -05:00
|
|
|
fn create_runtime_snapshot(snapshot_path: PathBuf, files: Vec<PathBuf>) {
|
2022-11-26 18:58:23 -05:00
|
|
|
let extensions_with_js: Vec<Extension> = vec![
|
2022-07-04 18:12:41 -04:00
|
|
|
deno_webidl::init(),
|
|
|
|
deno_console::init(),
|
|
|
|
deno_url::init(),
|
|
|
|
deno_tls::init(),
|
|
|
|
deno_web::init::<Permissions>(
|
|
|
|
deno_web::BlobStore::default(),
|
|
|
|
Default::default(),
|
|
|
|
),
|
|
|
|
deno_fetch::init::<Permissions>(Default::default()),
|
2022-09-28 08:11:12 -04:00
|
|
|
deno_cache::init::<SqliteBackedCache>(None),
|
2022-07-04 18:12:41 -04:00
|
|
|
deno_websocket::init::<Permissions>("".to_owned(), None, None),
|
|
|
|
deno_webstorage::init(None),
|
|
|
|
deno_crypto::init(None),
|
|
|
|
deno_webgpu::init(false),
|
|
|
|
deno_broadcast_channel::init(
|
|
|
|
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
|
|
|
false, // No --unstable.
|
|
|
|
),
|
2022-11-10 11:57:10 -05:00
|
|
|
deno_node::init::<Permissions>(None),
|
2022-07-04 18:12:41 -04:00
|
|
|
deno_ffi::init::<Permissions>(false),
|
|
|
|
deno_net::init::<Permissions>(
|
|
|
|
None, false, // No --unstable.
|
|
|
|
None,
|
|
|
|
),
|
2022-10-05 10:06:44 -04:00
|
|
|
deno_napi::init::<Permissions>(false),
|
2022-07-04 18:12:41 -04:00
|
|
|
deno_http::init(),
|
2022-08-18 08:05:02 -04:00
|
|
|
deno_flash::init::<Permissions>(false), // No --unstable
|
2022-07-04 18:12:41 -04:00
|
|
|
];
|
|
|
|
|
2022-11-21 08:36:26 -05:00
|
|
|
create_snapshot(CreateSnapshotOptions {
|
|
|
|
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
|
|
|
|
snapshot_path,
|
|
|
|
startup_snapshot: None,
|
2022-11-26 18:58:23 -05:00
|
|
|
extensions: vec![],
|
|
|
|
extensions_with_js,
|
2022-11-21 08:36:26 -05:00
|
|
|
additional_files: files,
|
|
|
|
compression_cb: Some(Box::new(|vec, snapshot_slice| {
|
|
|
|
lzzzz::lz4_hc::compress_to_vec(
|
|
|
|
snapshot_slice,
|
|
|
|
vec,
|
|
|
|
lzzzz::lz4_hc::CLEVEL_MAX,
|
|
|
|
)
|
|
|
|
.expect("snapshot compression failed");
|
|
|
|
})),
|
2022-07-04 18:12:41 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build_snapshot(runtime_snapshot_path: PathBuf) {
|
2022-11-28 06:47:25 -05:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
let mut js_files = get_js_files(env!("CARGO_MANIFEST_DIR"), "js");
|
|
|
|
#[cfg(not(feature = "snapshot_from_snapshot"))]
|
|
|
|
{
|
|
|
|
let manifest = env!("CARGO_MANIFEST_DIR");
|
|
|
|
let path = PathBuf::from(manifest);
|
|
|
|
js_files.push(path.join("js").join("99_main.js"));
|
|
|
|
}
|
2022-11-21 08:36:26 -05:00
|
|
|
create_runtime_snapshot(runtime_snapshot_path, js_files);
|
2022-07-04 18:12:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 12:01:30 -04:00
|
|
|
fn main() {
|
2022-07-04 18:12:41 -04:00
|
|
|
// To debug snapshot issues uncomment:
|
|
|
|
// op_fetch_asset::trace_serializer();
|
|
|
|
|
|
|
|
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
|
|
|
|
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
|
|
|
|
let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
|
|
|
|
// Main snapshot
|
2022-11-21 08:36:26 -05:00
|
|
|
let runtime_snapshot_path = o.join("RUNTIME_SNAPSHOT.bin");
|
2022-07-04 18:12:41 -04:00
|
|
|
|
|
|
|
// If we're building on docs.rs we just create
|
|
|
|
// and empty snapshot file and return, because `rusty_v8`
|
|
|
|
// doesn't actually compile on docs.rs
|
|
|
|
if env::var_os("DOCS_RS").is_some() {
|
|
|
|
let snapshot_slice = &[];
|
|
|
|
std::fs::write(&runtime_snapshot_path, snapshot_slice).unwrap();
|
2021-08-11 12:01:30 -04:00
|
|
|
}
|
2020-12-13 13:45:53 -05:00
|
|
|
|
2022-07-04 18:12:41 -04:00
|
|
|
#[cfg(not(feature = "docsrs"))]
|
|
|
|
not_docs::build_snapshot(runtime_snapshot_path)
|
2020-12-13 13:45:53 -05:00
|
|
|
}
|