Skip to content

Commit

Permalink
chore: clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jun 18, 2024
1 parent 14d8899 commit c45692d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
1 change: 1 addition & 0 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::zero_repeat_side_effects)]
#![allow(deprecated)]

#[macro_use]
Expand Down
4 changes: 2 additions & 2 deletions bench/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use napi::{CallContext, JsExternal, JsObject, JsString};

#[derive(Clone)]
pub struct QueryEngine {
pub datamodel: String,
pub _datamodel: String,
}

unsafe impl Sync for QueryEngine {}
Expand Down Expand Up @@ -40,7 +40,7 @@ fn new_engine(ctx: CallContext) -> napi::Result<napi::JsExternal> {
let a = ctx.get::<JsString>(0)?.into_utf8()?;
let model = a.into_owned()?;
let model_len = model.len();
let qe = QueryEngine { datamodel: model };
let qe = QueryEngine { _datamodel: model };
ctx.env.create_external(qe, Some(model_len as i64))
}

Expand Down
50 changes: 5 additions & 45 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod android;
mod macos;
mod wasi;
mod windows;

use std::env;
use std::path::PathBuf;

pub fn setup() {
println!("cargo:rerun-if-env-changed=DEBUG_GENERATED_CODE");
Expand All @@ -18,51 +18,11 @@ pub fn setup() {
Ok("wasi") => {
wasi::setup();
}
_ => {}
}

if env::var("CARGO_CFG_TARGET_ENV").unwrap().contains("gnu") {
let target_triple = env::var("TARGET").unwrap();
if target_triple.contains("windows") {
let libnode_path = search_libnode_path();
if let Some(libnode_dir) = libnode_path {
let node_lib_path = libnode_dir.join("libnode.dll");
if node_lib_path.exists() {
println!("cargo:rustc-link-search=native={}", libnode_dir.display());
println!("cargo:rustc-link-lib=node");
} else {
panic!("libnode.dll not found in {}", libnode_dir.display());
}
} else {
panic!("libnode.dll not found in any search path");
}
}
}
}

fn search_libnode_path() -> Option<PathBuf> {
if let Ok(path) = env::var("LIBNODE_PATH") {
let libnode_dir = PathBuf::from(path);
if libnode_dir.exists() {
return Some(libnode_dir);
}
}

if let Ok(paths) = env::var("LIBPATH") {
for path in env::split_paths(&paths) {
if path.join("libnode.dll").exists() {
return Some(path);
}
}
}

if let Ok(paths) = env::var("PATH") {
for path in env::split_paths(&paths) {
if path.join("libnode.dll").exists() {
return Some(path);
Ok("windows") => {
if let Ok("gnu") = env::var("CARGO_CFG_TARGET_ENV").as_deref() {
windows::setup_gnu();
}
}
_ => {}
}

None
}
44 changes: 44 additions & 0 deletions crates/build/src/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::env;
use std::path::PathBuf;

pub fn setup_gnu() {
let libnode_path = search_libnode_path();
if let Some(libnode_dir) = libnode_path {
let node_lib_path = libnode_dir.join("libnode.dll");
if node_lib_path.exists() {
println!("cargo:rustc-link-search=native={}", libnode_dir.display());
println!("cargo:rustc-link-lib=node");
} else {
panic!("libnode.dll not found in {}", libnode_dir.display());
}
} else {
panic!("libnode.dll not found in any search path");
}
}

fn search_libnode_path() -> Option<PathBuf> {
if let Ok(path) = env::var("LIBNODE_PATH") {
let libnode_dir = PathBuf::from(path);
if libnode_dir.exists() {
return Some(libnode_dir);
}
}

if let Ok(paths) = env::var("LIBPATH") {
for path in env::split_paths(&paths) {
if path.join("libnode.dll").exists() {
return Some(path);
}
}
}

if let Ok(paths) = env::var("PATH") {
for path in env::split_paths(&paths) {
if path.join("libnode.dll").exists() {
return Some(path);
}
}
}

None
}
2 changes: 1 addition & 1 deletion crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ optional = true
version = "2"

[build-dependencies]
napi-build = {path = "../build"}
napi-build = { path = "../build" }
8 changes: 5 additions & 3 deletions crates/napi/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern crate napi_build;

fn main() {
napi_build::setup();
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
if target_os == "windows" && target_env == "gnu" {
napi_build::setup();
}
}
2 changes: 1 addition & 1 deletion crates/napi/src/bindgen_runtime/js_values/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(deprecated)]

use std::{ptr, usize};
use std::ptr;

use super::{FromNapiValue, ToNapiValue, TypeName, Unknown, ValidateNapiValue};

Expand Down
2 changes: 1 addition & 1 deletion examples/napi-compat-mode/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn call_function_with_this(ctx: CallContext) -> Result<JsNull> {
let js_this: JsObject = ctx.this_unchecked();
let js_func = ctx.get::<Function<()>>(0)?;

js_func.apply(&js_this, ())?;
js_func.apply(js_this, ())?;

ctx.env.get_null()
}
Expand Down
1 change: 1 addition & 0 deletions examples/napi-compat-mode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(unused_variables)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::zero_repeat_side_effects)]
#![allow(deprecated)]

#[macro_use]
Expand Down

0 comments on commit c45692d

Please sign in to comment.