From 748c7672be3e1c8d43b94dcb73589ab1c1f7b541 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 10 Dec 2022 06:52:19 -0600 Subject: [PATCH] rearranging rust files --- CMakeLists.txt | 2 +- flake.nix | 6 ++- src/rust/Cargo.toml | 24 ----------- src/rust/build.rs | 6 --- src/rust/src/cxxqt_object.rs | 57 ------------------------- src/rust/src/lib.rs | 17 -------- src/rust/src/service_thing.rs | 80 ----------------------------------- 7 files changed, 6 insertions(+), 186 deletions(-) delete mode 100644 src/rust/Cargo.toml delete mode 100644 src/rust/build.rs delete mode 100644 src/rust/src/cxxqt_object.rs delete mode 100644 src/rust/src/lib.rs delete mode 100644 src/rust/src/service_thing.rs diff --git a/CMakeLists.txt b/CMakeLists.txt index 153a945..87642bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ add_subdirectory(src) set(CRATE libre-presenter) # Corrosion creates a CMake target with the same name as the crate. -corrosion_import_crate(MANIFEST_PATH src/rust/Cargo.toml CRATES ${CRATE}) +corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES ${CRATE}) # The Rust library's build script needs to be told where to output the # generated headers so CMake can find them. To do this, tell Corrosion diff --git a/flake.nix b/flake.nix index b7d764b..782fb65 100644 --- a/flake.nix +++ b/flake.nix @@ -23,8 +23,12 @@ in rec { + # packages = { + # crate = (rustPkgs.workspace.qml-minimal { }).bin; + # default = packages.crate; + # }; devShell = import ./shell.nix { inherit pkgs; }; - defaultPackage = pkgs.libsForQt5.callPackage ./default.nix {}; + defaultPackage = pkgs.libsForQt5.callPackage ./default.nix { inherit rustPkgs; }; } ); } diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml deleted file mode 100644 index 4c80df4..0000000 --- a/src/rust/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "libre-presenter" -version = "0.1.0" -edition = "2021" -authors = [ - "Chris Cochrun " -] -license = "GPL-3.0" - -# This will instruct Cargo to create a static -# library which CMake can link against -[lib] -crate-type = ["staticlib"] - -[dependencies] -cxx = "1.0.83" -cxx-qt = "0.4.1" -cxx-qt-lib = "0.4.1" - -# cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module -# and compiles it together with the Rust static library -[build-dependencies] -cxx-qt-build = "0.4.1" - diff --git a/src/rust/build.rs b/src/rust/build.rs deleted file mode 100644 index 6d2b652..0000000 --- a/src/rust/build.rs +++ /dev/null @@ -1,6 +0,0 @@ -use cxx_qt_build::CxxQtBuilder; - -fn main() { - CxxQtBuilder::new().file("src/cxxqt_object.rs").build(); - CxxQtBuilder::new().file("src/service_thing.rs").build(); -} diff --git a/src/rust/src/cxxqt_object.rs b/src/rust/src/cxxqt_object.rs deleted file mode 100644 index 0062145..0000000 --- a/src/rust/src/cxxqt_object.rs +++ /dev/null @@ -1,57 +0,0 @@ -#[cxx_qt::bridge] -mod my_object { - use cxx_qt_lib::QVariantValue; - - unsafe extern "C++" { - include!("cxx-qt-lib/qstring.h"); - type QString = cxx_qt_lib::QString; - include!("cxx-qt-lib/qvariant.h"); - type QVariant = cxx_qt_lib::QVariant; - } - - #[cxx_qt::qobject] - pub struct MyObject { - #[qproperty] - number: i32, - #[qproperty] - string: QString, - } - - impl Default for MyObject { - fn default() -> Self { - Self { - number: 0, - string: QString::from(""), - } - } - } - - impl qobject::MyObject { - #[qinvokable] - pub fn increment_number(self: Pin<&mut Self>) { - let previous = *self.as_ref().number(); - self.set_number(previous + 1); - } - - #[qinvokable] - pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) { - println!( - "Hi from Rust! String is '{}' and number is {}", - string, number - ); - println!("length is: {}", string.to_string().len()); - let mut nstr: String = string.to_string(); - nstr.push_str(" hi"); - self.set_string(QString::from(nstr.as_str())); - } - - #[qinvokable] - pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) { - println!("wow!"); - match variant.value() { - QVariantValue::QString(string) => self.set_string(string), - _ => println!("Unknown QVariant type"), - } - } - } -} diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs deleted file mode 100644 index 380ac19..0000000 --- a/src/rust/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} - -mod cxxqt_object; -mod service_thing; diff --git a/src/rust/src/service_thing.rs b/src/rust/src/service_thing.rs deleted file mode 100644 index a7b2d6f..0000000 --- a/src/rust/src/service_thing.rs +++ /dev/null @@ -1,80 +0,0 @@ -#[cxx_qt::bridge] -mod service_thing { - use cxx_qt_lib::QVariantValue; - - unsafe extern "C++" { - include!("cxx-qt-lib/qstring.h"); - type QString = cxx_qt_lib::QString; - include!("cxx-qt-lib/qvariant.h"); - type QVariant = cxx_qt_lib::QVariant; - } - - #[cxx_qt::qobject] - pub struct ServiceThing { - #[qproperty] - name: QString, - #[qproperty] - kind: QString, - #[qproperty] - background: QString, - #[qproperty] - background_type: QString, - #[qproperty] - text: QString, - #[qproperty] - audio: QString, - #[qproperty] - font: QString, - #[qproperty] - font_size: QString, - #[qproperty] - active: bool, - #[qproperty] - selected: bool, - } - - impl Default for ServiceThing { - fn default() -> Self { - Self { - name: QString::from(""), - kind: QString::from(""), - background: QString::from(""), - background_type: QString::from(""), - text: QString::from(""), - audio: QString::from(""), - font: QString::from(""), - font_size: QString::from(""), - active: false, - selected: false, - } - } - } - - impl qobject::ServiceThing { - #[qinvokable] - pub fn activate(self: Pin<&mut Self>) { - self.set_active(true); - } - - #[qinvokable] - pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) { - println!( - "Hi from Rust! String is '{}' and number is {}", - string, number - ); - println!("length is: {}", string.to_string().len()); - let mut nstr: String = string.to_string(); - nstr.push_str(" hi"); - self.set_name(QString::from(nstr.as_str())); - } - - #[qinvokable] - pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) { - println!("wow!"); - match variant.value() { - QVariantValue::QString(string) => self.set_name(string), - _ => println!("Unknown QVariant type"), - } - } - } -}