You can install with npm
:
$ npm install rust-jit
npm install -g neon-cli
You will also need to install:
- Rust
- Xcode
- You also need to install the
Command Line Tools
via Xcode. You can find this under the menuXcode -> Preferences -> Downloads
- This step will install
gcc
and the related toolchain containingmake
- You also need to install the
Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global --production windows-build-tools
from an elevated PowerShell or CMD.exe (run as Administrator).
Install tools and configuration manually:
-
Visual C++ Build Environment:
-
Option 1: Install Visual C++ Build Tools using the Default Install option.
-
Option 2: Install Visual Studio 2015 and select Common Tools for Visual C++ during setup. This also works with the free Community and Express for Desktop editions.
-
Option 3: if you already have Visual Studio 2015 installed and did not install the Common Tools for Visual C++ during setup, you can
File -> New -> Project
, pick any of the options underTemplates -> Other Languages -> Visual C++
thenOk
and Visual Studio will offer to install the Common Tools for Visual C++ with a "Install Missing Features" / "You need the Universal Windows App Development Tools to develop Windows app projects." dialog.
💡 [Windows Vista / 7 only] requires .NET Framework 4.5.1
-
-
Install Rust
-
Launch cmd,
npm config set msvs_version 2015
If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.
const RustJit = require("rust-jit");
const path = require("path");
let rustJit = new RustJit();
let code = `
let scope = call.scope;
let option_num = call.arguments.get(scope,0);
let mut num:i32 = 0;
if let Some(x1) = option_num {
if let neon::js::Variant::Integer(x2) = x1.variant() {
num = x2.value() as i32;
}
}
let mut fibnum:i32 = 1;
if num>2 {
let mut a:i32 = 1;
let mut b:i32 = 1;
let mut c:i32 = 0;
for _i in 2..num {
c=a+b;
a=b;
b=c;
}
fibnum = c;
}
Ok(neon::js::JsInteger::new(scope, fibnum))
`;
let rustFibByCode = rustJit.compileSync(code,'JsInteger');
console.log("rustJit.compileSync fib(5)=>5:"+rustFibByCode(5));
let rustFibByFile = rustJit.compileByFileSync(path.join(__dirname,"test.rs"),'JsInteger');
console.log("rustJit.compileByFileSync fib(6)=>8:"+rustFibByFile(6));