Skip to content

Modernize lints + CI #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 }}
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -182,38 +184,39 @@ 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:
needs: [documentation, bindings-windows, bindings-macos, cross]
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
4 changes: 2 additions & 2 deletions oo-bindgen/src/backend/c/cpp/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)")?;
Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/backend/c/ctype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
Pointer { inner }
}

impl<'a, T> CType for Pointer<'a, T>
impl<T> CType for Pointer<'_, T>
where
T: CType,
{
Expand Down
8 changes: 4 additions & 4 deletions oo-bindgen/src/backend/common/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/backend/dotnet/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions oo-bindgen/src/backend/dotnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand All @@ -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)?;

Expand All @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/backend/java/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/backend/java/jni/copy/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
12 changes: 9 additions & 3 deletions oo-bindgen/src/backend/java/jni/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down Expand Up @@ -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("}")?;

Expand All @@ -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()")
})?;

Expand All @@ -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;")
})
}
Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/cli/builders/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions oo-bindgen/src/cli/builders/dotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions oo-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion oo-bindgen/src/model/builder/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading