feat: edition 2021
This commit is contained in:
parent
b2e71b5e03
commit
e452c00fb4
16 changed files with 62 additions and 36 deletions
2
.github/workflows/lint.yaml
vendored
2
.github/workflows/lint.yaml
vendored
|
@ -62,7 +62,7 @@ jobs:
|
|||
run: cargo fmt -- --check
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy --all-features
|
||||
run: cargo clippy
|
||||
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
|
|
|
@ -55,6 +55,10 @@ _Main branch is now under napi@next developing. Checkout [v1 docs](https://napi.
|
|||
[![Windows arm64](https://github.com/napi-rs/napi-rs/actions/workflows/windows-arm.yml/badge.svg)](https://github.com/napi-rs/napi-rs/actions/workflows/windows-arm.yml)
|
||||
[![FreeBSD](https://api.cirrus-ci.com/github/napi-rs/napi-rs.svg)](https://cirrus-ci.com/github/napi-rs/napi-rs?branch=main)
|
||||
|
||||
## MSRV
|
||||
|
||||
**Rust** `1.57.0`
|
||||
|
||||
| | node12 | node14 | node16 | node17 |
|
||||
| --------------------- | ------ | ------ | ------ | ------ |
|
||||
| Windows x64 | ✓ | ✓ | ✓ | ✓ |
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
name = "napi-bench"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
description = "Codegen backend for napi procedural macro"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
homepage = "https://napi.rs"
|
||||
license = "MIT"
|
||||
name = "napi-derive-backend"
|
||||
|
@ -9,9 +9,9 @@ repository = "https://github.com/napi-rs/napi-rs"
|
|||
version = "1.0.16"
|
||||
|
||||
[features]
|
||||
noop = []
|
||||
strict = []
|
||||
type-def = ["regex", "once_cell"]
|
||||
noop = []
|
||||
|
||||
[dependencies]
|
||||
convert_case = "0.4"
|
||||
|
|
|
@ -107,7 +107,7 @@ impl NapiEnum {
|
|||
let mut define_properties = vec![];
|
||||
|
||||
for variant in self.variants.iter() {
|
||||
let name_lit = Literal::string(&format!("{}\0", variant.name.to_string()));
|
||||
let name_lit = Literal::string(&format!("{}\0", variant.name));
|
||||
let val_lit = Literal::i32_unsuffixed(variant.val);
|
||||
|
||||
define_properties.push(quote! {
|
||||
|
|
|
@ -82,10 +82,7 @@ impl TryToTokens for NapiStruct {
|
|||
|
||||
impl NapiStruct {
|
||||
fn gen_helper_mod(&self) -> TokenStream {
|
||||
let mod_name = Ident::new(
|
||||
&format!("__napi_helper__{}", self.name.to_string()),
|
||||
Span::call_site(),
|
||||
);
|
||||
let mod_name = Ident::new(&format!("__napi_helper__{}", self.name), Span::call_site());
|
||||
|
||||
let ctor = if self.kind == NapiStructKind::Constructor {
|
||||
self.gen_default_ctor()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
description = "N-API build support"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"]
|
||||
keywords = ["NodeJS", "FFI", "NAPI", "n-api"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>", "Forehalo <forehalo@gmail.com>"]
|
||||
description = "N-API procedural macros"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
keywords = ["NodeJS", "FFI", "NAPI", "n-api"]
|
||||
license = "MIT"
|
||||
name = "napi-derive"
|
||||
|
@ -13,9 +13,9 @@ version = "2.0.0-beta.4"
|
|||
compat-mode = []
|
||||
default = ["compat-mode", "full"]
|
||||
full = ["type-def", "strict"]
|
||||
noop = ["napi-derive-backend/noop"]
|
||||
strict = ["napi-derive-backend/strict"]
|
||||
type-def = ["napi-derive-backend/type-def"]
|
||||
noop = ["napi-derive-backend/noop"]
|
||||
|
||||
[dependencies]
|
||||
convert_case = "0.4"
|
||||
|
|
|
@ -8,22 +8,29 @@ extern crate syn;
|
|||
extern crate napi_derive_backend;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
use napi_derive_backend::{BindgenResult, TryToTokens};
|
||||
|
||||
#[cfg(feature = "type-def")]
|
||||
use napi_derive_backend::{ToTypeDef, TypeDef};
|
||||
use parser::{attrs::BindgenAttrs, ParseNapi};
|
||||
use proc_macro::TokenStream as RawStream;
|
||||
use proc_macro2::{TokenStream, TokenTree};
|
||||
use quote::ToTokens;
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use std::env;
|
||||
#[cfg(feature = "type-def")]
|
||||
#[cfg(all(feature = "type-def", not(feature = "noop")))]
|
||||
use std::{
|
||||
fs,
|
||||
io::{BufWriter, Result as IOResult, Write},
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use napi_derive_backend::{BindgenResult, TryToTokens};
|
||||
#[cfg(all(feature = "type-def", not(feature = "noop")))]
|
||||
use napi_derive_backend::{ToTypeDef, TypeDef};
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use parser::{attrs::BindgenAttrs, ParseNapi};
|
||||
use proc_macro::TokenStream as RawStream;
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use proc_macro2::{TokenStream, TokenTree};
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use quote::ToTokens;
|
||||
#[cfg(feature = "compat-mode")]
|
||||
use syn::{fold::Fold, parse_macro_input, ItemFn};
|
||||
#[cfg(not(feature = "noop"))]
|
||||
use syn::{Attribute, Item};
|
||||
|
||||
/// ```ignore
|
||||
|
@ -32,12 +39,13 @@ use syn::{Attribute, Item};
|
|||
/// "hello" + name
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(not(feature = "noop"))]
|
||||
#[proc_macro_attribute]
|
||||
pub fn napi(attr: RawStream, input: RawStream) -> RawStream {
|
||||
match expand(attr.into(), input.into()) {
|
||||
Ok(tokens) => {
|
||||
if env::var("DEBUG_GENERATED_CODE").is_ok() {
|
||||
println!("{}", tokens.to_string());
|
||||
println!("{}", tokens);
|
||||
}
|
||||
tokens.into()
|
||||
}
|
||||
|
@ -49,6 +57,13 @@ pub fn napi(attr: RawStream, input: RawStream) -> RawStream {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "noop")]
|
||||
#[proc_macro_attribute]
|
||||
pub fn napi(_attr: RawStream, input: RawStream) -> RawStream {
|
||||
input
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "noop"))]
|
||||
fn expand(attr: TokenStream, input: TokenStream) -> BindgenResult<TokenStream> {
|
||||
let mut item = syn::parse2::<syn::Item>(input)?;
|
||||
let opts: BindgenAttrs = syn::parse2(attr)?;
|
||||
|
@ -125,7 +140,7 @@ fn expand(attr: TokenStream, input: TokenStream) -> BindgenResult<TokenStream> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "type-def")]
|
||||
#[cfg(all(feature = "type-def", not(feature = "noop")))]
|
||||
fn output_type_def(type_def_file: String, type_def: TypeDef) -> IOResult<()> {
|
||||
let file = fs::OpenOptions::new()
|
||||
.append(true)
|
||||
|
@ -273,6 +288,7 @@ pub fn module_exports(_attr: RawStream, input: RawStream) -> RawStream {
|
|||
.into()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "noop"))]
|
||||
fn replace_napi_attr_in_mod(
|
||||
js_namespace: String,
|
||||
attrs: &mut Vec<syn::Attribute>,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["Nathan Sobo <nathan@github.com>", "Yinan Long <lynweklm@gmail.com>"]
|
||||
description = "N-API bindings"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
keywords = ["NodeJS", "Node", "FFI", "NAPI", "n-api"]
|
||||
license = "MIT"
|
||||
name = "napi"
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
js_values::*,
|
||||
sys,
|
||||
task::Task,
|
||||
Error, ExtendedErrorInfo, JsError, NodeVersion, Result, Status, ValueType,
|
||||
Error, ExtendedErrorInfo, NodeVersion, Result, Status, ValueType,
|
||||
};
|
||||
|
||||
#[cfg(feature = "napi8")]
|
||||
|
@ -22,6 +22,8 @@ use crate::cleanup_env::{CleanupEnvHook, CleanupEnvHookData};
|
|||
use crate::js_values::{De, Ser};
|
||||
#[cfg(feature = "napi4")]
|
||||
use crate::threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction};
|
||||
#[cfg(feature = "napi3")]
|
||||
use crate::JsError;
|
||||
#[cfg(all(feature = "serde-json"))]
|
||||
use serde::de::DeserializeOwned;
|
||||
#[cfg(all(feature = "serde-json"))]
|
||||
|
|
|
@ -25,6 +25,7 @@ pub struct Error {
|
|||
pub reason: String,
|
||||
// Convert raw `JsError` into Error
|
||||
// Only be used in `async fn(p: Promise<T>)` scenario
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
pub(crate) maybe_raw: sys::napi_ref,
|
||||
}
|
||||
|
||||
|
@ -54,6 +55,7 @@ impl From<SerdeJSONError> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
impl From<sys::napi_ref> for Error {
|
||||
fn from(value: sys::napi_ref) -> Self {
|
||||
Self {
|
||||
|
@ -79,6 +81,7 @@ impl Error {
|
|||
Error {
|
||||
status,
|
||||
reason,
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
maybe_raw: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +90,7 @@ impl Error {
|
|||
Error {
|
||||
status,
|
||||
reason: "".to_owned(),
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
maybe_raw: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +99,7 @@ impl Error {
|
|||
Error {
|
||||
status: Status::GenericFailure,
|
||||
reason,
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
maybe_raw: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +110,7 @@ impl From<std::ffi::NulError> for Error {
|
|||
Error {
|
||||
status: Status::GenericFailure,
|
||||
reason: format!("{}", error),
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
maybe_raw: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +121,7 @@ impl From<std::io::Error> for Error {
|
|||
Error {
|
||||
status: Status::GenericFailure,
|
||||
reason: format!("{}", error),
|
||||
#[cfg(all(feature = "tokio_rt", feature = "napi4"))]
|
||||
maybe_raw: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
description = "NodeJS N-API raw binding"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
include = ["src/**/*", "Cargo.toml", "build.rs", ".node-headers/**/*"]
|
||||
keywords = ["NodeJS", "FFI", "NAPI", "n-api"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
name = "napi-compat-mode-examples"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
name = "napi-examples"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
authors = ["LongYinan <lynweklm@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
name = "memory-testing"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
|
Loading…
Reference in a new issue