From 177e41b75313fd0babde698983db9fff8b7e1024 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 3 Aug 2020 12:21:22 +0800 Subject: [PATCH] docs: fix docs.rs build, add badges to README --- .github/workflows/linux-musl.yaml | 2 +- README.md | 4 ++++ sys/Cargo.toml | 11 +++++++++++ sys/build.rs | 32 +++++++++---------------------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/linux-musl.yaml b/.github/workflows/linux-musl.yaml index 0dbd2fe3..45cee299 100644 --- a/.github/workflows/linux-musl.yaml +++ b/.github/workflows/linux-musl.yaml @@ -35,7 +35,7 @@ jobs: - name: Run check run: | - docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder cargo check --all --bins --examples --tests -vvv + docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder cargo check -vvv - name: Run tests run: | diff --git a/README.md b/README.md index 6268a407..a5f36605 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ > This project was initialized from [xray](https://github.com/atom/xray) +![](https://docs.rs/napi/badge.svg?version=0.4.2) +![](https://img.shields.io/crates/v/napi.svg) +![](https://img.shields.io/npm/v/napi-rs.svg) + # Platform Support ![](https://github.com/napi-rs/napi-rs/workflows/macOS/badge.svg) diff --git a/sys/Cargo.toml b/sys/Cargo.toml index 483b1675..4001aa45 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -9,13 +9,24 @@ repository = "https://github.com/napi-rs/napi-rs" license = "MIT" keywords = ["NodeJS", "FFI", "NAPI", "n-api"] +[features] +docs-rs = [] + [target.'cfg(windows)'.build-dependencies] flate2 = "1.0" reqwest = { version = "0.10", features = ["native-tls", "blocking"] } tar = "0.4" +[target.x86_64-unknown-linux-gnu.build-dependencies] +flate2 = "1.0" +reqwest = { version = "0.10", features = ["native-tls", "blocking"] } +tar = "0.4" + [build-dependencies] bindgen = "0.54" glob = "0.3" regex = "1.3" semver = "0.10" + +[package.metadata.docs.rs] +features = ["docs"] diff --git a/sys/build.rs b/sys/build.rs index aff9e17a..7f795763 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -1,11 +1,11 @@ extern crate bindgen; -#[cfg(windows)] +#[cfg(any(target_os = "windows", feature = "docs-rs"))] extern crate flate2; extern crate glob; -#[cfg(windows)] +#[cfg(any(target_os = "windows", feature = "docs-rs"))] extern crate reqwest; extern crate semver; -#[cfg(windows)] +#[cfg(any(target_os = "windows", feature = "docs-rs"))] extern crate tar; use glob::glob; @@ -14,8 +14,7 @@ use std::env; use std::path::PathBuf; use std::process::Command; -// https://stackoverflow.com/questions/37498864/finding-executable-in-path-with-rust - +#[cfg(not(any(target_os = "windows", feature = "docs-rs")))] const NODE_PRINT_EXEC_PATH: &'static str = "console.log(process.execPath)"; fn main() { @@ -56,24 +55,11 @@ fn main() { .expect("Unable to write napi bindings"); } -#[cfg(target_os = "windows")] +#[cfg(any(target_os = "windows", feature = "docs-rs"))] fn find_node_include_path(node_full_version: &str) -> PathBuf { - let mut node_exec_path = PathBuf::from( - String::from_utf8( - Command::new("node") - .arg("-e") - .arg(NODE_PRINT_EXEC_PATH) - .output() - .unwrap() - .stdout, - ) - .expect("can not find executable node"), - ) - .parent() - .unwrap() - .to_path_buf(); - node_exec_path.push(format!("node-headers-{}.tar.gz", node_full_version)); - let mut header_dist_path = PathBuf::from(&PathBuf::from(&node_exec_path).parent().unwrap()); + let mut out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + out_path.push(format!("node-headers-{}.tar.gz", node_full_version)); + let mut header_dist_path = PathBuf::from(&PathBuf::from(&out_path).parent().unwrap()); let unpack_path = PathBuf::from(&header_dist_path); header_dist_path.push(format!("node-{}", node_full_version)); header_dist_path.push("include"); @@ -95,7 +81,7 @@ fn find_node_include_path(node_full_version: &str) -> PathBuf { header_dist_path } -#[cfg(not(target_os = "windows"))] +#[cfg(not(any(target_os = "windows", feature = "docs-rs")))] fn find_node_include_path(_node_full_version: &str) -> PathBuf { let node_exec_path = String::from_utf8( Command::new("node")