From 5514fbb67ef7bc2501279ad8797c978019ee3954 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 3 May 2024 19:33:43 +0200 Subject: [PATCH] [DONT MERGE]: BUMP OF PACKAGES --- TODO | 2 + cog.toml | 6 +- flake.lock | 24 ++-- flake.nix | 1 + licenses.txt | 3 + src/macros/generate.old/command_enum/mod.rs | 125 ------------------ src/macros/generate.old/lua_wrapper/mod.rs | 44 ------ src/macros/generate.old/mod.rs | 78 ----------- .../host/lua}/lua_functions_to_globals/mod.rs | 0 src/macros/generate/convert/host/lua/mod.rs | 84 ++++++++++++ .../host/lua}/rust_wrapper_functions/mod.rs | 0 11 files changed, 105 insertions(+), 262 deletions(-) create mode 100644 TODO create mode 100644 licenses.txt delete mode 100644 src/macros/generate.old/command_enum/mod.rs delete mode 100644 src/macros/generate.old/lua_wrapper/mod.rs delete mode 100644 src/macros/generate.old/mod.rs rename src/macros/{generate.old/lua_wrapper => generate/convert/host/lua}/lua_functions_to_globals/mod.rs (100%) create mode 100644 src/macros/generate/convert/host/lua/mod.rs rename src/macros/{generate.old/lua_wrapper => generate/convert/host/lua}/rust_wrapper_functions/mod.rs (100%) diff --git a/TODO b/TODO new file mode 100644 index 0000000..c701eac --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +- cargo clippy +- cargo deny diff --git a/cog.toml b/cog.toml index 597c9af..2d5edd3 100644 --- a/cog.toml +++ b/cog.toml @@ -25,8 +25,8 @@ ignore_merge_commits = false [commit_types] pre_bump_hooks = [ - "licensur -p -i", # update the license header in each file - "nix build", # verify the project builds + "./scripts/renew_copyright_header.sh", # update the license header in each file + "nix flake check", # verify the project builds "nix fmt", # format "cargo set-version {{version}}", # bump version in Cargo.toml ] @@ -43,4 +43,4 @@ path = "NEWS.md" remote = "git.nerdcult.net" repository = "trixy" owner = "trinitrix" -authors = [{ signature = "Soispha", username = "soispha" }] +authors = [{ signature = "Benedikt Peetz", username = "soispha" }] diff --git a/flake.lock b/flake.lock index 5716eb4..590b08f 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1711407199, - "narHash": "sha256-A/nB4j3JHL51ztlMQdfKw6y8tUJJzai3bLsZUEEaBxY=", + "lastModified": 1714755562, + "narHash": "sha256-jJ0xVJ27aQ3mLV8xqy064smZs96fJL84bccbKpZ+JcY=", "owner": "ipetkov", "repo": "crane", - "rev": "7e468a455506f2e65550e08dfd45092f0857a009", + "rev": "234eee4fa47c3860700d757ae94e43cf81b03dfd", "type": "github" }, "original": { @@ -152,11 +152,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1711370797, - "narHash": "sha256-2xu0jVSjuKhN97dqc4bVtvEH52Rwh6+uyI1XCnzoUyI=", + "lastModified": 1714656196, + "narHash": "sha256-kjQkA98lMcsom6Gbhw8SYzmwrSo+2nruiTcTZp5jK7o=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "c726225724e681b3626acc941c6f95d2b0602087", + "rev": "94035b482d181af0a0f8f77823a790b256b7c3cc", "type": "github" }, "original": { @@ -188,11 +188,11 @@ ] }, "locked": { - "lastModified": 1711419061, - "narHash": "sha256-+5M/czgYGqs/jKmi8bvYC+JUYboUKNTfkRiesXopeXQ=", + "lastModified": 1714702555, + "narHash": "sha256-/NoUbE5S5xpK1FU3nlHhQ/tL126+JcisXdzy3Ng4pDU=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "4c11d2f698ff1149f76b69e72852d5d75f492d0c", + "rev": "7f0e3ef7b7fbed78e12e5100851175d28af4b7c6", "type": "github" }, "original": { @@ -256,11 +256,11 @@ ] }, "locked": { - "lastModified": 1710781103, - "narHash": "sha256-nehQK/XTFxfa6rYKtbi8M1w+IU1v5twYhiyA4dg1vpg=", + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "7ee5aaac63c30d3c97a8c56efe89f3b2aa9ae564", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index bd32fcc..7b04f73 100644 --- a/flake.nix +++ b/flake.nix @@ -200,6 +200,7 @@ formatter = treefmtEval.config.build.wrapper; checks = { + build = craneBuild; formatting = treefmtEval.config.build.check self; }; diff --git a/licenses.txt b/licenses.txt new file mode 100644 index 0000000..34187c6 --- /dev/null +++ b/licenses.txt @@ -0,0 +1,3 @@ +https://reuse.software/faq/ +gcc -fanalyzer -> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html + -> https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html diff --git a/src/macros/generate.old/command_enum/mod.rs b/src/macros/generate.old/command_enum/mod.rs deleted file mode 100644 index 5c79ee0..0000000 --- a/src/macros/generate.old/command_enum/mod.rs +++ /dev/null @@ -1,125 +0,0 @@ -/* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* SPDX-License-Identifier: LGPL-3.0-or-later -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ - -use convert_case::{Case, Casing}; -use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote, ToTokens}; -use syn::{punctuated::Punctuated, Ident, Token, Type}; - -use crate::{command_enum_parsing::Field, DataCommandEnum}; - -use super::get_input_type_of_bare_fn_field; - -pub fn command_enum(input: &DataCommandEnum) -> TokenStream2 { - let (fields, namespace_enums): (TokenStream2, TokenStream2) = - turn_fields_to_enum(&input.fields); - - quote! { - #[derive(Debug)] - pub enum Command { - #fields - } - #namespace_enums - } -} - -fn turn_fields_to_enum(fields: &Punctuated) -> (TokenStream2, TokenStream2) { - let output: Vec<_> = fields - .iter() - .map(|field| turn_struct_field_to_enum(field)) - .collect(); - - let mut fields_output: TokenStream2 = Default::default(); - let mut namespace_enums_output: TokenStream2 = Default::default(); - - for (fields, namespace_enum) in output { - fields_output.extend(fields.to_token_stream()); - namespace_enums_output.extend(namespace_enum.to_token_stream()); - } - - (fields_output, namespace_enums_output) -} - -fn turn_struct_field_to_enum(field: &Field) -> (TokenStream2, TokenStream2) { - match field { - Field::Function(fun_field) => { - let field_name = format_ident!( - "{}", - fun_field - .name - .to_string() - .from_case(Case::Snake) - .to_case(Case::Pascal) - ); - - let input_type: Option = get_input_type_of_bare_fn_field(fun_field); - - match input_type { - Some(input_type) => ( - quote! { - #field_name(#input_type), - }, - quote! {}, - ), - None => ( - quote! { - #field_name, - }, - quote! {}, - ), - } - } - Field::Namespace(namespace) => { - let (namespace_output_fields, namespace_output_namespace_enums) = - turn_fields_to_enum(&namespace.fields); - let namespace_name: Ident = format_ident!( - "{}", - namespace - .path - .iter() - .map(|name| name.to_string()) - .collect::() - ); - - let new_namespace_name: Ident = format_ident!( - "{}", - namespace_name - .to_string() - .from_case(Case::Snake) - .to_case(Case::Pascal) - ); - - ( - quote! { - #new_namespace_name(#new_namespace_name), - }, - quote! { - #[derive(Debug)] - pub enum #new_namespace_name { - #namespace_output_fields - } - #namespace_output_namespace_enums - }, - ) - } - } -} diff --git a/src/macros/generate.old/lua_wrapper/mod.rs b/src/macros/generate.old/lua_wrapper/mod.rs deleted file mode 100644 index a9902af..0000000 --- a/src/macros/generate.old/lua_wrapper/mod.rs +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* SPDX-License-Identifier: LGPL-3.0-or-later -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ - -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; - -use crate::{ - generate::lua_wrapper::{ - lua_functions_to_globals::generate_add_lua_functions_to_globals, - rust_wrapper_functions::generate_rust_wrapper_functions, - }, - DataCommandEnum, -}; - -mod lua_functions_to_globals; -mod rust_wrapper_functions; - -pub fn lua_wrapper(input: &DataCommandEnum) -> TokenStream2 { - let add_lua_functions_to_globals = generate_add_lua_functions_to_globals(input); - let rust_wrapper_functions = generate_rust_wrapper_functions(None, input); - quote! { - #add_lua_functions_to_globals - #rust_wrapper_functions - } -} diff --git a/src/macros/generate.old/mod.rs b/src/macros/generate.old/mod.rs deleted file mode 100644 index 58314ff..0000000 --- a/src/macros/generate.old/mod.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* SPDX-License-Identifier: LGPL-3.0-or-later -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ - -mod command_enum; -mod lua_wrapper; - -pub use command_enum::command_enum; -pub use lua_wrapper::lua_wrapper; -use syn::{ReturnType, Type, TypeBareFn}; - -use crate::command_enum_parsing::FunctionDeclaration; - -pub fn get_bare_fn_input_type(function: &TypeBareFn) -> Option { - if function.inputs.len() == 1 { - Some( - function - .inputs - .first() - .expect("Only one element exists, we checked the length above") - .ty - .clone(), - ) - } else if function.inputs.len() == 0 { - // No inputs, so we can't return a type - None - } else { - unreachable!( - "The Function can only take one or zero arguments. - Use a tuple `(arg1, arg2)` if you want more" - ); - } -} - -pub fn get_input_type_of_bare_fn_field(field: &FunctionDeclaration) -> Option { - match &field.ty { - syn::Type::BareFn(function) => get_bare_fn_input_type(&function), - _ => unimplemented!( - "Please specify the type as a bare fn type. - That is: `fn() -> `" - ), - } -} -pub fn get_return_type_of_bare_fn_field(field: &FunctionDeclaration) -> Option { - match &field.ty { - syn::Type::BareFn(function) => get_bare_fn_return_type(&function), - _ => unimplemented!( - "Please specify the type as a bare fn type. - That is: `fn() -> `" - ), - } -} - -pub fn get_bare_fn_return_type(function: &TypeBareFn) -> Option { - let return_path: &ReturnType = &function.output; - match return_path { - ReturnType::Default => None, - ReturnType::Type(_, return_type) => Some(*return_type.to_owned()), - } -} diff --git a/src/macros/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs b/src/macros/generate/convert/host/lua/lua_functions_to_globals/mod.rs similarity index 100% rename from src/macros/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs rename to src/macros/generate/convert/host/lua/lua_functions_to_globals/mod.rs diff --git a/src/macros/generate/convert/host/lua/mod.rs b/src/macros/generate/convert/host/lua/mod.rs new file mode 100644 index 0000000..e5a9c7c --- /dev/null +++ b/src/macros/generate/convert/host/lua/mod.rs @@ -0,0 +1,84 @@ +/* +* Copyright (C) 2023 - 2024: +* The Trinitrix Project +* SPDX-License-Identifier: LGPL-3.0-or-later +* +* This file is part of the Trixy crate for Trinitrix. +* +* Trixy is free software: you can redistribute it and/or modify +* it under the terms of the Lesser GNU General Public License as +* published by the Free Software Foundation, either version 3 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* and the Lesser GNU General Public License along with this program. +* If not, see . +*/ + +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +pub mod lua_functions_to_globals; +pub mod rust_wrapper_functions; + +mod function; + +/// #[derive(Debug)] +/// pub enum Command { +/// Greet(String), +/// } +/// pub fn add_lua_functions_to_globals( +/// lua: mlua::Lua, +/// tx: tokio::sync::mpsc::Sender, +/// ) -> mlua::Lua { +/// lua.set_app_data(tx); +/// let globals = lua.globals(); +/// { +/// let wrapped_lua_function_greet = lua +/// .create_async_function(greet) +/// .expect( +/// format!( +/// "The function: `{}` should be defined", +/// "greet", +/// ) +/// ); +/// globals +/// .set("greet", wrapped_lua_function_greet) +/// .expect("Setting a static global value should work"); +/// } +/// drop(globals); +/// lua +/// } +/// async fn greet(lua: &mlua::Lua, input: String) -> Result { +/// let (callback_tx, callback_rx) = tokio::sync::oneshot::channel::(); +/// let tx: core::cell::Ref> = lua +/// .app_data_ref() +/// .expect("This should exist, it was set before"); +/// (*tx) +/// .send(Event::CommandEvent(Command::Greet(input.clone()), Some(callback_tx))) +/// .await +/// .expect("This should work, as the receiver is not dropped"); +/// match callback_rx.await { +/// Ok(output) => { +/// return Ok(output); +/// } +/// Err(err) => { +/// return Err(mlua::Error::ExternalError(std::sync::Arc::new(err))); +/// } +/// }; +/// } +pub fn generate() -> TokenStream2 {} + +// pub fn generate(input: &DataCommandEnum) -> TokenStream2 { +// let add_lua_functions_to_globals = generate_add_lua_functions_to_globals(input); +// let rust_wrapper_functions = generate_rust_wrapper_functions(None, input); +// quote! { +// #add_lua_functions_to_globals +// #rust_wrapper_functions +// } +// } diff --git a/src/macros/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs b/src/macros/generate/convert/host/lua/rust_wrapper_functions/mod.rs similarity index 100% rename from src/macros/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs rename to src/macros/generate/convert/host/lua/rust_wrapper_functions/mod.rs