From 0d71f56705f95f7562ac1bed8f70a55dcf701f86 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 24 Oct 2016 14:45:05 -0700 Subject: [PATCH 01/19] Use statically-dispatched destructor call to work around MSVC bug --- crates/neon-sys/src/neon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/neon-sys/src/neon.cc b/crates/neon-sys/src/neon.cc index 025bc8783..563e156e6 100644 --- a/crates/neon-sys/src/neon.cc +++ b/crates/neon-sys/src/neon.cc @@ -221,7 +221,7 @@ extern "C" void NeonSys_Scope_Enter(v8::HandleScope *scope, v8::Isolate *isolate } extern "C" void NeonSys_Scope_Exit(v8::HandleScope *scope) { - scope->~HandleScope(); + scope->HandleScope::~HandleScope(); } extern "C" size_t NeonSys_Scope_Sizeof() { From 93219efadea42e9a0260e30f61f9363bfff4c32e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 24 Oct 2016 14:52:23 -0700 Subject: [PATCH 02/19] Fix object file path on windows --- crates/neon-sys/build.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index 660598146..c407d283a 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -14,10 +14,16 @@ fn mode() -> &'static str { if debug() { "Debug" } else { "Release" } } +#[cfg(not(windows))] fn object_path(libname: &str) -> String { format!("build/{}/obj.target/{}/src/{}.o", mode(), libname, libname) } +#[cfg(windows)] +fn object_path(libname: &str) -> String { + format!("build\\{}\\obj\\{}\\{}.obj", mode(), libname, libname) +} + fn build_object_file() { // Ensure that all package.json dependencies and dev dependencies are installed. Command::new("npm").arg("install").status().ok() From 4e2725a24a2489ed26ace99f8e4bb31e9369b592 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 24 Oct 2016 15:02:21 -0700 Subject: [PATCH 03/19] Fix npm path on windows --- crates/neon-sys/build.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index c407d283a..07f995f98 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -14,7 +14,7 @@ fn mode() -> &'static str { if debug() { "Debug" } else { "Release" } } -#[cfg(not(windows))] +#[cfg(unix)] fn object_path(libname: &str) -> String { format!("build/{}/obj.target/{}/src/{}.o", mode(), libname, libname) } @@ -24,16 +24,22 @@ fn object_path(libname: &str) -> String { format!("build\\{}\\obj\\{}\\{}.obj", mode(), libname, libname) } +#[cfg(unix)] +const NPM_COMMAND : &'static str = "npm"; + +#[cfg(windows)] +const NPM_COMMAND : &'static str = "npm.cmd"; + fn build_object_file() { // Ensure that all package.json dependencies and dev dependencies are installed. - Command::new("npm").arg("install").status().ok() + Command::new(NPM_COMMAND).arg("install").status().ok() .expect(r#"failed to run "npm install" for neon-sys"#); // Run the package.json `configure` script, which invokes `node-gyp configure` from the local node_modules. - Command::new("npm").arg("run").arg(if debug() { "configure-debug" } else { "configure-release" }).status().ok().unwrap(); + Command::new(NPM_COMMAND).arg("run").arg(if debug() { "configure-debug" } else { "configure-release" }).status().ok().unwrap(); // Run the package.json `build` script, which invokes `node-gyp build` from the local node_modules. - Command::new("npm").arg("run").arg(if debug() { "build-debug" } else { "build-release" }).status().ok().unwrap(); + Command::new(NPM_COMMAND).arg("run").arg(if debug() { "build-debug" } else { "build-release" }).status().ok().unwrap(); } fn link_library() { From fc09605c444c8841d9e2dd36eb2c967d64c49e41 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 24 Oct 2016 15:41:17 -0700 Subject: [PATCH 04/19] Add appveyor.yml --- appveyor.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..2e91ad40a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,23 @@ +environment: + nodejs_version: "6" + +install: + # Install node + - ps: Install-Product node $env:nodejs_version + + # Install Rust + - curl -sSf -o rustup-init.exe https://win.rustup.rs + - rustup-init.exe -y + - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin + - rustc -V + - cargo -V + +build: false + +test_script: + - cd tests + - npm test + +cache: + - target + - C:\Users\appveyor\.cargo\registry From dcd8c86372b7f871d82c98ae41d72662cc1619e4 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 25 Oct 2016 10:49:52 +0200 Subject: [PATCH 05/19] Run `npm` with `--silent` to prevent it from stalling on Windows For some reason, node-gyp never exits if we run `npm` commands without the `--silent` option. Passing `--no-progress --no-color` and/or capturing the output of stderr and stdout doesn't help. This will still make the npm commands fail in case something goes wrong, and won't suppress the node-gyp output when running cargo in verbose mode. --- crates/neon-sys/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index 07f995f98..2e310b270 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -32,14 +32,14 @@ const NPM_COMMAND : &'static str = "npm.cmd"; fn build_object_file() { // Ensure that all package.json dependencies and dev dependencies are installed. - Command::new(NPM_COMMAND).arg("install").status().ok() + Command::new(NPM_COMMAND).args(&["install", "--silent"]).status().ok() .expect(r#"failed to run "npm install" for neon-sys"#); // Run the package.json `configure` script, which invokes `node-gyp configure` from the local node_modules. - Command::new(NPM_COMMAND).arg("run").arg(if debug() { "configure-debug" } else { "configure-release" }).status().ok().unwrap(); + Command::new(NPM_COMMAND).args(&["run", "--silent"]).arg(if debug() { "configure-debug" } else { "configure-release" }).status().ok().unwrap(); // Run the package.json `build` script, which invokes `node-gyp build` from the local node_modules. - Command::new(NPM_COMMAND).arg("run").arg(if debug() { "build-debug" } else { "build-release" }).status().ok().unwrap(); + Command::new(NPM_COMMAND).args(&["run", "--silent"]).arg(if debug() { "build-debug" } else { "build-release" }).status().ok().unwrap(); } fn link_library() { From 1edee6cec7bfc925020c4f21a88e6c575392ed5b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 25 Oct 2016 19:58:28 +0200 Subject: [PATCH 06/19] Disable `WholeProgramOptimization` along with `LinkTimeCodeGeneration` ...because they were preventing `neon_sys` functions from being included into the `neon_sys` object file on Windows. Signed-off-by: Max Brunsfeld --- crates/neon-sys/binding.gyp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/neon-sys/binding.gyp b/crates/neon-sys/binding.gyp index 07a65591e..ace89f069 100644 --- a/crates/neon-sys/binding.gyp +++ b/crates/neon-sys/binding.gyp @@ -1,7 +1,19 @@ { - "targets": [{ - "target_name": "neon", - "sources": [ "src/neon.cc" ], - "include_dirs": [ " Date: Wed, 26 Oct 2016 16:37:11 +0200 Subject: [PATCH 07/19] Resolve and pass node.lib to the linker on Windows Other platforms support dynamic lookup of symbols. On Windows, however, we always need to provide a .lib file with the node headers when linking the final dynamic library that will be used by Node applications. Signed-off-by: Nathan Sobo --- Cargo.toml | 5 +++ build.rs | 7 +++ crates/neon-sys/Cargo.toml | 1 + crates/neon-sys/build.rs | 87 +++++++++++++++++++----------------- crates/neon-sys/package.json | 8 +--- tests/native/Cargo.toml | 1 + tests/native/build.rs | 11 +++++ 7 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 build.rs create mode 100644 tests/native/build.rs diff --git a/Cargo.toml b/Cargo.toml index 4f4a73781..59fbe64ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,11 @@ homepage = "http://neon.rustbridge.io" repository = "https://github.com/rustbridge/neon" license = "MIT/Apache-2.0" exclude = ["neon.jpg"] +build = "build.rs" + +# This name is arbitrary, but allows us to re-export the location of node.lib +# to dependent packages so they can link on Windows. +links = "neon-sys" [dependencies] cslice = { version = "=0.1.1", path = "crates/cslice" } diff --git a/build.rs b/build.rs new file mode 100644 index 000000000..636490c38 --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +use std::env; + +fn main() { + if cfg!(windows) { + println!("cargo:node_root_dir={}", env::var("DEP_NEON_NODE_ROOT_DIR").unwrap()); + } +} diff --git a/crates/neon-sys/Cargo.toml b/crates/neon-sys/Cargo.toml index ff8967f1c..71aa40e43 100644 --- a/crates/neon-sys/Cargo.toml +++ b/crates/neon-sys/Cargo.toml @@ -17,3 +17,4 @@ cslice = { version = "=0.1.1", path = "../cslice" } [build-dependencies] gcc = "0.3" +regex = "0.1" diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index 2e310b270..d863f651a 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -1,58 +1,65 @@ extern crate gcc; +extern crate regex; use std::process::Command; use std::env; +use regex::Regex; -fn debug() -> bool { - match env::var("DEBUG") { - Ok(s) => s == "true", - Err(_) => false - } -} - -fn mode() -> &'static str { - if debug() { "Debug" } else { "Release" } -} - -#[cfg(unix)] -fn object_path(libname: &str) -> String { - format!("build/{}/obj.target/{}/src/{}.o", mode(), libname, libname) -} +fn main() { + // 1. Build the object file from source using node-gyp. + build_object_file(); -#[cfg(windows)] -fn object_path(libname: &str) -> String { - format!("build\\{}\\obj\\{}\\{}.obj", mode(), libname, libname) + // 2. Link the library from the object file using gcc. + link_library(); } -#[cfg(unix)] -const NPM_COMMAND : &'static str = "npm"; - -#[cfg(windows)] -const NPM_COMMAND : &'static str = "npm.cmd"; - fn build_object_file() { + let npm_command = if cfg!(unix) { "npm" } else { "npm.cmd" }; + let node_gyp_command = if cfg!(unix) { "node-gyp" } else { "node-gyp.cmd" }; + // Ensure that all package.json dependencies and dev dependencies are installed. - Command::new(NPM_COMMAND).args(&["install", "--silent"]).status().ok() - .expect(r#"failed to run "npm install" for neon-sys"#); + Command::new(npm_command).args(&["install", "--silent"]).status().ok().expect("Failed to run \"npm install\" for neon-sys!"); - // Run the package.json `configure` script, which invokes `node-gyp configure` from the local node_modules. - Command::new(NPM_COMMAND).args(&["run", "--silent"]).arg(if debug() { "configure-debug" } else { "configure-release" }).status().ok().unwrap(); + // Run `node-gyp configure` (appending -d in debug mode). + let configure_args = if debug() { vec!["configure", "-d"] } else { vec!["configure"] }; + let output = Command::new(node_gyp_command) + .args(&configure_args) + .output() + .expect("Failed to run \"node-gyp configure\" for neon-sys!"); + + if cfg!(windows) { + let stderr = String::from_utf8_lossy(&output.stderr); + let node_root_dir = Regex::new(r"'-Dnode_root_dir=(.+)'").unwrap() + .captures(&stderr) + .and_then(|captures| captures.at(1)) + .expect("Couldn't find node_root_dir in node-gyp output."); + println!("cargo:node_root_dir={}", node_root_dir); + } - // Run the package.json `build` script, which invokes `node-gyp build` from the local node_modules. - Command::new(NPM_COMMAND).args(&["run", "--silent"]).arg(if debug() { "build-debug" } else { "build-release" }).status().ok().unwrap(); + // Run `node-gyp build` (appending -d in debug mode). + let build_args = if debug() { vec!["build", "-d"] } else { vec!["build"] }; + Command::new(node_gyp_command) + .args(&build_args) + .status() + .ok() + .expect("Failed to run \"node-gyp build\" for neon-sys!"); } +// Link the built object file into a static library. fn link_library() { - // Link the built object file into a static library. - gcc::Config::new() - .object(object_path("neon")) - .compile("libneon.a"); -} + let configuration = if debug() { "Debug" } else { "Release" }; + let object_path = if cfg!(unix) { + format!("build/{}/obj.target/neon/src/neon.o", configuration) + } else { + format!("build\\{}\\obj\\neon\\neon.obj", configuration) + }; -fn main() { - // 1. Build the object file from source using node-gyp. - build_object_file(); + gcc::Config::new().object(object_path).compile("libneon.a"); +} - // 2. Link the library from the object file using gcc. - link_library(); +fn debug() -> bool { + match env::var("DEBUG") { + Ok(s) => s == "true", + Err(_) => false + } } diff --git a/crates/neon-sys/package.json b/crates/neon-sys/package.json index 3d2e97938..d2221d50e 100644 --- a/crates/neon-sys/package.json +++ b/crates/neon-sys/package.json @@ -1,14 +1,10 @@ { "main": "index.js", "scripts": { - "configure-release": "node-gyp configure", - "build-release": "node-gyp build", - "configure-debug": "node-gyp configure -d", - "build-debug": "node-gyp build -d" + "preinstall": "echo 'Skipping node-gyp installation as part of npm install.'" }, "devDependencies": { - "nan": "^2.3.2", - "node-gyp": "^3.3.1" + "nan": "^2.3.2" }, "dependencies": { "bindings": "1.2.1" diff --git a/tests/native/Cargo.toml b/tests/native/Cargo.toml index e9efed6ad..829405773 100644 --- a/tests/native/Cargo.toml +++ b/tests/native/Cargo.toml @@ -3,6 +3,7 @@ name = "tests" version = "0.1.0" authors = ["The Neon Community"] license = "MIT/Apache-2.0" +build = "build.rs" [lib] name = "tests" diff --git a/tests/native/build.rs b/tests/native/build.rs new file mode 100644 index 000000000..0376470f3 --- /dev/null +++ b/tests/native/build.rs @@ -0,0 +1,11 @@ +use std::env; + +fn main() { + if cfg!(windows) { + let debug = env::var("DEBUG").ok().map_or(false, |s| s == "true"); + let configuration = if debug { "Debug" } else { "Release" }; + let node_root_dir = env::var("DEP_NEON_SYS_NODE_ROOT_DIR").unwrap(); + println!("cargo:rustc-link-lib=node"); + println!("cargo:rustc-link-search={}\\{}", node_root_dir, configuration); + } +} From 5da00eb14caae3b5ef247a67b1cfa16cefeb95e9 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 26 Oct 2016 16:21:45 +0200 Subject: [PATCH 08/19] Prevent cargo build from hanging on Windows --- crates/neon-sys/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index d863f651a..79131f024 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -1,7 +1,7 @@ extern crate gcc; extern crate regex; -use std::process::Command; +use std::process::{Command, Stdio}; use std::env; use regex::Regex; @@ -39,6 +39,7 @@ fn build_object_file() { // Run `node-gyp build` (appending -d in debug mode). let build_args = if debug() { vec!["build", "-d"] } else { vec!["build"] }; Command::new(node_gyp_command) + .stderr(Stdio::null()) // Prevent cargo build from hanging on Windows. .args(&build_args) .status() .ok() From 8c80bc0510529014d1a6eb7dbedeee97faa44c0d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 26 Oct 2016 13:33:11 -0600 Subject: [PATCH 09/19] Use C calling convention This fixes link errors when compiling against 32-bit Node on Windows. Signed-off-by: Max Brunsfeld --- crates/neon-sys/src/array.rs | 2 +- crates/neon-sys/src/buffer.rs | 2 +- crates/neon-sys/src/call.rs | 2 +- crates/neon-sys/src/class.rs | 2 +- crates/neon-sys/src/convert.rs | 2 +- crates/neon-sys/src/error.rs | 2 +- crates/neon-sys/src/fun.rs | 2 +- crates/neon-sys/src/mem.rs | 2 +- crates/neon-sys/src/module.rs | 2 +- crates/neon-sys/src/object.rs | 2 +- crates/neon-sys/src/primitive.rs | 2 +- crates/neon-sys/src/scope.rs | 2 +- crates/neon-sys/src/string.rs | 2 +- crates/neon-sys/src/tag.rs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/neon-sys/src/array.rs b/crates/neon-sys/src/array.rs index 84a85474e..f6358b2a6 100644 --- a/crates/neon-sys/src/array.rs +++ b/crates/neon-sys/src/array.rs @@ -1,6 +1,6 @@ use raw::{Local, Isolate}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Array_New"] pub fn new(out: &mut Local, isolate: *mut Isolate, length: u32); diff --git a/crates/neon-sys/src/buffer.rs b/crates/neon-sys/src/buffer.rs index a6100ceed..1c9565612 100644 --- a/crates/neon-sys/src/buffer.rs +++ b/crates/neon-sys/src/buffer.rs @@ -3,7 +3,7 @@ use cslice::CMutSlice; // Suppress a spurious rustc warning about the use of CMutSlice. #[allow(improper_ctypes)] -extern "system" { +extern "C" { #[link_name = "NeonSys_Buffer_New"] pub fn new(out: &mut Local, size: u32) -> bool; diff --git a/crates/neon-sys/src/call.rs b/crates/neon-sys/src/call.rs index fdae07395..75408cd23 100644 --- a/crates/neon-sys/src/call.rs +++ b/crates/neon-sys/src/call.rs @@ -1,6 +1,6 @@ use raw::{FunctionCallbackInfo, Isolate, Local}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Call_SetReturn"] pub fn set_return(info: &FunctionCallbackInfo, value: Local); diff --git a/crates/neon-sys/src/class.rs b/crates/neon-sys/src/class.rs index a1cfb59c6..9b294b320 100644 --- a/crates/neon-sys/src/class.rs +++ b/crates/neon-sys/src/class.rs @@ -1,7 +1,7 @@ use std::os::raw::c_void; use raw::{Isolate, Local}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Class_GetClassMap"] pub fn get_class_map(isolate: *mut Isolate) -> *mut c_void; diff --git a/crates/neon-sys/src/convert.rs b/crates/neon-sys/src/convert.rs index b0954dfb5..b78b90eec 100644 --- a/crates/neon-sys/src/convert.rs +++ b/crates/neon-sys/src/convert.rs @@ -1,6 +1,6 @@ use raw::Local; -extern "system" { +extern "C" { #[link_name = "NeonSys_Convert_ToObject"] pub fn to_object(out: &mut Local, value: &Local) -> bool; diff --git a/crates/neon-sys/src/error.rs b/crates/neon-sys/src/error.rs index 7226fd92d..b257a5457 100644 --- a/crates/neon-sys/src/error.rs +++ b/crates/neon-sys/src/error.rs @@ -1,6 +1,6 @@ use raw::Local; -extern "system" { +extern "C" { #[link_name = "NeonSys_Error_Throw"] pub fn throw(val: Local); diff --git a/crates/neon-sys/src/fun.rs b/crates/neon-sys/src/fun.rs index d38ac8828..69dae698c 100644 --- a/crates/neon-sys/src/fun.rs +++ b/crates/neon-sys/src/fun.rs @@ -1,7 +1,7 @@ use std::os::raw::c_void; use raw::{FunctionCallbackInfo, Local}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Fun_New"] pub fn new(out: &mut Local, isolate: *mut c_void, callback: *mut c_void, kernel: *mut c_void) -> bool; diff --git a/crates/neon-sys/src/mem.rs b/crates/neon-sys/src/mem.rs index fd2ddf045..361f170b7 100644 --- a/crates/neon-sys/src/mem.rs +++ b/crates/neon-sys/src/mem.rs @@ -1,6 +1,6 @@ use raw::Local; -extern "system" { +extern "C" { #[link_name = "NeonSys_Mem_SameHandle"] pub fn same_handle(h1: Local, h2: Local) -> bool; diff --git a/crates/neon-sys/src/module.rs b/crates/neon-sys/src/module.rs index 3a5227811..1b194ab14 100644 --- a/crates/neon-sys/src/module.rs +++ b/crates/neon-sys/src/module.rs @@ -1,7 +1,7 @@ use std::os::raw::c_void; use raw::Local; -extern "system" { +extern "C" { #[link_name = "NeonSys_Module_ExecKernel"] pub fn exec_kernel(kernel: *mut c_void, callback: extern fn(*mut c_void, *mut c_void, *mut c_void), exports: Local, scope: *mut c_void); diff --git a/crates/neon-sys/src/object.rs b/crates/neon-sys/src/object.rs index 15222f8e3..cf83a69c3 100644 --- a/crates/neon-sys/src/object.rs +++ b/crates/neon-sys/src/object.rs @@ -1,6 +1,6 @@ use raw::{Isolate, Local}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Object_New"] pub fn new(out: &mut Local); diff --git a/crates/neon-sys/src/primitive.rs b/crates/neon-sys/src/primitive.rs index d274e26e7..2286d5106 100644 --- a/crates/neon-sys/src/primitive.rs +++ b/crates/neon-sys/src/primitive.rs @@ -1,6 +1,6 @@ use raw::{Local, Isolate}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Primitive_Undefined"] pub fn undefined(out: &mut Local); diff --git a/crates/neon-sys/src/scope.rs b/crates/neon-sys/src/scope.rs index 6860d7a01..179359e7b 100644 --- a/crates/neon-sys/src/scope.rs +++ b/crates/neon-sys/src/scope.rs @@ -1,7 +1,7 @@ use std::os::raw::c_void; use raw::{HandleScope, EscapableHandleScope, Local}; -extern "system" { +extern "C" { #[link_name = "NeonSys_Scope_Escape"] pub fn escape(out: &mut Local, scope: *mut EscapableHandleScope, value: Local); diff --git a/crates/neon-sys/src/string.rs b/crates/neon-sys/src/string.rs index 957823b60..4b9942cbe 100644 --- a/crates/neon-sys/src/string.rs +++ b/crates/neon-sys/src/string.rs @@ -1,6 +1,6 @@ use raw::{Local, Isolate}; -extern "system" { +extern "C" { #[link_name = "NeonSys_String_New"] pub fn new(out: &mut Local, isolate: *mut Isolate, data: *const u8, len: i32) -> bool; diff --git a/crates/neon-sys/src/tag.rs b/crates/neon-sys/src/tag.rs index b4c5e30b9..4529270ea 100644 --- a/crates/neon-sys/src/tag.rs +++ b/crates/neon-sys/src/tag.rs @@ -16,7 +16,7 @@ pub enum Tag { Other } -extern "system" { +extern "C" { #[link_name = "NeonSys_Tag_Of"] pub fn of(val: Local) -> Tag; From 5269af767ee8d23c4f98d70ad0c5afdc4ae664c2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 26 Oct 2016 13:33:14 -0600 Subject: [PATCH 10/19] Temporarily build node bindings only against ia32 for testing Signed-off-by: Max Brunsfeld --- crates/neon-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index 79131f024..d9f091c35 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -21,7 +21,7 @@ fn build_object_file() { Command::new(npm_command).args(&["install", "--silent"]).status().ok().expect("Failed to run \"npm install\" for neon-sys!"); // Run `node-gyp configure` (appending -d in debug mode). - let configure_args = if debug() { vec!["configure", "-d"] } else { vec!["configure"] }; + let configure_args = if debug() { vec!["configure", "-d", "--arch=ia32"] } else { vec!["configure", "--arch=ia32"] }; let output = Command::new(node_gyp_command) .args(&configure_args) .output() From 5af3a5ab86f7f3b95f988ab339b3621210093bab Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 26 Oct 2016 13:32:43 -0600 Subject: [PATCH 11/19] Base node-gyp --arch flag on Cargo target architecture Signed-off-by: Max Brunsfeld --- crates/neon-sys/build.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index d9f091c35..c5015c3f3 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -20,8 +20,18 @@ fn build_object_file() { // Ensure that all package.json dependencies and dev dependencies are installed. Command::new(npm_command).args(&["install", "--silent"]).status().ok().expect("Failed to run \"npm install\" for neon-sys!"); - // Run `node-gyp configure` (appending -d in debug mode). - let configure_args = if debug() { vec!["configure", "-d", "--arch=ia32"] } else { vec!["configure", "--arch=ia32"] }; + // Run `node-gyp configure` with correct debug and architecture flags + let mut configure_args = vec!["configure"]; + if debug() { + configure_args.push("--debug") + } + let target = env::var("TARGET").unwrap(); + if target.contains("i686") || target.contains("i586") { + configure_args.push("--arch=ia32"); + } else if target.contains("x86_64") { + configure_args.push("--arch=x64"); + } + let output = Command::new(node_gyp_command) .args(&configure_args) .output() From 377a5d3dc88becac35689018333ac2fb89e7ba3d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 26 Oct 2016 14:50:28 -0700 Subject: [PATCH 12/19] Test on both x86 and x64 platforms on appveyor --- appveyor.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 2e91ad40a..8d25c912e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,12 @@ environment: nodejs_version: "6" +platform: + - x86 + - x64 + install: - # Install node - ps: Install-Product node $env:nodejs_version - - # Install Rust - curl -sSf -o rustup-init.exe https://win.rustup.rs - rustup-init.exe -y - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin From 0ea08843d0cecf56dfba6f597a6a1e48427731a4 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 26 Oct 2016 14:56:47 -0700 Subject: [PATCH 13/19] Use Visual Studio 15.0 on Appveyor The alignof operator is not implemented in older versions of MSVC --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 8d25c912e..6dc1718fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,5 @@ +os: Visual Studio 2015 + environment: nodejs_version: "6" From d08ae692042645afd12dcf49fc7f0d4d478c6ae6 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 26 Oct 2016 15:13:24 -0700 Subject: [PATCH 14/19] Install the correct node.js for the current platform on appveyor --- appveyor.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6dc1718fd..5c1c93611 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,14 +1,16 @@ os: Visual Studio 2015 environment: - nodejs_version: "6" + NODEJS_VERSION: "6" platform: - x86 - x64 install: - - ps: Install-Product node $env:nodejs_version + - ps: Install-Product node $env:NODEJS_VERSION $env:PLATFORM + - node -e "console.log(process.arch, process.versions)" + - curl -sSf -o rustup-init.exe https://win.rustup.rs - rustup-init.exe -y - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin From 523afa321129fc4d7c8e956ccd9a00acfa1d60fe Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Oct 2016 09:14:34 +0200 Subject: [PATCH 15/19] Build on x64 on AppVeyor but compile for x86 as well --- appveyor.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5c1c93611..37e8258f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,19 +1,24 @@ os: Visual Studio 2015 +platform: x64 + environment: NODEJS_VERSION: "6" + matrix: + - NODE_ARCHITECTURE: x64 + RUST_TOOLCHAIN: stable-x86_64-pc-windows-msvc -platform: - - x86 - - x64 + - NODE_ARCHITECTURE: x86 + RUST_TOOLCHAIN: stable-i686-pc-windows-msvc install: - - ps: Install-Product node $env:NODEJS_VERSION $env:PLATFORM + - ps: Install-Product node $env:NODEJS_VERSION $env:NODE_ARCHITECTURE - node -e "console.log(process.arch, process.versions)" - curl -sSf -o rustup-init.exe https://win.rustup.rs - - rustup-init.exe -y + - rustup-init.exe -y --default-toolchain %RUST_TOOLCHAIN% - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin + - rustup show - rustc -V - cargo -V From 9949e5dbabb4b79975ef3f5f00915c0691f05390 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Oct 2016 11:02:04 +0200 Subject: [PATCH 16/19] Downcase npm environment variables to ensure they are read by node-gyp Apparently, on Windows, cargo capitalizes all the environment variables passed from the outside. Node-gyp, however, reads them in a case-sensitive way, thus forcing us to downcase them before running it. --- crates/neon-sys/build.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index c5015c3f3..814f7c547 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -17,19 +17,23 @@ fn build_object_file() { let npm_command = if cfg!(unix) { "npm" } else { "npm.cmd" }; let node_gyp_command = if cfg!(unix) { "node-gyp" } else { "node-gyp.cmd" }; + if cfg!(windows) { + // Downcase all the npm environment variables to ensure they are read by node-gyp. + for (key, value) in env::vars() { + if key.starts_with("NPM_CONFIG") { + env::remove_var(&key); + env::set_var(key.to_lowercase(), value); + } + } + } + // Ensure that all package.json dependencies and dev dependencies are installed. Command::new(npm_command).args(&["install", "--silent"]).status().ok().expect("Failed to run \"npm install\" for neon-sys!"); - // Run `node-gyp configure` with correct debug and architecture flags - let mut configure_args = vec!["configure"]; + // Run `node-gyp configure` in verbose mode to read node_root_dir on Windows. + let mut configure_args = vec!["configure", "--verbose"]; if debug() { - configure_args.push("--debug") - } - let target = env::var("TARGET").unwrap(); - if target.contains("i686") || target.contains("i586") { - configure_args.push("--arch=ia32"); - } else if target.contains("x86_64") { - configure_args.push("--arch=x64"); + configure_args.push("--debug"); } let output = Command::new(node_gyp_command) @@ -47,7 +51,11 @@ fn build_object_file() { } // Run `node-gyp build` (appending -d in debug mode). - let build_args = if debug() { vec!["build", "-d"] } else { vec!["build"] }; + let mut build_args = vec!["build"]; + if debug() { + build_args.push("--debug"); + } + Command::new(node_gyp_command) .stderr(Stdio::null()) // Prevent cargo build from hanging on Windows. .args(&build_args) From a33091bcf1538dae5e1ab6af1af5458d7b951609 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Oct 2016 12:47:42 +0200 Subject: [PATCH 17/19] Test 32bit and 64bit compilation on a x86 platform on AppVeyor --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 37e8258f3..5fc1a6939 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,8 @@ os: Visual Studio 2015 -platform: x64 +platform: + - x64 + - x86 environment: NODEJS_VERSION: "6" From 73ad12c9fb4133221c011e8f461750f885f3acae Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Oct 2016 19:44:24 +0200 Subject: [PATCH 18/19] Remove build dependency on regex crate Signed-off-by: Max Brunsfeld --- crates/neon-sys/Cargo.toml | 1 - crates/neon-sys/build.rs | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/neon-sys/Cargo.toml b/crates/neon-sys/Cargo.toml index 71aa40e43..ff8967f1c 100644 --- a/crates/neon-sys/Cargo.toml +++ b/crates/neon-sys/Cargo.toml @@ -17,4 +17,3 @@ cslice = { version = "=0.1.1", path = "../cslice" } [build-dependencies] gcc = "0.3" -regex = "0.1" diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index 814f7c547..e1f814fb3 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -1,9 +1,7 @@ extern crate gcc; -extern crate regex; use std::process::{Command, Stdio}; use std::env; -use regex::Regex; fn main() { // 1. Build the object file from source using node-gyp. @@ -42,12 +40,14 @@ fn build_object_file() { .expect("Failed to run \"node-gyp configure\" for neon-sys!"); if cfg!(windows) { - let stderr = String::from_utf8_lossy(&output.stderr); - let node_root_dir = Regex::new(r"'-Dnode_root_dir=(.+)'").unwrap() - .captures(&stderr) - .and_then(|captures| captures.at(1)) + let node_gyp_output = String::from_utf8_lossy(&output.stderr); + let node_root_dir_flag_pattern = "'-Dnode_root_dir="; + let node_root_dir_start_index = node_gyp_output + .find(node_root_dir_flag_pattern) + .map(|i| i + node_root_dir_flag_pattern.len()) .expect("Couldn't find node_root_dir in node-gyp output."); - println!("cargo:node_root_dir={}", node_root_dir); + let node_root_dir_end_index = node_gyp_output[node_root_dir_start_index..].find("'").unwrap() + node_root_dir_start_index; + println!("cargo:node_root_dir={}", &node_gyp_output[node_root_dir_start_index..node_root_dir_end_index]); } // Run `node-gyp build` (appending -d in debug mode). From 895d706d1c965ddbbe1e2322edc1682212daefa5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 28 Oct 2016 15:04:33 +0200 Subject: [PATCH 19/19] Parameterize node_lib_file in addition to node_root_dir ...because on newer Electron versions node-gyp stores the library as `iojs.lib` and not as `node.lib`. --- build.rs | 1 + crates/neon-sys/build.rs | 7 +++++++ tests/native/build.rs | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 636490c38..eb423cfab 100644 --- a/build.rs +++ b/build.rs @@ -3,5 +3,6 @@ use std::env; fn main() { if cfg!(windows) { println!("cargo:node_root_dir={}", env::var("DEP_NEON_NODE_ROOT_DIR").unwrap()); + println!("cargo:node_lib_file={}", env::var("DEP_NEON_NODE_LIB_FILE").unwrap()); } } diff --git a/crates/neon-sys/build.rs b/crates/neon-sys/build.rs index e1f814fb3..0c5b49e95 100644 --- a/crates/neon-sys/build.rs +++ b/crates/neon-sys/build.rs @@ -48,6 +48,13 @@ fn build_object_file() { .expect("Couldn't find node_root_dir in node-gyp output."); let node_root_dir_end_index = node_gyp_output[node_root_dir_start_index..].find("'").unwrap() + node_root_dir_start_index; println!("cargo:node_root_dir={}", &node_gyp_output[node_root_dir_start_index..node_root_dir_end_index]); + let node_lib_file_flag_pattern = "'-Dnode_lib_file="; + let node_lib_file_start_index = node_gyp_output + .find(node_lib_file_flag_pattern) + .map(|i| i + node_lib_file_flag_pattern.len()) + .expect("Couldn't find node_lib_file in node-gyp output."); + let node_lib_file_end_index = node_gyp_output[node_lib_file_start_index..].find(".lib").unwrap() + node_lib_file_start_index; + println!("cargo:node_lib_file={}", &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index]); } // Run `node-gyp build` (appending -d in debug mode). diff --git a/tests/native/build.rs b/tests/native/build.rs index 0376470f3..59242e3b2 100644 --- a/tests/native/build.rs +++ b/tests/native/build.rs @@ -5,7 +5,8 @@ fn main() { let debug = env::var("DEBUG").ok().map_or(false, |s| s == "true"); let configuration = if debug { "Debug" } else { "Release" }; let node_root_dir = env::var("DEP_NEON_SYS_NODE_ROOT_DIR").unwrap(); - println!("cargo:rustc-link-lib=node"); + let node_lib_file = env::var("DEP_NEON_SYS_NODE_LIB_FILE").unwrap(); println!("cargo:rustc-link-search={}\\{}", node_root_dir, configuration); + println!("cargo:rustc-link-lib={}", node_lib_file); } }