summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/BUILD.gn270
-rw-r--r--cli/Cargo.toml51
-rw-r--r--cli/build.rs20
-rw-r--r--cli/js_errors.rs20
-rw-r--r--cli/msg.fbs2
-rw-r--r--cli/msg.rs2
-rw-r--r--cli/startup_data.rs20
7 files changed, 366 insertions, 19 deletions
diff --git a/cli/BUILD.gn b/cli/BUILD.gn
new file mode 100644
index 000000000..f6000a08f
--- /dev/null
+++ b/cli/BUILD.gn
@@ -0,0 +1,270 @@
+# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import("//build/toolchain/cc_wrapper.gni")
+import("//build_extra/flatbuffers/flatbuffer.gni")
+import("//build_extra/flatbuffers/rust/rust_flatbuffer.gni")
+import("//build_extra/rust/rust.gni")
+import("//third_party/v8/gni/v8.gni")
+import("//third_party/v8/snapshot_toolchain.gni")
+import("../deno.gni")
+
+main_extern = [
+ "../core:deno_core",
+
+ "$rust_build:ansi_term",
+ "$rust_build:atty",
+ "$rust_build:dirs",
+ "$rust_build:flatbuffers",
+ "$rust_build:futures",
+ "$rust_build:getopts",
+ "$rust_build:http",
+ "$rust_build:hyper",
+ "$rust_build:hyper_rustls",
+ "$rust_build:lazy_static",
+ "$rust_build:libc",
+ "$rust_build:log",
+ "$rust_build:rand",
+ "$rust_build:regex",
+ "$rust_build:remove_dir_all",
+ "$rust_build:ring",
+ "$rust_build:rustyline",
+ "$rust_build:serde_json",
+ "$rust_build:source_map_mappings",
+ "$rust_build:tempfile",
+ "$rust_build:tokio",
+ "$rust_build:tokio_executor",
+ "$rust_build:tokio_fs",
+ "$rust_build:tokio_io",
+ "$rust_build:tokio_process",
+ "$rust_build:tokio_threadpool",
+ "$rust_build:url",
+]
+if (is_win) {
+ main_extern += [ "$rust_build:winapi" ]
+}
+
+ts_sources = [
+ "../js/assets.ts",
+ "../js/blob.ts",
+ "../js/buffer.ts",
+ "../js/build.ts",
+ "../js/chmod.ts",
+ "../js/console_table.ts",
+ "../js/compiler.ts",
+ "../js/console.ts",
+ "../js/copy_file.ts",
+ "../js/core.ts",
+ "../js/custom_event.ts",
+ "../js/deno.ts",
+ "../js/dir.ts",
+ "../js/dispatch.ts",
+ "../js/dom_types.ts",
+ "../js/errors.ts",
+ "../js/event.ts",
+ "../js/event_target.ts",
+ "../js/fetch.ts",
+ "../js/format_error.ts",
+ "../js/dom_file.ts",
+ "../js/file_info.ts",
+ "../js/files.ts",
+ "../js/flatbuffers.ts",
+ "../js/form_data.ts",
+ "../js/globals.ts",
+ "../js/headers.ts",
+ "../js/io.ts",
+ "../js/lib.web_assembly.d.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/permissions.ts",
+ "../js/plugins.d.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/resources.ts",
+ "../js/stat.ts",
+ "../js/symlink.ts",
+ "../js/text_encoding.ts",
+ "../js/timers.ts",
+ "../js/truncate.ts",
+ "../js/types.ts",
+ "../js/url.ts",
+ "../js/url_search_params.ts",
+ "../js/util.ts",
+ "../js/window.ts",
+ "../js/workers.ts",
+ "../js/write_file.ts",
+ "../js/performance.ts",
+ "../js/version.ts",
+ "../tsconfig.json",
+
+ # Listing package.json and yarn.lock as sources ensures the bundle is rebuilt
+ # when npm packages are added/removed or their contents changes.
+ "../package.json",
+ "../third_party/yarn.lock",
+]
+
+# When Cargo is driving the build, GN/Ninja are used to produce these non-Rust
+# targets. Cargo handles all Rust source files and the final linking step.
+group("deno_deps") {
+ deps = [
+ ":msg_rs",
+ ":snapshot_compiler",
+ ":snapshot_deno",
+ ]
+}
+
+# Optimized dependencies for cross compiled builds.
+# This can be removed once we get snapshots into cross compiled builds.
+group("deno_deps_cross") {
+ testonly = true
+ deps = [
+ ":compiler_bundle",
+ ":main_bundle",
+ ":msg_rs",
+ ]
+}
+
+# Reads the cargo info from Cargo.toml
+deno_cargo_info = exec_script(
+ "../build_extra/rust/get_cargo_info.py",
+ [ rebase_path("Cargo.toml", root_build_dir) ], "json")
+
+rust_executable("deno") {
+ source_root = "main.rs"
+ extern = main_extern
+ deps = [
+ ":deno_deps",
+ ]
+
+ # Extract version from Cargo.toml
+ # TODO integrate this into rust.gni by allowing the rust_executable template
+ # to specify a cargo.toml from which it will extract a version.
+ crate_version = deno_cargo_info.version
+ inputs = [
+ "Cargo.toml",
+ ]
+}
+
+rust_test("test_rs") {
+ source_root = "main.rs"
+ extern = main_extern
+ deps = [
+ ":deno_deps",
+ ]
+
+ # Extract version from Cargo.toml
+ crate_version = deno_cargo_info.version
+ inputs = [
+ "Cargo.toml",
+ ]
+}
+
+
+# Generates the core TypeScript type library for deno that will be
+# included in the runtime bundle
+run_node("deno_runtime_declaration") {
+ out_dir = target_gen_dir
+ sources = ts_sources
+ outputs = [
+ "$out_dir/lib/lib.deno_runtime.d.ts",
+ ]
+ deps = [
+ ":msg_ts",
+ ]
+ inputs = ts_sources + [
+ "//tools/ts_library_builder/tsconfig.json",
+ "//tools/ts_library_builder/main.ts",
+ "//tools/ts_library_builder/build_library.ts",
+ "//tools/ts_library_builder/ast_util.ts",
+ ]
+ args = [
+ rebase_path("//node_modules/ts-node/dist/bin.js", root_build_dir),
+ "--project",
+ rebase_path("//tools/ts_library_builder/tsconfig.json"),
+ "--skip-ignore",
+ rebase_path("//tools/ts_library_builder/main.ts", root_build_dir),
+ "--basePath",
+ rebase_path("//", root_build_dir),
+ "--inline",
+ rebase_path("//js/lib.web_assembly.d.ts", root_build_dir),
+ "--buildPath",
+ rebase_path(root_build_dir, root_build_dir),
+ "--outFile",
+ rebase_path(outputs[0], root_build_dir),
+ "--silent",
+ ]
+ if (is_debug) {
+ args += [ "--debug" ]
+ }
+}
+
+bundle("main_bundle") {
+ out_dir = "$target_gen_dir/bundle/"
+ out_name = "main"
+ deps = [
+ ":deno_runtime_declaration",
+ ":msg_ts",
+ ":write_gn_args",
+ ]
+ data = [
+ "$target_gen_dir/gn_args.txt",
+ ]
+}
+
+bundle("compiler_bundle") {
+ out_dir = "$target_gen_dir/bundle/"
+ out_name = "compiler"
+ deps = [
+ ":deno_runtime_declaration",
+ ":msg_ts",
+ ":write_gn_args",
+ ]
+ data = [
+ "$target_gen_dir/gn_args.txt",
+ ]
+}
+
+ts_flatbuffer("msg_ts") {
+ sources = [
+ "msg.fbs",
+ ]
+}
+
+rust_flatbuffer("msg_rs") {
+ sources = [
+ "msg.fbs",
+ ]
+}
+
+# Generates $target_gen_dir/snapshot_deno.bin
+snapshot("snapshot_deno") {
+ source_root = "$target_gen_dir/bundle/main.js"
+ deps = [
+ ":main_bundle",
+ ]
+}
+
+# Generates $target_gen_dir/snapshot_compiler.bin
+snapshot("snapshot_compiler") {
+ source_root = "$target_gen_dir/bundle/compiler.js"
+ deps = [
+ ":compiler_bundle",
+ ]
+}
+
+action("write_gn_args") {
+ script = "//tools/write_gn_args.py"
+ outputs = [
+ "$target_gen_dir/gn_args.txt",
+ ]
+ args = [ rebase_path(outputs[0], root_build_dir) ]
+}
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
new file mode 100644
index 000000000..c58558887
--- /dev/null
+++ b/cli/Cargo.toml
@@ -0,0 +1,51 @@
+# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+# Dummy package info required by `cargo fetch`.
+# Use tools/sync_third_party.py to install deps after editing this file.
+# Deno does not build with cargo. Deno uses a build system called gn.
+# See build_extra/rust/BUILD.gn for the manually built configuration of rust
+# crates.
+
+
+[[bin]]
+name = "deno"
+path = "main.rs"
+
+[package]
+name = "deno"
+version = "0.3.5"
+edition = "2018"
+
+[dependencies]
+deno_core = { path = "../core" }
+
+ansi_term = "0.11.0"
+atty = "0.2.11"
+dirs = "1.0.5"
+flatbuffers = "0.5.0"
+futures = "0.1.25"
+getopts = "0.2.18"
+http = "0.1.16"
+hyper = "0.12.25"
+hyper-rustls = "0.16.1"
+integer-atomics = "1.0.2"
+lazy_static = "1.3.0"
+libc = "0.2.51"
+log = "0.4.6"
+rand = "0.6.5"
+regex = "1.1.2"
+remove_dir_all = "0.5.1"
+ring = "0.14.6"
+rustyline = "3.0.0"
+serde_json = "1.0.39"
+source-map-mappings = "0.5.0"
+tempfile = "3.0.7"
+tokio = "0.1.18"
+tokio-executor = "0.1.7"
+tokio-fs = "0.1.6"
+tokio-io = "0.1.12"
+tokio-process = "0.2.3"
+tokio-threadpool = "0.1.13"
+url = "1.7.2"
+
+[target.'cfg(windows)'.dependencies]
+winapi = "0.3.6"
diff --git a/cli/build.rs b/cli/build.rs
new file mode 100644
index 000000000..4d50d8a5f
--- /dev/null
+++ b/cli/build.rs
@@ -0,0 +1,20 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+// Run "cargo build -vv" if you want to see gn output.
+mod gn {
+ include!("../gn.rs");
+}
+
+fn main() {
+ let build = gn::Build::setup();
+
+ let gn_target = if build.check_only {
+ // When RLS is running "cargo check" to analyze the source code, we're not
+ // trying to build a working executable, rather we're just compiling all
+ // rust code. Therefore, make ninja build only 'msg_generated.rs'.
+ "cli:msg_rs"
+ } else {
+ "cli:deno_deps"
+ };
+
+ build.run(gn_target);
+}
diff --git a/cli/js_errors.rs b/cli/js_errors.rs
index 1cb9cb3a1..b478849d2 100644
--- a/cli/js_errors.rs
+++ b/cli/js_errors.rs
@@ -64,9 +64,9 @@ impl<'a> fmt::Display for JSErrorColor<'a> {
let e = self.0;
if e.script_resource_name.is_some() {
let script_resource_name = e.script_resource_name.as_ref().unwrap();
- // Avoid showing internal code from gen/bundle/main.js
- if script_resource_name != "gen/bundle/main.js"
- && script_resource_name != "gen/bundle/compiler.js"
+ // Avoid showing internal code from gen/cli/bundle/main.js
+ if script_resource_name != "gen/cli/bundle/main.js"
+ && script_resource_name != "gen/cli/bundle/compiler.js"
{
if e.line_number.is_some() && e.start_column.is_some() {
assert!(e.line_number.is_some());
@@ -216,14 +216,16 @@ fn builtin_source_map(_: &str) -> Option<Vec<u8>> {
#[cfg(not(feature = "check-only"))]
fn builtin_source_map(script_name: &str) -> Option<Vec<u8>> {
match script_name {
- "gen/bundle/main.js" => Some(
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/main.js.map"))
- .to_vec(),
+ "gen/cli/bundle/main.js" => Some(
+ include_bytes!(concat!(
+ env!("GN_OUT_DIR"),
+ "/gen/cli/bundle/main.js.map"
+ )).to_vec(),
),
- "gen/bundle/compiler.js" => Some(
+ "gen/cli/bundle/compiler.js" => Some(
include_bytes!(concat!(
env!("GN_OUT_DIR"),
- "/gen/bundle/compiler.js.map"
+ "/gen/cli/bundle/compiler.js.map"
)).to_vec(),
),
_ => None,
@@ -381,7 +383,7 @@ mod tests {
frames: vec![StackFrame {
line: 11,
column: 12,
- script_name: "gen/bundle/main.js".to_string(),
+ script_name: "gen/cli/bundle/main.js".to_string(),
function_name: "setLogDebug".to_string(),
is_eval: false,
is_constructor: false,
diff --git a/cli/msg.fbs b/cli/msg.fbs
index e6b860908..45f940f7d 100644
--- a/cli/msg.fbs
+++ b/cli/msg.fbs
@@ -388,7 +388,7 @@ table OpenRes {
table Read {
rid: uint32;
- // (ptr, len) is passed as second parameter to libdeno.send().
+ // (ptr, len) is passed as second parameter to Deno.core.send().
}
table ReadRes {
diff --git a/cli/msg.rs b/cli/msg.rs
index 080f39de8..d4f62604c 100644
--- a/cli/msg.rs
+++ b/cli/msg.rs
@@ -11,7 +11,7 @@ use std::sync::atomic::Ordering;
// GN_OUT_DIR is set either by build.rs (for the Cargo build), or by
// build_extra/rust/run.py (for the GN+Ninja build).
-include!(concat!(env!("GN_OUT_DIR"), "/gen/msg_generated.rs"));
+include!(concat!(env!("GN_OUT_DIR"), "/gen/cli/msg_generated.rs"));
impl<'a> From<&'a isolate_state::Metrics> for MetricsResArgs {
fn from(m: &'a isolate_state::Metrics) -> Self {
diff --git a/cli/startup_data.rs b/cli/startup_data.rs
index 6e636e579..747e8b11d 100644
--- a/cli/startup_data.rs
+++ b/cli/startup_data.rs
@@ -7,19 +7,19 @@ pub fn deno_isolate_init() -> StartupData {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source_bytes =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/main.js"));
+ include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
#[cfg(feature = "check-only")]
let source_bytes = vec![];
StartupData::Script(Script {
- filename: "gen/bundle/main.js".to_string(),
+ filename: "gen/cli/bundle/main.js".to_string(),
source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
let data =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin"));
+ include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];
@@ -33,20 +33,24 @@ pub fn compiler_isolate_init() -> StartupData {
if cfg!(feature = "no-snapshot-init") {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
- let source_bytes =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/compiler.js"));
+ let source_bytes = include_bytes!(concat!(
+ env!("GN_OUT_DIR"),
+ "/gen/cli/bundle/compiler.js"
+ ));
#[cfg(feature = "check-only")]
let source_bytes = vec![];
StartupData::Script(Script {
- filename: "gen/bundle/compiler.js".to_string(),
+ filename: "gen/cli/bundle/compiler.js".to_string(),
source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
- let data =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_compiler.bin"));
+ let data = include_bytes!(concat!(
+ env!("GN_OUT_DIR"),
+ "/gen/cli/snapshot_compiler.bin"
+ ));
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];