deno.land / x / deno@v1.28.2 / runtime / build.rs

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use std::env;use std::path::Path;use std::path::PathBuf;
// This is a shim that allows to generate documentation on docs.rs#[cfg(not(feature = "docsrs"))]mod not_docs { use super::*; use deno_cache::SqliteBackedCache; use deno_core::snapshot_util::*; use deno_core::Extension;
struct Permissions;
impl deno_fetch::FetchPermissions for Permissions { fn check_net_url( &mut self, _url: &deno_core::url::Url, _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") }
fn check_read( &mut self, _p: &Path, _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") } }
impl deno_websocket::WebSocketPermissions for Permissions { fn check_net_url( &mut self, _url: &deno_core::url::Url, _api_name: &str, ) -> 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!") } }
impl deno_napi::NapiPermissions for Permissions { fn check( &mut self, _path: Option<&Path>, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") } }
impl deno_flash::FlashPermissions for Permissions { fn check_net<T: AsRef<str>>( &mut self, _host: &(T, Option<u16>), _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") } }
impl deno_node::NodePermissions for Permissions { fn check_read( &mut self, _p: &Path, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") } }
impl deno_net::NetPermissions for Permissions { fn check_net<T: AsRef<str>>( &mut self, _host: &(T, Option<u16>), _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") }
fn check_read( &mut self, _p: &Path, _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") }
fn check_write( &mut self, _p: &Path, _api_name: &str, ) -> Result<(), deno_core::error::AnyError> { unreachable!("snapshotting!") } }
fn create_runtime_snapshot(snapshot_path: PathBuf, files: Vec<PathBuf>) { let extensions: Vec<Extension> = vec![ 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()), deno_cache::init::<SqliteBackedCache>(None), 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. ), deno_node::init::<Permissions>(None), deno_ffi::init::<Permissions>(false), deno_net::init::<Permissions>( None, false, // No --unstable. None, ), deno_napi::init::<Permissions>(false), deno_http::init(), deno_flash::init::<Permissions>(false), // No --unstable ];
create_snapshot(CreateSnapshotOptions { cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), snapshot_path, startup_snapshot: None, extensions, 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"); })), }); }
pub fn build_snapshot(runtime_snapshot_path: PathBuf) { let js_files = get_js_files(env!("CARGO_MANIFEST_DIR"), "js"); create_runtime_snapshot(runtime_snapshot_path, js_files); }}
fn main() { // 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 let runtime_snapshot_path = o.join("RUNTIME_SNAPSHOT.bin");
// 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(); return; }
#[cfg(not(feature = "docsrs"))] not_docs::build_snapshot(runtime_snapshot_path)}
deno

Version Info

Tagged at
a year ago