-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
993d58c
commit f1dcfbb
Showing
7 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ v8/ | |
tools/protoc_wrapper/ | ||
third_party/protobuf/ | ||
third_party/zlib/ | ||
third_party/rust_crates/libc/ | ||
.gclient_entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extern crate libc; | ||
use libc::c_char; | ||
use libc::c_int; | ||
use std::ffi::CStr; | ||
use std::ffi::CString; | ||
|
||
#[link(name = "deno", kind = "static")] | ||
extern "C" { | ||
fn deno_v8_version() -> *const c_char; | ||
fn deno_init(); | ||
|
||
// Note: `deno_set_flags` actually takes `char**` as it's second argument, | ||
// not `const char**`, so this is technically incorrect. However it doesn't | ||
// actually modify the contents of the strings, so it's not unsafe. | ||
// TODO: use the correct function signature. | ||
fn deno_set_flags(argc: *mut c_int, argv: *mut *const c_char); | ||
} | ||
|
||
fn set_flags() { | ||
// Create a vector of zero terminated c strings. | ||
let mut argv = std::env::args() | ||
.map(|arg| CString::new(arg).unwrap().as_ptr()) | ||
.collect::<Vec<_>>(); | ||
let mut argc = argv.len() as c_int; | ||
unsafe { | ||
// pass the pointer of the vector's internal buffer to a C function | ||
deno_set_flags(&mut argc, argv.as_mut_ptr()); | ||
}; | ||
} | ||
|
||
fn main() { | ||
println!("Hi"); | ||
set_flags(); | ||
unsafe { deno_init() }; | ||
let v = unsafe { deno_v8_version() }; | ||
let c_str = unsafe { CStr::from_ptr(v) }; | ||
let version = c_str.to_str().unwrap(); | ||
println!("version: {}", version); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ prettier --write \ | |
# Do not format these. | ||
# js/msg.pb.js | ||
# js/msg.pb.d.ts | ||
|
||
rustfmt --write-mode overwrite *.rs |