Skip to content

Commit

Permalink
Feature: Native plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Jul 16, 2019
1 parent 9c45499 commit fb33832
Show file tree
Hide file tree
Showing 31 changed files with 804 additions and 37 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env:
- CARGO_HOME=$TRAVIS_BUILD_DIR/third_party/rust_crates/
- RUSTUP_HOME=$HOME/.rustup/
- RUST_BACKTRACE=full
- CARGO_TARGET_DIR=$HOME/target
- PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH
- PYTHONPATH=third_party/python_packages
- RUSTC_WRAPPER=sccache
Expand Down Expand Up @@ -72,8 +71,8 @@ before_script:
script:
- ./tools/lint.py
- ./tools/test_format.py
- ./tools/build.py -C target/release
- DENO_BUILD_MODE=release ./tools/test.py
- ./tools/build.py --release -C target/release
- DENO_BUILD_MODE=release ./tools/test.py -v

jobs:
fast_finish: true
Expand Down
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ members = [
"cli",
"core",
"tools/hyper_hello",
"tests/plugin",
]
58 changes: 58 additions & 0 deletions build_extra/rust/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,51 @@ rust_rlib("dirs_sys") {
}
}

rust_proc_macro("dlopen_derive") {
edition = "2015"
source_root = "$cargo_home/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/dlopen_derive-0.1.4/src/lib.rs"
args = [
"--cap-lints",
"allow",
]
extern_rlib = [
"syn",
"quote",
"libc",
]
}

rust_rlib("dlopen") {
edition = "2015"
source_root = "$cargo_home/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/dlopen-0.1.7/src/lib.rs"
args = [
"--cap-lints",
"allow",
]
extern = [
{
label = ":dlopen_derive"
crate_name = "dlopen_derive"
crate_type = "proc_macro"
},
]
extern_rlib = [ "lazy_static" ]
if (is_posix) {
extern_rlib += [ "libc" ]
}
if (is_win) {
extern += [
{
label = ":winapi-0.2.8"
crate_name = "winapi"
crate_type = "rlib"
crate_version = "0.2.8"
},
]
extern_rlib += [ "kernel32" ]
}
}

rust_rlib("either") {
edition = "2015"
source_root = "$cargo_home/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/either-1.5.2/src/lib.rs"
Expand Down Expand Up @@ -579,6 +624,10 @@ rust_rlib("log") {
edition = "2015"
source_root = "$cargo_home/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/log-0.4.6/src/lib.rs"
extern_rlib = [ "cfg_if" ]
features = [
"default",
"std",
]
args = [
"--cap-lints",
"allow",
Expand Down Expand Up @@ -1267,11 +1316,20 @@ rust_rlib("serde") {
features = [
"default",
"std",
"derive",
"serde_derive",
]
args = [
"--cap-lints",
"allow",
]
extern = [
{
label = ":serde_derive"
crate_name = "serde_derive"
crate_type = "proc_macro"
},
]

# Added by custom-build script.
cfg = [
Expand Down
17 changes: 17 additions & 0 deletions build_extra/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ template("_rust_crate") {
} else if (crate_type == "rlib") {
out_file = "lib$crate_name$crate_suffix.rlib"
emit_type = "link"
} else if (crate_type == "dylib" || crate_type == "cdylib") {
out_file = "$shared_lib_prefix$crate_name$crate_suffix$shared_lib_suffix"
emit_type = "link"
}
out_path = "$out_dir/$out_file"

Expand Down Expand Up @@ -308,6 +311,20 @@ template("rust_rlib") {
}
}

template("rust_dylib") {
_rust_crate(target_name) {
forward_variables_from(invoker, "*")
crate_type = "dylib"
}
}

template("rust_cdylib") {
_rust_crate(target_name) {
forward_variables_from(invoker, "*")
crate_type = "cdylib"
}
}

template("rust_proc_macro") {
_rust_crate(target_name) {
forward_variables_from(invoker, "*")
Expand Down
2 changes: 2 additions & 0 deletions cli/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ main_extern_rlib = [
"atty",
"clap",
"dirs",
"dlopen",
"flatbuffers",
"futures",
"fwdansi",
Expand Down Expand Up @@ -105,6 +106,7 @@ ts_sources = [
"../js/metrics.ts",
"../js/mkdir.ts",
"../js/mock_builtin.js",
"../js/native_plugins.ts",
"../js/net.ts",
"../js/os.ts",
"../js/permissions.ts",
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ansi_term = "0.11.0"
atty = "0.2.11"
clap = "2.33.0"
dirs = "2.0.1"
dlopen = "0.1.7"
flatbuffers = "0.6.0"
futures = "0.1.27"
http = "0.1.17"
Expand Down
13 changes: 13 additions & 0 deletions cli/deno_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub use crate::msg::ErrorKind;
use deno::AnyError;
use deno::ErrBox;
use deno::ModuleResolutionError;
use dlopen::Error as DlopenError;
use http::uri;
use hyper;
use rustyline::error::ReadlineError;
Expand Down Expand Up @@ -199,6 +200,17 @@ impl GetErrorKind for ReadlineError {
}
}

impl GetErrorKind for DlopenError {
fn kind(&self) -> ErrorKind {
match self {
DlopenError::NullCharacter(_) => ErrorKind::PluginNullCharacter,
DlopenError::OpeningLibraryError(io_err)
| DlopenError::SymbolGettingError(io_err) => GetErrorKind::kind(io_err),
DlopenError::NullSymbol => ErrorKind::PluginNullSymbol,
}
}
}

#[cfg(unix)]
mod unix {
use super::{ErrorKind, GetErrorKind};
Expand Down Expand Up @@ -245,6 +257,7 @@ impl GetErrorKind for dyn AnyError {
.or_else(|| self.downcast_ref::<uri::InvalidUri>().map(Get::kind))
.or_else(|| self.downcast_ref::<url::ParseError>().map(Get::kind))
.or_else(|| self.downcast_ref::<ReadlineError>().map(Get::kind))
.or_else(|| self.downcast_ref::<DlopenError>().map(Get::kind))
.or_else(|| unix_error_kind(self))
.unwrap_or_else(|| {
panic!("Can't get ErrorKind for {:?}", self);
Expand Down
4 changes: 2 additions & 2 deletions cli/dispatch_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ pub fn dispatch_minimal(
Ok(buf)
}));
if is_sync {
Op::Sync(fut.wait().unwrap())
Op::Sync(fut.wait().unwrap()) as CoreOp
} else {
Op::Async(fut)
Op::Async(fut) as CoreOp
}
}

Expand Down
13 changes: 11 additions & 2 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct DenoFlags {
pub allow_env: bool,
pub allow_run: bool,
pub allow_hrtime: bool,
pub allow_plugins: bool,
pub no_prompts: bool,
pub no_fetch: bool,
pub seed: Option<u64>,
Expand Down Expand Up @@ -87,6 +88,10 @@ fn add_run_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
Arg::with_name("allow-hrtime")
.long("allow-hrtime")
.help("Allow high resolution time measurement"),
).arg(
Arg::with_name("allow-plugins")
.long("allow-plugins")
.help("Allow loading native plugins via dlopen"),
).arg(
Arg::with_name("allow-all")
.short("A")
Expand Down Expand Up @@ -540,14 +545,17 @@ fn parse_run_args(mut flags: DenoFlags, matches: &ArgMatches) -> DenoFlags {
if matches.is_present("allow-hrtime") {
flags.allow_hrtime = true;
}
if matches.is_present("allow-plugins") {
flags.allow_plugins = true;
}
if matches.is_present("allow-all") {
flags.allow_read = true;
flags.allow_write = true;
flags.allow_env = true;
flags.allow_net = true;
flags.allow_run = true;
flags.allow_read = true;
flags.allow_write = true;
flags.allow_hrtime = true;
flags.allow_plugins = true;
}
if matches.is_present("no-prompt") {
flags.no_prompts = true;
Expand Down Expand Up @@ -960,6 +968,7 @@ mod tests {
allow_read: true,
allow_write: true,
allow_hrtime: true,
allow_plugins: true,
..DenoFlags::default()
}
);
Expand Down
36 changes: 36 additions & 0 deletions cli/msg.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ union Any {
Cwd,
CwdRes,
Dial,
PluginOpen,
PluginOpenRes,
PluginSym,
PluginSymRes,
PluginCall,
PluginCallRes,
Environ,
EnvironRes,
Exit,
Expand Down Expand Up @@ -148,6 +154,10 @@ enum ErrorKind: byte {
// other kinds
Diagnostic,
JSError,

// dlopen errors
PluginNullSymbol,
PluginNullCharacter,
}

table Cwd {}
Expand Down Expand Up @@ -598,4 +608,30 @@ table Seek {

table GetRandomValues {}

table PluginOpen {
filename: string;
}

table PluginOpenRes {
rid: uint32;
}

table PluginSym {
rid: uint32;
name: string;
}

table PluginSymRes {
rid: uint32;
}

table PluginCall {
rid: uint32;
data: [ubyte];
}

table PluginCallRes {
data: [ubyte];
}

root_type Base;
Loading

0 comments on commit fb33832

Please sign in to comment.