diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95430a98..dba69c85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust ${{ matrix.rust }} uses: dtolnay/rust-toolchain@master with: @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust ${{ matrix.rust }} uses: dtolnay/rust-toolchain@master with: @@ -49,14 +49,16 @@ jobs: run: cargo clippy -- -D warnings # Build documentation documentation: + env: + DoxygenVersion: 1.13.2 runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable - - name: Install doxygen 1.9.3 - run: wget -q https://www.doxygen.nl/files/doxygen-1.9.5.linux.bin.tar.gz -O- | sudo tar --strip-components=1 -C /usr -xz doxygen-1.9.5 + - name: Install doxygen ${{ env.DoxygenVersion }} + run: wget -q https://www.doxygen.nl/files/doxygen-${{ env.DoxygenVersion }}.linux.bin.tar.gz -O- | sudo tar --strip-components=1 -C /usr -xz doxygen-${{ env.DoxygenVersion }} - name: Build FFI and JNI shared libraries run: cargo build --release -p foo-ffi -p foo-ffi-java - name: C bindings @@ -74,7 +76,7 @@ jobs: cp -a tests/bindings/java/foo/target/apidocs ~/doc/java rm tests/bindings/c/generated/logo.png tests/bindings/c/generated/doxygen-awesome.css - name: Upload documentation - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: doc path: ~/doc @@ -91,7 +93,7 @@ jobs: test: false steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: @@ -106,9 +108,9 @@ jobs: Copy-Item -Path ./target/${{ matrix.target }}/release/foo_ffi.dll.lib -Destination ffi-modules/${{ matrix.target }} Copy-Item -Path ./target/${{ matrix.target }}/release/foo_ffi_java.dll -Destination ffi-modules/${{ matrix.target }} - name: Upload compiled FFI modules - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: ffi-modules + name: ffi-modules-${{ matrix.target }} path: ffi-modules - name: C Bindings Tests if: ${{ matrix.test }} @@ -132,7 +134,7 @@ jobs: target: x86_64-apple-darwin steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: @@ -145,9 +147,9 @@ jobs: cp ./target/release/libfoo_ffi.dylib ./ffi-modules/${{ matrix.target }} cp ./target/release/libfoo_ffi_java.dylib ./ffi-modules/${{ matrix.target }} - name: Upload compiled FFI modules - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: ffi-modules + name: ffi-modules-${{ matrix.target }} path: ffi-modules - name: .NET Bindings Tests run: cargo run --bin foo-bindings -- --dotnet @@ -167,7 +169,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: @@ -182,9 +184,9 @@ jobs: cp ./target/${{ matrix.target }}/release/libfoo_ffi.so ./ffi-modules/${{ matrix.target }} cp ./target/${{ matrix.target }}/release/libfoo_ffi_java.so ./ffi-modules/${{ matrix.target }} - name: Upload compiled FFI modules - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: ffi-modules + name: ffi-modules-${{matrix.target}} path: ffi-modules # Package all the generated bindings packaging: @@ -192,28 +194,29 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable - name: Download compiled FFI - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: - name: ffi-modules path: ffi-modules + pattern: ffi-modules-* + merge-multiple: true - name: Package all bindings run: cargo run --bin foo-bindings -- --package ./ffi-modules --options ./packaging.json - name: Upload C/C++ bindings - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: c-bindings path: tests/bindings/c/generated/* - name: Upload .NET bindings - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: dotnet-bindings path: tests/bindings/dotnet/nupkg/* - name: Upload Java bindings - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: java-bindings path: tests/bindings/java/foo/target/*.jar diff --git a/oo-bindgen/src/backend/c/cpp/implementation.rs b/oo-bindgen/src/backend/c/cpp/implementation.rs index d75a499e..0b479cbd 100644 --- a/oo-bindgen/src/backend/c/cpp/implementation.rs +++ b/oo-bindgen/src/backend/c/cpp/implementation.rs @@ -477,7 +477,7 @@ fn write_class_implementation( let cpp_name = handle.core_cpp_type(); // write constructor - for constructor in &handle.constructor { + if let Some(constructor) = &handle.constructor { f.writeln(&format!( "{}::{}({}) : self(fn::{}({}))", cpp_name, @@ -491,7 +491,7 @@ fn write_class_implementation( } // write the destructor - for destructor in &handle.destructor { + if let Some(destructor) = &handle.destructor { f.writeln(&format!("{cpp_name}::~{cpp_name}()"))?; blocked(f, |f| { f.writeln("if(self)")?; diff --git a/oo-bindgen/src/backend/c/ctype.rs b/oo-bindgen/src/backend/c/ctype.rs index ec77b31d..d4e14015 100644 --- a/oo-bindgen/src/backend/c/ctype.rs +++ b/oo-bindgen/src/backend/c/ctype.rs @@ -18,7 +18,7 @@ where Pointer { inner } } -impl<'a, T> CType for Pointer<'a, T> +impl CType for Pointer<'_, T> where T: CType, { diff --git a/oo-bindgen/src/backend/common/formatting.rs b/oo-bindgen/src/backend/common/formatting.rs index b7ac9ad7..30cc7c2c 100644 --- a/oo-bindgen/src/backend/common/formatting.rs +++ b/oo-bindgen/src/backend/common/formatting.rs @@ -70,7 +70,7 @@ impl<'a, 'b> PrefixPrinter<'a, 'b> { } } -impl<'a, 'b> Printer for PrefixPrinter<'a, 'b> { +impl Printer for PrefixPrinter<'_, '_> { fn write(&mut self, s: &str) -> FormattingResult<()> { self.inner.write(s) } @@ -93,7 +93,7 @@ impl<'a> IndentedPrinter<'a> { } } -impl<'a> Printer for IndentedPrinter<'a> { +impl Printer for IndentedPrinter<'_> { fn write(&mut self, s: &str) -> FormattingResult<()> { self.inner.write(s) } @@ -115,7 +115,7 @@ impl<'a> CommentedPrinter<'a> { } } -impl<'a> Printer for CommentedPrinter<'a> { +impl Printer for CommentedPrinter<'_> { fn write(&mut self, s: &str) -> FormattingResult<()> { self.inner.write(s) } @@ -137,7 +137,7 @@ impl<'a> DoxygenPrinter<'a> { } } -impl<'a> Printer for DoxygenPrinter<'a> { +impl Printer for DoxygenPrinter<'_> { fn write(&mut self, s: &str) -> FormattingResult<()> { self.inner.write(s) } diff --git a/oo-bindgen/src/backend/dotnet/formatting.rs b/oo-bindgen/src/backend/dotnet/formatting.rs index 3ebf724a..b2244df7 100644 --- a/oo-bindgen/src/backend/dotnet/formatting.rs +++ b/oo-bindgen/src/backend/dotnet/formatting.rs @@ -10,7 +10,7 @@ impl<'a> DocumentationPrinter<'a> { } } -impl<'a> Printer for DocumentationPrinter<'a> { +impl Printer for DocumentationPrinter<'_> { fn write(&mut self, s: &str) -> FormattingResult<()> { self.inner.write(s) } diff --git a/oo-bindgen/src/backend/dotnet/mod.rs b/oo-bindgen/src/backend/dotnet/mod.rs index 38adb742..553b0f07 100644 --- a/oo-bindgen/src/backend/dotnet/mod.rs +++ b/oo-bindgen/src/backend/dotnet/mod.rs @@ -489,7 +489,7 @@ fn generate_interfaces(lib: &Library, config: &DotnetBindgenConfig) -> Formattin for interface in lib.interfaces() { // Open file let mut filename = config.output_dir.clone(); - filename.push(&format!("I{}", interface.name().camel_case())); + filename.push(format!("I{}", interface.name().camel_case())); filename.set_extension("cs"); let mut f = FilePrinter::new(filename)?; @@ -503,7 +503,7 @@ fn generate_iterator_helpers(lib: &Library, config: &DotnetBindgenConfig) -> For for iter in lib.iterators() { // Open file let mut filename = config.output_dir.clone(); - filename.push(&format!("{}Helpers", iter.name().camel_case())); + filename.push(format!("{}Helpers", iter.name().camel_case())); filename.set_extension("cs"); let mut f = FilePrinter::new(filename)?; @@ -520,7 +520,7 @@ fn generate_collection_helpers( for coll in lib.collections() { // Open file let mut filename = config.output_dir.clone(); - filename.push(&format!("{}Helpers", coll.name().camel_case())); + filename.push(format!("{}Helpers", coll.name().camel_case())); filename.set_extension("cs"); let mut f = FilePrinter::new(filename)?; diff --git a/oo-bindgen/src/backend/java/api/mod.rs b/oo-bindgen/src/backend/java/api/mod.rs index 59cdd629..138bb54b 100644 --- a/oo-bindgen/src/backend/java/api/mod.rs +++ b/oo-bindgen/src/backend/java/api/mod.rs @@ -40,7 +40,7 @@ impl JavaBindgenConfig { for dir in self.group_id.split('.') { result.push(dir); } - result.push(&lib.settings.name.kebab_case()); + result.push(lib.settings.name.kebab_case()); result } diff --git a/oo-bindgen/src/backend/java/jni/conversion/convertible_to_rust.rs b/oo-bindgen/src/backend/java/jni/conversion/convertible_to_rust.rs index 4537239e..7cdcb90c 100644 --- a/oo-bindgen/src/backend/java/jni/conversion/convertible_to_rust.rs +++ b/oo-bindgen/src/backend/java/jni/conversion/convertible_to_rust.rs @@ -5,11 +5,11 @@ use crate::model::*; /// Conversion happens in two phases: /// /// 1) `to_rust` is called to do a primary conversion from the JNI type to the Rust type. If a -/// conversion is required, it will frequently be used to shadow the variable. +/// conversion is required, it will frequently be used to shadow the variable. /// /// 2) `call_site` is called to do a secondary conversion to extract the final type passed to -/// the native function. This is generally used to get an inner type from some RAII type, e.g. -/// JavaString. +/// the native function. This is generally used to get an inner type from some RAII type, e.g. +/// JavaString. /// /// Conversions assume that there are two variables in scope: /// diff --git a/oo-bindgen/src/backend/java/jni/copy/util.rs b/oo-bindgen/src/backend/java/jni/copy/util.rs index 41e87578..bad78654 100644 --- a/oo-bindgen/src/backend/java/jni/copy/util.rs +++ b/oo-bindgen/src/backend/java/jni/copy/util.rs @@ -9,7 +9,7 @@ impl<'a> LocalFrameGuard<'a> { } } -impl<'a> Drop for LocalFrameGuard<'a> { +impl Drop for LocalFrameGuard<'_> { fn drop(&mut self) { let _ = self.env.pop_local_frame(jni::objects::JObject::null()); } diff --git a/oo-bindgen/src/backend/java/jni/mod.rs b/oo-bindgen/src/backend/java/jni/mod.rs index fe697a98..20e6c385 100644 --- a/oo-bindgen/src/backend/java/jni/mod.rs +++ b/oo-bindgen/src/backend/java/jni/mod.rs @@ -20,7 +20,7 @@ pub struct JniBindgenConfig<'a> { pub ffi_name: &'a str, } -impl<'a> JniBindgenConfig<'a> { +impl JniBindgenConfig<'_> { fn java_signature_path(&self, libname: &str) -> String { let mut result = self.group_id.replace('.', "/"); result.push('/'); @@ -147,6 +147,10 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> { f.newline()?; f.writeln("pub(crate) fn get_cache<'a>() -> &'a JCache {")?; + indented(f, |f| { + f.writeln("// safety: this is only called after initialization / JVM load") + })?; + indented(f, |f| f.writeln("#[allow(static_mut_refs)]"))?; indented(f, |f| f.writeln("unsafe { JCACHE.as_ref().unwrap() }"))?; f.writeln("}")?; @@ -158,7 +162,8 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> { blocked(f, |f| { f.writeln("let vm = unsafe { jni::JavaVM::from_raw(vm).unwrap() };")?; f.writeln("let jcache = JCache::init(vm);")?; - f.writeln("unsafe { JCACHE.replace(jcache) };")?; + f.writeln("// safety: this is only called during library loading")?; + f.writeln("unsafe { JCACHE = Some(jcache); };")?; f.writeln("jni::JNIVersion::V8.into()") })?; @@ -168,7 +173,8 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> { f.writeln("#[no_mangle]")?; f.writeln("pub extern \"C\" fn JNI_OnUnload(_vm: *mut jni::sys::JavaVM, _: *mut std::ffi::c_void) -> jni::sys::jint")?; blocked(f, |f| { - f.writeln("unsafe { JCACHE.take().unwrap(); }")?; + f.writeln("// safety: this is only called during library unloading / JVM shutdown")?; + f.writeln("unsafe { JCACHE = None; }")?; f.writeln("return 0;") }) } diff --git a/oo-bindgen/src/cli/builders/c.rs b/oo-bindgen/src/cli/builders/c.rs index 46251939..0a372c43 100644 --- a/oo-bindgen/src/cli/builders/c.rs +++ b/oo-bindgen/src/cli/builders/c.rs @@ -79,7 +79,7 @@ impl BindingBuilder for CBindingBuilder { fn test(&mut self) { // Run unit tests let result = Command::new("ctest") - .current_dir(&self.build_dir()) + .current_dir(self.build_dir()) .args([".", "-C", "Debug"]) .status() .unwrap(); diff --git a/oo-bindgen/src/cli/builders/dotnet.rs b/oo-bindgen/src/cli/builders/dotnet.rs index 85ba4b90..dcb20a99 100644 --- a/oo-bindgen/src/cli/builders/dotnet.rs +++ b/oo-bindgen/src/cli/builders/dotnet.rs @@ -66,7 +66,7 @@ impl BindingBuilder for DotnetBindingBuilder { fn build(&mut self) { let result = Command::new("dotnet") - .current_dir(&self.output_dir()) + .current_dir(self.output_dir()) .arg("build") .arg("--configuration") .arg("Release") @@ -78,7 +78,7 @@ impl BindingBuilder for DotnetBindingBuilder { fn test(&mut self) { // Run unit tests let result = Command::new("dotnet") - .current_dir(&self.output_dir()) + .current_dir(self.output_dir()) .arg("test") .arg("--configuration") .arg("Release") @@ -90,7 +90,7 @@ impl BindingBuilder for DotnetBindingBuilder { fn package(&mut self) { // Produce a nupkg let result = Command::new("dotnet") - .current_dir(&self.output_dir()) + .current_dir(self.output_dir()) .arg("pack") .arg("--configuration") .arg("Release") diff --git a/oo-bindgen/src/lib.rs b/oo-bindgen/src/lib.rs index 87e92d5d..392585ce 100644 --- a/oo-bindgen/src/lib.rs +++ b/oo-bindgen/src/lib.rs @@ -9,8 +9,6 @@ overflowing_literals, patterns_in_fns_without_body, pub_use_of_private_extern_crate, unknown_crate_types, -order_dependent_trait_objects, - improper_ctypes, late_bound_lifetime_arguments, non_camel_case_types, diff --git a/oo-bindgen/src/model/builder/library.rs b/oo-bindgen/src/model/builder/library.rs index c9f1eb9c..19e6232c 100644 --- a/oo-bindgen/src/model/builder/library.rs +++ b/oo-bindgen/src/model/builder/library.rs @@ -282,7 +282,7 @@ impl LibraryBuilder { /// Define a structure that can be used in any context. /// - /// Backends will generate bi-directional conversion routines + /// Backends will generate bidirectional conversion routines /// for this type of struct. pub fn define_universal_struct( &mut self, diff --git a/oo-bindgen/src/model/doc.rs b/oo-bindgen/src/model/doc.rs index 3fc15d7e..f2474324 100644 --- a/oo-bindgen/src/model/doc.rs +++ b/oo-bindgen/src/model/doc.rs @@ -650,13 +650,12 @@ impl TryFrom<&str> for DocStringElement { #[cfg(test)] mod tests { - use std::convert::TryInto; use super::*; #[test] fn parse_param_reference() { - let doc: DocString = "This is a {param:foo} test.".try_into().unwrap(); + let doc: DocString = "This is a {param:foo} test.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -670,7 +669,7 @@ mod tests { #[test] fn parse_class_reference() { - let doc: DocString = "This is a {class:MyClass} test.".try_into().unwrap(); + let doc: DocString = "This is a {class:MyClass} test.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -684,7 +683,7 @@ mod tests { #[test] fn parse_class_reference_at_the_end() { - let doc: DocString = "This is a test {class:MyClass2}".try_into().unwrap(); + let doc: DocString = "This is a test {class:MyClass2}".into(); assert_eq!( [ DocStringElement::Text("This is a test ".to_owned()), @@ -697,9 +696,7 @@ mod tests { #[test] fn parse_class_method() { - let doc: DocString = "This is a {class:MyClass.do_something()} method." - .try_into() - .unwrap(); + let doc: DocString = "This is a {class:MyClass.do_something()} method.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -716,7 +713,7 @@ mod tests { #[test] fn parse_struct() { - let doc: DocString = "This is a {struct:MyStruct} struct.".try_into().unwrap(); + let doc: DocString = "This is a {struct:MyStruct} struct.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -730,9 +727,7 @@ mod tests { #[test] fn parse_struct_element() { - let doc: DocString = "This is a {struct:MyStruct.foo} struct element." - .try_into() - .unwrap(); + let doc: DocString = "This is a {struct:MyStruct.foo} struct element.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -749,7 +744,7 @@ mod tests { #[test] fn parse_enum() { - let doc: DocString = "This is a {enum:MyEnum} enum.".try_into().unwrap(); + let doc: DocString = "This is a {enum:MyEnum} enum.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -763,9 +758,7 @@ mod tests { #[test] fn parse_enum_element() { - let doc: DocString = "This is a {enum:MyEnum.foo} enum variant." - .try_into() - .unwrap(); + let doc: DocString = "This is a {enum:MyEnum.foo} enum variant.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -782,9 +775,7 @@ mod tests { #[test] fn parse_interface() { - let doc: DocString = "This is a {interface:Interface} interface." - .try_into() - .unwrap(); + let doc: DocString = "This is a {interface:Interface} interface.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -798,9 +789,8 @@ mod tests { #[test] fn parse_interface_method() { - let doc: DocString = "This is a {interface:Interface.foo()} interface method." - .try_into() - .unwrap(); + let doc: DocString = + "This is a {interface:Interface.foo()} interface method.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -817,7 +807,7 @@ mod tests { #[test] fn parse_null() { - let doc: DocString = "This is a {null} null.".try_into().unwrap(); + let doc: DocString = "This is a {null} null.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), @@ -831,7 +821,7 @@ mod tests { #[test] fn parse_iterator() { - let doc: DocString = "This is a {iterator} iterator.".try_into().unwrap(); + let doc: DocString = "This is a {iterator} iterator.".into(); assert_eq!( [ DocStringElement::Text("This is a ".to_owned()), diff --git a/tests/foo-ffi-java/src/lib.rs b/tests/foo-ffi-java/src/lib.rs index 9d04bde2..0001877a 100644 --- a/tests/foo-ffi-java/src/lib.rs +++ b/tests/foo-ffi-java/src/lib.rs @@ -5,6 +5,7 @@ clippy::redundant_closure, clippy::needless_borrow, clippy::needless_return, + clippy::needless_lifetimes, clippy::not_unsafe_ptr_arg_deref, unused_variables, dead_code diff --git a/tests/foo-ffi/src/lib.rs b/tests/foo-ffi/src/lib.rs index e120bdfd..0788174e 100644 --- a/tests/foo-ffi/src/lib.rs +++ b/tests/foo-ffi/src/lib.rs @@ -37,6 +37,7 @@ mod thread_class; mod universal; #[allow(clippy::extra_unused_lifetimes)] +#[allow(clippy::needless_lifetimes)] pub mod ffi; static VERSION: &str = concat!("1.2.3", "\0");