Skip to content

Commit dfed5a9

Browse files
authored
Modernize lints + CI (#129)
1 parent 3f1472e commit dfed5a9

File tree

17 files changed

+69
-70
lines changed

17 files changed

+69
-70
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ${{ matrix.os }}
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424
- name: Install Rust ${{ matrix.rust }}
2525
uses: dtolnay/rust-toolchain@master
2626
with:
@@ -37,7 +37,7 @@ jobs:
3737
runs-on: ubuntu-latest
3838
steps:
3939
- name: Checkout
40-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
4141
- name: Install Rust ${{ matrix.rust }}
4242
uses: dtolnay/rust-toolchain@master
4343
with:
@@ -49,14 +49,16 @@ jobs:
4949
run: cargo clippy -- -D warnings
5050
# Build documentation
5151
documentation:
52+
env:
53+
DoxygenVersion: 1.13.2
5254
runs-on: ubuntu-latest
5355
steps:
5456
- name: Checkout
55-
uses: actions/checkout@v3
57+
uses: actions/checkout@v4
5658
- name: Install Rust
5759
uses: dtolnay/rust-toolchain@stable
58-
- name: Install doxygen 1.9.3
59-
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
60+
- name: Install doxygen ${{ env.DoxygenVersion }}
61+
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 }}
6062
- name: Build FFI and JNI shared libraries
6163
run: cargo build --release -p foo-ffi -p foo-ffi-java
6264
- name: C bindings
@@ -74,7 +76,7 @@ jobs:
7476
cp -a tests/bindings/java/foo/target/apidocs ~/doc/java
7577
rm tests/bindings/c/generated/logo.png tests/bindings/c/generated/doxygen-awesome.css
7678
- name: Upload documentation
77-
uses: actions/upload-artifact@v2
79+
uses: actions/upload-artifact@v4
7880
with:
7981
name: doc
8082
path: ~/doc
@@ -91,7 +93,7 @@ jobs:
9193
test: false
9294
steps:
9395
- name: Checkout
94-
uses: actions/checkout@v3
96+
uses: actions/checkout@v4
9597
- name: Install Rust
9698
uses: dtolnay/rust-toolchain@stable
9799
with:
@@ -106,9 +108,9 @@ jobs:
106108
Copy-Item -Path ./target/${{ matrix.target }}/release/foo_ffi.dll.lib -Destination ffi-modules/${{ matrix.target }}
107109
Copy-Item -Path ./target/${{ matrix.target }}/release/foo_ffi_java.dll -Destination ffi-modules/${{ matrix.target }}
108110
- name: Upload compiled FFI modules
109-
uses: actions/upload-artifact@v2
111+
uses: actions/upload-artifact@v4
110112
with:
111-
name: ffi-modules
113+
name: ffi-modules-${{ matrix.target }}
112114
path: ffi-modules
113115
- name: C Bindings Tests
114116
if: ${{ matrix.test }}
@@ -132,7 +134,7 @@ jobs:
132134
target: x86_64-apple-darwin
133135
steps:
134136
- name: Checkout
135-
uses: actions/checkout@v3
137+
uses: actions/checkout@v4
136138
- name: Install Rust
137139
uses: dtolnay/rust-toolchain@stable
138140
with:
@@ -145,9 +147,9 @@ jobs:
145147
cp ./target/release/libfoo_ffi.dylib ./ffi-modules/${{ matrix.target }}
146148
cp ./target/release/libfoo_ffi_java.dylib ./ffi-modules/${{ matrix.target }}
147149
- name: Upload compiled FFI modules
148-
uses: actions/upload-artifact@v2
150+
uses: actions/upload-artifact@v4
149151
with:
150-
name: ffi-modules
152+
name: ffi-modules-${{ matrix.target }}
151153
path: ffi-modules
152154
- name: .NET Bindings Tests
153155
run: cargo run --bin foo-bindings -- --dotnet
@@ -167,7 +169,7 @@ jobs:
167169
runs-on: ubuntu-latest
168170
steps:
169171
- name: Checkout
170-
uses: actions/checkout@v3
172+
uses: actions/checkout@v4
171173
- name: Install Rust
172174
uses: dtolnay/rust-toolchain@stable
173175
with:
@@ -182,38 +184,39 @@ jobs:
182184
cp ./target/${{ matrix.target }}/release/libfoo_ffi.so ./ffi-modules/${{ matrix.target }}
183185
cp ./target/${{ matrix.target }}/release/libfoo_ffi_java.so ./ffi-modules/${{ matrix.target }}
184186
- name: Upload compiled FFI modules
185-
uses: actions/upload-artifact@v2
187+
uses: actions/upload-artifact@v4
186188
with:
187-
name: ffi-modules
189+
name: ffi-modules-${{matrix.target}}
188190
path: ffi-modules
189191
# Package all the generated bindings
190192
packaging:
191193
needs: [documentation, bindings-windows, bindings-macos, cross]
192194
runs-on: ubuntu-latest
193195
steps:
194196
- name: Checkout
195-
uses: actions/checkout@v3
197+
uses: actions/checkout@v4
196198
- name: Install Rust
197199
uses: dtolnay/rust-toolchain@stable
198200
- name: Download compiled FFI
199-
uses: actions/download-artifact@v2
201+
uses: actions/download-artifact@v4
200202
with:
201-
name: ffi-modules
202203
path: ffi-modules
204+
pattern: ffi-modules-*
205+
merge-multiple: true
203206
- name: Package all bindings
204207
run: cargo run --bin foo-bindings -- --package ./ffi-modules --options ./packaging.json
205208
- name: Upload C/C++ bindings
206-
uses: actions/upload-artifact@v2
209+
uses: actions/upload-artifact@v4
207210
with:
208211
name: c-bindings
209212
path: tests/bindings/c/generated/*
210213
- name: Upload .NET bindings
211-
uses: actions/upload-artifact@v2
214+
uses: actions/upload-artifact@v4
212215
with:
213216
name: dotnet-bindings
214217
path: tests/bindings/dotnet/nupkg/*
215218
- name: Upload Java bindings
216-
uses: actions/upload-artifact@v2
219+
uses: actions/upload-artifact@v4
217220
with:
218221
name: java-bindings
219222
path: tests/bindings/java/foo/target/*.jar

oo-bindgen/src/backend/c/cpp/implementation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ fn write_class_implementation(
477477
let cpp_name = handle.core_cpp_type();
478478

479479
// write constructor
480-
for constructor in &handle.constructor {
480+
if let Some(constructor) = &handle.constructor {
481481
f.writeln(&format!(
482482
"{}::{}({}) : self(fn::{}({}))",
483483
cpp_name,
@@ -491,7 +491,7 @@ fn write_class_implementation(
491491
}
492492

493493
// write the destructor
494-
for destructor in &handle.destructor {
494+
if let Some(destructor) = &handle.destructor {
495495
f.writeln(&format!("{cpp_name}::~{cpp_name}()"))?;
496496
blocked(f, |f| {
497497
f.writeln("if(self)")?;

oo-bindgen/src/backend/c/ctype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ where
1818
Pointer { inner }
1919
}
2020

21-
impl<'a, T> CType for Pointer<'a, T>
21+
impl<T> CType for Pointer<'_, T>
2222
where
2323
T: CType,
2424
{

oo-bindgen/src/backend/common/formatting.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a, 'b> PrefixPrinter<'a, 'b> {
7070
}
7171
}
7272

73-
impl<'a, 'b> Printer for PrefixPrinter<'a, 'b> {
73+
impl Printer for PrefixPrinter<'_, '_> {
7474
fn write(&mut self, s: &str) -> FormattingResult<()> {
7575
self.inner.write(s)
7676
}
@@ -93,7 +93,7 @@ impl<'a> IndentedPrinter<'a> {
9393
}
9494
}
9595

96-
impl<'a> Printer for IndentedPrinter<'a> {
96+
impl Printer for IndentedPrinter<'_> {
9797
fn write(&mut self, s: &str) -> FormattingResult<()> {
9898
self.inner.write(s)
9999
}
@@ -115,7 +115,7 @@ impl<'a> CommentedPrinter<'a> {
115115
}
116116
}
117117

118-
impl<'a> Printer for CommentedPrinter<'a> {
118+
impl Printer for CommentedPrinter<'_> {
119119
fn write(&mut self, s: &str) -> FormattingResult<()> {
120120
self.inner.write(s)
121121
}
@@ -137,7 +137,7 @@ impl<'a> DoxygenPrinter<'a> {
137137
}
138138
}
139139

140-
impl<'a> Printer for DoxygenPrinter<'a> {
140+
impl Printer for DoxygenPrinter<'_> {
141141
fn write(&mut self, s: &str) -> FormattingResult<()> {
142142
self.inner.write(s)
143143
}

oo-bindgen/src/backend/dotnet/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl<'a> DocumentationPrinter<'a> {
1010
}
1111
}
1212

13-
impl<'a> Printer for DocumentationPrinter<'a> {
13+
impl Printer for DocumentationPrinter<'_> {
1414
fn write(&mut self, s: &str) -> FormattingResult<()> {
1515
self.inner.write(s)
1616
}

oo-bindgen/src/backend/dotnet/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ fn generate_interfaces(lib: &Library, config: &DotnetBindgenConfig) -> Formattin
489489
for interface in lib.interfaces() {
490490
// Open file
491491
let mut filename = config.output_dir.clone();
492-
filename.push(&format!("I{}", interface.name().camel_case()));
492+
filename.push(format!("I{}", interface.name().camel_case()));
493493
filename.set_extension("cs");
494494
let mut f = FilePrinter::new(filename)?;
495495

@@ -503,7 +503,7 @@ fn generate_iterator_helpers(lib: &Library, config: &DotnetBindgenConfig) -> For
503503
for iter in lib.iterators() {
504504
// Open file
505505
let mut filename = config.output_dir.clone();
506-
filename.push(&format!("{}Helpers", iter.name().camel_case()));
506+
filename.push(format!("{}Helpers", iter.name().camel_case()));
507507
filename.set_extension("cs");
508508
let mut f = FilePrinter::new(filename)?;
509509

@@ -520,7 +520,7 @@ fn generate_collection_helpers(
520520
for coll in lib.collections() {
521521
// Open file
522522
let mut filename = config.output_dir.clone();
523-
filename.push(&format!("{}Helpers", coll.name().camel_case()));
523+
filename.push(format!("{}Helpers", coll.name().camel_case()));
524524
filename.set_extension("cs");
525525
let mut f = FilePrinter::new(filename)?;
526526

oo-bindgen/src/backend/java/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl JavaBindgenConfig {
4040
for dir in self.group_id.split('.') {
4141
result.push(dir);
4242
}
43-
result.push(&lib.settings.name.kebab_case());
43+
result.push(lib.settings.name.kebab_case());
4444
result
4545
}
4646

oo-bindgen/src/backend/java/jni/conversion/convertible_to_rust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::model::*;
55
/// Conversion happens in two phases:
66
///
77
/// 1) `to_rust` is called to do a primary conversion from the JNI type to the Rust type. If a
8-
/// conversion is required, it will frequently be used to shadow the variable.
8+
/// conversion is required, it will frequently be used to shadow the variable.
99
///
1010
/// 2) `call_site` is called to do a secondary conversion to extract the final type passed to
11-
/// the native function. This is generally used to get an inner type from some RAII type, e.g.
12-
/// JavaString.
11+
/// the native function. This is generally used to get an inner type from some RAII type, e.g.
12+
/// JavaString.
1313
///
1414
/// Conversions assume that there are two variables in scope:
1515
///

oo-bindgen/src/backend/java/jni/copy/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl<'a> LocalFrameGuard<'a> {
99
}
1010
}
1111

12-
impl<'a> Drop for LocalFrameGuard<'a> {
12+
impl Drop for LocalFrameGuard<'_> {
1313
fn drop(&mut self) {
1414
let _ = self.env.pop_local_frame(jni::objects::JObject::null());
1515
}

oo-bindgen/src/backend/java/jni/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct JniBindgenConfig<'a> {
2020
pub ffi_name: &'a str,
2121
}
2222

23-
impl<'a> JniBindgenConfig<'a> {
23+
impl JniBindgenConfig<'_> {
2424
fn java_signature_path(&self, libname: &str) -> String {
2525
let mut result = self.group_id.replace('.', "/");
2626
result.push('/');
@@ -147,6 +147,10 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> {
147147
f.newline()?;
148148

149149
f.writeln("pub(crate) fn get_cache<'a>() -> &'a JCache {")?;
150+
indented(f, |f| {
151+
f.writeln("// safety: this is only called after initialization / JVM load")
152+
})?;
153+
indented(f, |f| f.writeln("#[allow(static_mut_refs)]"))?;
150154
indented(f, |f| f.writeln("unsafe { JCACHE.as_ref().unwrap() }"))?;
151155
f.writeln("}")?;
152156

@@ -158,7 +162,8 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> {
158162
blocked(f, |f| {
159163
f.writeln("let vm = unsafe { jni::JavaVM::from_raw(vm).unwrap() };")?;
160164
f.writeln("let jcache = JCache::init(vm);")?;
161-
f.writeln("unsafe { JCACHE.replace(jcache) };")?;
165+
f.writeln("// safety: this is only called during library loading")?;
166+
f.writeln("unsafe { JCACHE = Some(jcache); };")?;
162167
f.writeln("jni::JNIVersion::V8.into()")
163168
})?;
164169

@@ -168,7 +173,8 @@ fn generate_cache(f: &mut dyn Printer) -> FormattingResult<()> {
168173
f.writeln("#[no_mangle]")?;
169174
f.writeln("pub extern \"C\" fn JNI_OnUnload(_vm: *mut jni::sys::JavaVM, _: *mut std::ffi::c_void) -> jni::sys::jint")?;
170175
blocked(f, |f| {
171-
f.writeln("unsafe { JCACHE.take().unwrap(); }")?;
176+
f.writeln("// safety: this is only called during library unloading / JVM shutdown")?;
177+
f.writeln("unsafe { JCACHE = None; }")?;
172178
f.writeln("return 0;")
173179
})
174180
}

0 commit comments

Comments
 (0)