diff options
Diffstat (limited to 'cli_snapshots')
-rw-r--r-- | cli_snapshots/BUILD.gn | 121 | ||||
-rw-r--r-- | cli_snapshots/Cargo.toml | 18 | ||||
-rw-r--r-- | cli_snapshots/README.md | 9 | ||||
-rw-r--r-- | cli_snapshots/build.rs | 24 | ||||
-rw-r--r-- | cli_snapshots/lib.rs | 43 | ||||
-rw-r--r-- | cli_snapshots/run.py | 15 |
6 files changed, 230 insertions, 0 deletions
diff --git a/cli_snapshots/BUILD.gn b/cli_snapshots/BUILD.gn new file mode 100644 index 000000000..c22305579 --- /dev/null +++ b/cli_snapshots/BUILD.gn @@ -0,0 +1,121 @@ +import("//build_extra/rust/rust.gni") + +rust_rlib("deno_cli_snapshots") { + source_root = "lib.rs" + generated_source_dir = rebase_path(root_out_dir) + deps = [ + ":deno_cli_snapshots_build_run", + ] +} + +ts_sources = [ + "../js/base64.ts", + "../js/blob.ts", + "../js/body.ts", + "../js/buffer.ts", + "../js/build.ts", + "../js/chmod.ts", + "../js/chown.ts", + "../js/colors.ts", + "../js/compiler.ts", + "../js/console.ts", + "../js/console_table.ts", + "../js/copy_file.ts", + "../js/core.ts", + "../js/custom_event.ts", + "../js/deno.ts", + "../js/diagnostics.ts", + "../js/dir.ts", + "../js/dispatch.ts", + "../js/dispatch_json.ts", + "../js/dispatch_minimal.ts", + "../js/dom_file.ts", + "../js/dom_types.ts", + "../js/dom_util.ts", + "../js/error_stack.ts", + "../js/errors.ts", + "../js/event.ts", + "../js/event_target.ts", + "../js/fetch.ts", + "../js/file_info.ts", + "../js/files.ts", + "../js/form_data.ts", + "../js/format_error.ts", + "../js/get_random_values.ts", + "../js/globals.ts", + "../js/headers.ts", + "../js/io.ts", + "../js/lib.deno_runtime.d.ts", + "../js/lib.web_assembly.d.ts", + "../js/link.ts", + "../js/location.ts", + "../js/main.ts", + "../js/make_temp_dir.ts", + "../js/metrics.ts", + "../js/mkdir.ts", + "../js/mock_builtin.js", + "../js/net.ts", + "../js/os.ts", + "../js/performance.ts", + "../js/permissions.ts", + "../js/process.ts", + "../js/read_dir.ts", + "../js/read_file.ts", + "../js/read_link.ts", + "../js/remove.ts", + "../js/rename.ts", + "../js/repl.ts", + "../js/request.ts", + "../js/resources.ts", + "../js/stat.ts", + "../js/symlink.ts", + "../js/text_encoding.ts", + "../js/timers.ts", + "../js/truncate.ts", + "../js/type_directives.ts", + "../js/types.ts", + "../js/url.ts", + "../js/url_search_params.ts", + "../js/util.ts", + "../js/utime.ts", + "../js/version.ts", + "../js/window.ts", + "../js/workers.ts", + "../js/write_file.ts", + "../js/xeval.ts", +] + +action("deno_cli_snapshots_build_run") { + script = "run.py" + inputs = ts_sources + outputs = [ + "$root_out_dir/CLI_SNAPSHOT.bin", + "$root_out_dir/CLI_SNAPSHOT.js", + "$root_out_dir/CLI_SNAPSHOT.js.map", + "$root_out_dir/CLI_SNAPSHOT.d.ts", + "$root_out_dir/COMPILER_SNAPSHOT.bin", + "$root_out_dir/COMPILER_SNAPSHOT.js", + "$root_out_dir/COMPILER_SNAPSHOT.js.map", + "$root_out_dir/COMPILER_SNAPSHOT.d.ts", + ] + args = [ rebase_path("$root_out_dir/deno_cli_snapshots_build", ".") ] + deps = [ + ":deno_cli_snapshots_build", + ] +} + +rust_executable("deno_cli_snapshots_build") { + source_root = "build.rs" + extern = [ + { + label = "../deno_typescript:deno_typescript" + crate_name = "deno_typescript" + crate_type = "rlib" + }, + { + label = "../core:deno" + crate_name = "deno" + crate_type = "rlib" + }, + ] +} diff --git a/cli_snapshots/Cargo.toml b/cli_snapshots/Cargo.toml new file mode 100644 index 000000000..e6cbf6a25 --- /dev/null +++ b/cli_snapshots/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "deno_cli_snapshots" +version = "0.0.3" +license = "MIT" +authors = ["Ryan Dahl <ry@tinyclouds.org>"] +edition = "2018" +description = "Provides snapshots for the deno CLI" +repository = "https://github.com/ry/deno_typescript" + +[lib] +path = "lib.rs" + +[dev-dependencies] +deno = { path = "../core" } + +[build-dependencies] +deno_typescript = { path = "../deno_typescript", version = "0.0.3" } + diff --git a/cli_snapshots/README.md b/cli_snapshots/README.md new file mode 100644 index 000000000..427429a2b --- /dev/null +++ b/cli_snapshots/README.md @@ -0,0 +1,9 @@ +This is a small crate which exports just a few static blobs. It contains a +build.rs file which compiles Deno's internal JavaScript and TypeScript code +first into a single AMD bundle, and then into a binary V8 Snapshot. + +The main Deno executable crate ("cli") depends on this crate and has access to +all the runtime code. + +The //js/ directory should be moved as a sub-directory of this crate, to denote +the dependency structure. However, that is left to future work. diff --git a/cli_snapshots/build.rs b/cli_snapshots/build.rs new file mode 100644 index 000000000..cffa3d6b3 --- /dev/null +++ b/cli_snapshots/build.rs @@ -0,0 +1,24 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +use std::env; +use std::path::PathBuf; + +fn main() { + // To debug snapshot issues uncomment: + // deno_typescript::trace_serializer(); + + let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let o = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let js_dir = c.join("../js"); + + let root_names = vec![js_dir.join("main.ts")]; + let bundle = o.join("CLI_SNAPSHOT.js"); + let state = deno_typescript::compile_bundle(&bundle, root_names).unwrap(); + assert!(bundle.exists()); + deno_typescript::mksnapshot_bundle(&bundle, state).unwrap(); + + let root_names = vec![js_dir.join("compiler.ts")]; + let bundle = o.join("COMPILER_SNAPSHOT.js"); + let state = deno_typescript::compile_bundle(&bundle, root_names).unwrap(); + assert!(bundle.exists()); + deno_typescript::mksnapshot_bundle_ts(&bundle, state).unwrap(); +} diff --git a/cli_snapshots/lib.rs b/cli_snapshots/lib.rs new file mode 100644 index 000000000..1147e7903 --- /dev/null +++ b/cli_snapshots/lib.rs @@ -0,0 +1,43 @@ +pub static CLI_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin")); +pub static CLI_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.js.map")); +pub static CLI_SNAPSHOT_DTS: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.d.ts")); + +pub static COMPILER_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); +pub static COMPILER_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.js.map")); +pub static COMPILER_SNAPSHOT_DTS: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.d.ts")); + +#[test] +fn cli_snapshot() { + let mut isolate = + deno::Isolate::new(deno::StartupData::Snapshot(CLI_SNAPSHOT), false); + deno::js_check(isolate.execute( + "<anon>", + r#" + if (!window) { + throw Error("bad"); + } + console.log("we have console.log!!!"); + "#, + )); +} + +#[test] +fn compiler_snapshot() { + let mut isolate = + deno::Isolate::new(deno::StartupData::Snapshot(COMPILER_SNAPSHOT), false); + deno::js_check(isolate.execute( + "<anon>", + r#" + if (!compilerMain) { + throw Error("bad"); + } + console.log(`ts version: ${ts.version}`); + "#, + )); +} diff --git a/cli_snapshots/run.py b/cli_snapshots/run.py new file mode 100644 index 000000000..4dba78768 --- /dev/null +++ b/cli_snapshots/run.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +# This script is to execute build.rs during the GN build. See BUILD.gn. +import subprocess +import sys +import os + +d = os.path.dirname(os.path.realpath(__file__)) +exe = sys.argv[1] +env = os.environ.copy() +env["CARGO_MANIFEST_DIR"] = d +env["OUT_DIR"] = os.path.dirname(exe) +# To match the behavior of cargo, we need to cd into this directory. +os.chdir(d) +sys.exit(subprocess.call([exe], env=env)) |