From 5b83c05045b793239f0bc2327d978a6b407be909 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Wed, 9 Aug 2017 15:17:21 -0500 Subject: [PATCH 1/5] Fix linking neon-runtime on windows. -l is only intended to communicate the names of libraries See https://github.com/rust-lang/rust/issues/38850 for more details. --- crates/neon-build/src/lib.rs | 5 ++++- crates/neon-runtime/build.rs | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/neon-build/src/lib.rs b/crates/neon-build/src/lib.rs index 0856f6409..c780cf78a 100644 --- a/crates/neon-build/src/lib.rs +++ b/crates/neon-build/src/lib.rs @@ -1,4 +1,5 @@ use std::env; +use std::path::Path; /// Set up the build environment by setting Cargo configuration variables. pub fn setup() { @@ -7,7 +8,9 @@ pub fn setup() { let configuration = if debug { "Debug" } else { "Release" }; let node_root_dir = env::var("DEP_NEON_RUNTIME_NODE_ROOT_DIR").unwrap(); let node_lib_file = env::var("DEP_NEON_RUNTIME_NODE_LIB_FILE").unwrap(); + let node_lib_path = Path::new(&node_lib_file); println!("cargo:rustc-link-search={}\\{}", node_root_dir, configuration); - println!("cargo:rustc-link-lib={}", node_lib_file); + println!("cargo:rustc-link-search=native={}", &node_lib_path.parent().unwrap().display()); + println!("cargo:rustc-link-lib={}", &node_lib_path.file_stem().unwrap().to_str().unwrap()); } } diff --git a/crates/neon-runtime/build.rs b/crates/neon-runtime/build.rs index d0d311976..968cccf04 100644 --- a/crates/neon-runtime/build.rs +++ b/crates/neon-runtime/build.rs @@ -57,8 +57,9 @@ fn build_object_file() { .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]); + let node_lib_file_end_index = node_gyp_output[node_lib_file_start_index..].find("'").unwrap() + node_lib_file_start_index; + let node_lib_file = &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index]; + println!("cargo:node_lib_file={}", node_lib_file); } // Run `node-gyp build`. From 99be4c82b6230900e088e0d5551d86149a7b9952 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 10 Aug 2017 21:31:30 -0500 Subject: [PATCH 2/5] replace <(target_arch) string with the actual target_arch --- crates/neon-runtime/Cargo.toml | 1 + crates/neon-runtime/build.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/neon-runtime/Cargo.toml b/crates/neon-runtime/Cargo.toml index f1d87b843..5ccd9e16b 100644 --- a/crates/neon-runtime/Cargo.toml +++ b/crates/neon-runtime/Cargo.toml @@ -17,3 +17,4 @@ cslice = "0.2" [build-dependencies] gcc = "0.3" +regex = "0.2" diff --git a/crates/neon-runtime/build.rs b/crates/neon-runtime/build.rs index 968cccf04..200c31860 100644 --- a/crates/neon-runtime/build.rs +++ b/crates/neon-runtime/build.rs @@ -1,7 +1,9 @@ extern crate gcc; +extern crate regex; use std::process::Command; use std::env; +use regex::Regex; fn main() { // 1. Build the object file from source using node-gyp. @@ -45,6 +47,8 @@ fn build_object_file() { if cfg!(windows) { let node_gyp_output = String::from_utf8_lossy(&output.stderr); + let version_regex = Regex::new(r"node@(?P\d+\.\d+\.\d+)\s+\|\s+(?P\w+)\s+\|\s(?Pia32|x64)").unwrap(); + let captures = version_regex.captures(&node_gyp_output).unwrap(); let node_root_dir_flag_pattern = "'-Dnode_root_dir="; let node_root_dir_start_index = node_gyp_output .find(node_root_dir_flag_pattern) @@ -58,7 +62,7 @@ fn build_object_file() { .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("'").unwrap() + node_lib_file_start_index; - let node_lib_file = &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index]; + let node_lib_file = &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index].replace("<(target_arch)", &captures["arch"]); println!("cargo:node_lib_file={}", node_lib_file); } From a188d3d751c80b4438c0948d2f0c2669f80f0b05 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 17 Aug 2017 21:13:52 -0500 Subject: [PATCH 3/5] make compatible with npm <= 5.0.0 npm 5.0.3 changed the CLI output so '-Dnode_lib_file' returned the path of the file vs just the file name. --- build.rs | 1 + crates/neon-build/src/lib.rs | 9 ++++++--- crates/neon-runtime/build.rs | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index eb423cfab..1403e0996 100644 --- a/build.rs +++ b/build.rs @@ -3,6 +3,7 @@ use std::env; fn main() { if cfg!(windows) { println!("cargo:node_root_dir={}", env::var("DEP_NEON_NODE_ROOT_DIR").unwrap()); + println!("cargo:node_arch={}", env::var("DEP_NEON_NODE_ARCH").unwrap()); println!("cargo:node_lib_file={}", env::var("DEP_NEON_NODE_LIB_FILE").unwrap()); } } diff --git a/crates/neon-build/src/lib.rs b/crates/neon-build/src/lib.rs index c780cf78a..d5a769dc6 100644 --- a/crates/neon-build/src/lib.rs +++ b/crates/neon-build/src/lib.rs @@ -8,9 +8,12 @@ pub fn setup() { let configuration = if debug { "Debug" } else { "Release" }; let node_root_dir = env::var("DEP_NEON_RUNTIME_NODE_ROOT_DIR").unwrap(); let node_lib_file = env::var("DEP_NEON_RUNTIME_NODE_LIB_FILE").unwrap(); - let node_lib_path = Path::new(&node_lib_file); + let node_arch = env::var("DEP_NEON_RUNTIME_NODE_ARCH").unwrap(); + let node_lib_file_path = Path::new(&node_lib_file); + let mut node_lib_path = Path::new(&node_root_dir).to_path_buf(); + node_lib_path.push(&node_arch); println!("cargo:rustc-link-search={}\\{}", node_root_dir, configuration); - println!("cargo:rustc-link-search=native={}", &node_lib_path.parent().unwrap().display()); - println!("cargo:rustc-link-lib={}", &node_lib_path.file_stem().unwrap().to_str().unwrap()); + println!("cargo:rustc-link-search=native={}", &node_lib_path.display()); + println!("cargo:rustc-link-lib={}", &node_lib_file_path.file_stem().unwrap().to_str().unwrap()); } } diff --git a/crates/neon-runtime/build.rs b/crates/neon-runtime/build.rs index 200c31860..57289814c 100644 --- a/crates/neon-runtime/build.rs +++ b/crates/neon-runtime/build.rs @@ -49,6 +49,7 @@ fn build_object_file() { let node_gyp_output = String::from_utf8_lossy(&output.stderr); let version_regex = Regex::new(r"node@(?P\d+\.\d+\.\d+)\s+\|\s+(?P\w+)\s+\|\s(?Pia32|x64)").unwrap(); let captures = version_regex.captures(&node_gyp_output).unwrap(); + println!("cargo:node_arch={}", &captures["arch"]); let node_root_dir_flag_pattern = "'-Dnode_root_dir="; let node_root_dir_start_index = node_gyp_output .find(node_root_dir_flag_pattern) @@ -62,7 +63,7 @@ fn build_object_file() { .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("'").unwrap() + node_lib_file_start_index; - let node_lib_file = &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index].replace("<(target_arch)", &captures["arch"]); + let node_lib_file = &node_gyp_output[node_lib_file_start_index..node_lib_file_end_index]; println!("cargo:node_lib_file={}", node_lib_file); } From a324cea83d59004b2bc33da89087310479eaaa28 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 17 Aug 2017 21:24:05 -0500 Subject: [PATCH 4/5] test latest + lts version of node, remove dupe platform matrix --- appveyor.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 40ba7a8ac..be5016fbd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,21 +1,23 @@ os: Visual Studio 2015 -platform: - - x64 - - x86 - environment: - NODEJS_VERSION: "6" RUST_BACKTRACE: 1 matrix: - - NODE_ARCHITECTURE: x64 + - PLATFORM: x64 + NODEJS_VERSION: "6" RUST_TOOLCHAIN: stable-x86_64-pc-windows-msvc - - - NODE_ARCHITECTURE: x86 + - PLATFORM: x86 + NODEJS_VERSION: "6" + RUST_TOOLCHAIN: stable-i686-pc-windows-msvc + - PLATFORM: x64 + NODEJS_VERSION: "8" + RUST_TOOLCHAIN: stable-x86_64-pc-windows-msvc + - PLATFORM: x86 + NODEJS_VERSION: "8" RUST_TOOLCHAIN: stable-i686-pc-windows-msvc install: - - ps: Install-Product node $env:NODEJS_VERSION $env:NODE_ARCHITECTURE + - ps: Install-Product node $env:NODEJS_VERSION $env:PLATFORM - npm config set msvs_version 2015 - node -e "console.log(process.argv[0], process.arch, process.versions)" From 331852ff1dd642ea3429ef822cd1ecf3ba4f031e Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 17 Aug 2017 23:54:25 -0500 Subject: [PATCH 5/5] fix gcc::Config deprecation warning --- crates/neon-runtime/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/neon-runtime/build.rs b/crates/neon-runtime/build.rs index 57289814c..14edcac1c 100644 --- a/crates/neon-runtime/build.rs +++ b/crates/neon-runtime/build.rs @@ -84,7 +84,7 @@ fn link_library() { format!("build\\{}\\obj\\neon\\neon.obj", configuration) }; - gcc::Config::new().object(object_path).compile("libneon.a"); + gcc::Build::new().object(object_path).compile("libneon.a"); } fn debug() -> bool {