From 120cc8d44f10ccb1cd8f9bb3b3e16d3d4886b9ec Mon Sep 17 00:00:00 2001 From: Kwangsoo Yeo Date: Mon, 16 Oct 2023 15:58:55 -0700 Subject: [PATCH] update rust --- .github/workflows/rust-codestyle.yml | 8 ++++++++ .github/workflows/rust-demos.yml | 8 ++++++++ binding/rust/src/rhino.rs | 18 ++++++++++-------- demo/rust/filedemo/Cargo.lock | 4 +--- demo/rust/filedemo/Cargo.toml | 2 +- demo/rust/micdemo/Cargo.lock | 4 +--- demo/rust/micdemo/Cargo.toml | 2 +- resources/.lint/spell-check/dict.txt | 1 + 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/rust-codestyle.yml b/.github/workflows/rust-codestyle.yml index bcfa721a2..1f79c5465 100644 --- a/.github/workflows/rust-codestyle.yml +++ b/.github/workflows/rust-codestyle.yml @@ -44,6 +44,10 @@ jobs: toolchain: stable override: true + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust + - name: Run clippy run: cargo clippy -- -D warnings working-directory: binding/rust @@ -85,6 +89,10 @@ jobs: profile: minimal toolchain: stable override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Run clippy run: cargo clippy -- -D warnings diff --git a/.github/workflows/rust-demos.yml b/.github/workflows/rust-demos.yml index f783001fc..8d83500aa 100644 --- a/.github/workflows/rust-demos.yml +++ b/.github/workflows/rust-demos.yml @@ -50,6 +50,10 @@ jobs: profile: minimal toolchain: stable override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Rust build micdemo run: cargo build --verbose @@ -89,6 +93,10 @@ jobs: with: toolchain: nightly override: true + + - name: Rust build binding + run: bash copy.sh && cargo build --verbose + working-directory: binding/rust - name: Rust build micdemo run: cargo build --verbose diff --git a/binding/rust/src/rhino.rs b/binding/rust/src/rhino.rs index b90daec41..5954c5682 100644 --- a/binding/rust/src/rhino.rs +++ b/binding/rust/src/rhino.rs @@ -27,7 +27,11 @@ use libloading::os::unix::Symbol as RawSymbol; use libloading::os::windows::Symbol as RawSymbol; #[repr(C)] -struct CRhino {} +struct CRhino { + // Fields suggested by the Rustonomicon: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs + _data: [u8; 0], + _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, +} #[repr(C)] #[derive(PartialEq, Clone, Debug)] @@ -87,6 +91,7 @@ type PvGetErrorStackFn = type PvFreeErrorStackFn = unsafe extern "C" fn(message_stack: *mut *mut c_char); type PvSetSdkFn = unsafe extern "C" fn(sdk: *const c_char); + #[derive(PartialEq, Clone, Debug)] pub enum RhinoErrorStatus { LibraryError(PvStatus), @@ -129,16 +134,13 @@ impl std::fmt::Display for RhinoError { let mut message_string = String::new(); message_string.push_str(&format!("{} with status '{:?}'", self.message, self.status)); - if self.message_stack.len() == 0 { - message_string.push_str("."); - write!(f, "{}", message_string) - } else { - message_string.push_str(":"); + if !self.message_stack.is_empty() { + message_string.push(':'); for x in 0..self.message_stack.len() { message_string.push_str(&format!(" [{}] {}\n", x, self.message_stack[x])) - } - write!(f, "{}", message_string) + }; } + write!(f, "{}", message_string) } } diff --git a/demo/rust/filedemo/Cargo.lock b/demo/rust/filedemo/Cargo.lock index 12c7fc65b..01526a17a 100644 --- a/demo/rust/filedemo/Cargo.lock +++ b/demo/rust/filedemo/Cargo.lock @@ -306,9 +306,7 @@ dependencies = [ [[package]] name = "pv_rhino" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83df0b253a4ee96e3428394f2f7a4769505c7e0bd91e1b4379141a289494c53" +version = "3.0.0" dependencies = [ "libc", "libloading", diff --git a/demo/rust/filedemo/Cargo.toml b/demo/rust/filedemo/Cargo.toml index 09246c612..d54470e63 100644 --- a/demo/rust/filedemo/Cargo.toml +++ b/demo/rust/filedemo/Cargo.toml @@ -8,4 +8,4 @@ chrono = "0.4.23" clap = "3.2.3" hound = "3.4.0" itertools = "0.10.3" -pv_rhino = "=2.2.1" +pv_rhino = { path = "../../../binding/rust" } diff --git a/demo/rust/micdemo/Cargo.lock b/demo/rust/micdemo/Cargo.lock index 3535b42e9..3780fa934 100644 --- a/demo/rust/micdemo/Cargo.lock +++ b/demo/rust/micdemo/Cargo.lock @@ -277,9 +277,7 @@ dependencies = [ [[package]] name = "pv_rhino" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83df0b253a4ee96e3428394f2f7a4769505c7e0bd91e1b4379141a289494c53" +version = "3.0.0" dependencies = [ "libc", "libloading 0.7.4", diff --git a/demo/rust/micdemo/Cargo.toml b/demo/rust/micdemo/Cargo.toml index 54b91a702..2f55e1c4f 100644 --- a/demo/rust/micdemo/Cargo.toml +++ b/demo/rust/micdemo/Cargo.toml @@ -10,4 +10,4 @@ ctrlc = "3.2.2" hound = "3.4.0" itertools = "0.10.3" pv_recorder = "=1.2.1" -pv_rhino = "=2.2.1" +pv_rhino = { path = "../../../binding/rust" } diff --git a/resources/.lint/spell-check/dict.txt b/resources/.lint/spell-check/dict.txt index e207a36b8..4931cd809 100644 --- a/resources/.lint/spell-check/dict.txt +++ b/resources/.lint/spell-check/dict.txt @@ -106,6 +106,7 @@ rhinomicdemo rhinotestapp rodio rosado +Rustonomicon RTLD seumateu shōmei