diff --git a/Cargo.toml b/Cargo.toml index d98686f3..f853fd31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ "ecosystem/rust/pyo3-importer", "ecosystem/rust/cargo", "ecosystem/rust/example", -# "ecosystem/rust/exporter", + "ecosystem/rust/exporter", # "ecosystem/rust/runtime", "ecosystem/rust/parser", # "ecosystem/c/cmake", diff --git a/ecosystem/rust/exporter/Cargo.toml b/ecosystem/rust/exporter/Cargo.toml index 34551575..c411e977 100644 --- a/ecosystem/rust/exporter/Cargo.toml +++ b/ecosystem/rust/exporter/Cargo.toml @@ -6,12 +6,8 @@ edition.workspace = true license.workspace = true [dependencies] -ligen-ir.workspace = true -ligen-traits.workspace = true -ligen-utils.workspace = true -ligen-common.workspace = true -ligen-parsing.workspace = true -serde_json.workspace = true +ligen.workspace = true +serde_json.workspace = true [dev-dependencies] pretty_assertions.workspace = true diff --git a/ecosystem/rust/exporter/src/generator/exporter/mod.rs b/ecosystem/rust/exporter/src/generator/exporter/mod.rs deleted file mode 100644 index 48ecad66..00000000 --- a/ecosystem/rust/exporter/src/generator/exporter/mod.rs +++ /dev/null @@ -1,113 +0,0 @@ -// FIXME: Move this to a generation module. -use ligen_ir::*; - -use ligen_traits::generator::file_generator::{TemplateBasedGenerator, TemplateRegister, Template, Inputs}; -use std::path::PathBuf; -use std::str::FromStr; -use ligen_ir::Type; - -use ligen_traits::prelude::*; -use ligen_traits::{register_functions, register_templates}; - -fn marshal_output(inputs: &Inputs) -> String { - let type_ = inputs - .get(0) - .and_then(|input| serde_json::from_value::(input).ok()); - if let Some(Type::Composite(_, _)) = type_ { - "Box::into_raw(Box::new(result))" - } else { - "result" - }.into() -} - -fn type_mapping(type_: &Type, root: bool) -> String { - match type_ { - Type::Reference(reference) => { - let type_ = type_mapping(&reference.type_, false); - match reference.mutability { - // FIXME: Change this to pointers and check if they are null or not. - Mutability::Mutable => format!("&mut {}", type_), - Mutability::Constant => format!("&{}", type_), - } - }, - Type::Composite(composite, _generics) => { - // FIXME: Hardcoded. - let opaque = true && root; - let mapped = composite.to_string("::"); - if opaque { - format!("*mut {}", mapped) - } else { - mapped - } - }, - Type::Primitive(primitive) => { - match primitive { - Primitive::Boolean => "bool", - Primitive::Character => "char", - Primitive::Float(float) => { - match float { - Float::F32 => "f32", - Float::F64 => "f64" - } - }, - Primitive::Integer(integer) => { - match integer { - Integer::I8 => "i8", - Integer::U8 => "u8", - Integer::I16 => "i16", - Integer::U16 => "u16", - Integer::I32 => "i32", - Integer::U32 => "u32", - Integer::I64 => "i64", - Integer::U64 => "u64", - Integer::I128 => "i128", - Integer::U128 => "u128", - Integer::ISize => "isize", - Integer::USize => "usize" - } - } - }.to_string() - } - }.to_string() -} - -fn mapped_type(inputs: &Inputs) -> String { - let type_ = inputs - .get(0) - .and_then(|input| serde_json::from_value::(input).ok()); - if let Some(type_) = type_ { - type_mapping(&type_, true) - } else { - "()".to_string() - } -} - -#[derive(Debug, Default)] -pub struct RustGenerator; - -impl TemplateRegister for RustGenerator { - fn register_templates(&self, template: &mut Template) -> Result<()> { - register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library); - Ok(()) - } -} - -impl TemplateBasedGenerator for RustGenerator { - fn register_functions(&self, _library: &Library, template: &mut Template) { - register_functions!(template, mapped_type, marshal_output); - } - - fn base_path(&self) -> PathBuf { - PathBuf::from("rust".to_string()) - } - - fn module_generation_path(&self, _library: &Library, _module: &Module) -> PathBuf { - // let is_root_module = library.root_module == *module; - // let name = if is_root_module { "lib.rs" } else { "mod.rs" }; - let path = PathBuf::from_str("src").unwrap(); - // path = path.join(PathBuf::from(module.path.clone().without_first())); - // path = path.join(name); - // FIXME: This is not working. - path - } -} diff --git a/ecosystem/rust/exporter/src/generator/importer/mod.rs b/ecosystem/rust/exporter/src/generator/importer/mod.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/ecosystem/rust/exporter/src/generator/mod.rs b/ecosystem/rust/exporter/src/generator/mod.rs deleted file mode 100644 index 7232f658..00000000 --- a/ecosystem/rust/exporter/src/generator/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod exporter; -pub mod importer; \ No newline at end of file diff --git a/ecosystem/rust/exporter/src/lib.rs b/ecosystem/rust/exporter/src/lib.rs index 72749cba..e69de29b 100644 --- a/ecosystem/rust/exporter/src/lib.rs +++ b/ecosystem/rust/exporter/src/lib.rs @@ -1,3 +0,0 @@ -// TODO: Rework the exporter. - -pub mod generator; diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/arguments.hbs b/ecosystem/rust/exporter/src/templates/arguments.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/arguments.hbs rename to ecosystem/rust/exporter/src/templates/arguments.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/function.hbs b/ecosystem/rust/exporter/src/templates/function.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/function.hbs rename to ecosystem/rust/exporter/src/templates/function.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/identifier.hbs b/ecosystem/rust/exporter/src/templates/identifier.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/identifier.hbs rename to ecosystem/rust/exporter/src/templates/identifier.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/implementation.hbs b/ecosystem/rust/exporter/src/templates/implementation.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/implementation.hbs rename to ecosystem/rust/exporter/src/templates/implementation.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/method.hbs b/ecosystem/rust/exporter/src/templates/method.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/method.hbs rename to ecosystem/rust/exporter/src/templates/method.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/module.hbs b/ecosystem/rust/exporter/src/templates/module.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/module.hbs rename to ecosystem/rust/exporter/src/templates/module.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/object.hbs b/ecosystem/rust/exporter/src/templates/object.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/object.hbs rename to ecosystem/rust/exporter/src/templates/object.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/parameters.hbs b/ecosystem/rust/exporter/src/templates/parameters.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/parameters.hbs rename to ecosystem/rust/exporter/src/templates/parameters.hbs diff --git a/ecosystem/rust/exporter/src/generator/exporter/templates/project.hbs b/ecosystem/rust/exporter/src/templates/project.hbs similarity index 100% rename from ecosystem/rust/exporter/src/generator/exporter/templates/project.hbs rename to ecosystem/rust/exporter/src/templates/project.hbs diff --git a/ecosystem/rust/pyo3-importer/Cargo.toml b/ecosystem/rust/pyo3-importer/Cargo.toml index e46441c7..b8aa987f 100644 --- a/ecosystem/rust/pyo3-importer/Cargo.toml +++ b/ecosystem/rust/pyo3-importer/Cargo.toml @@ -11,7 +11,5 @@ readme.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ligen-ir.workspace = true -ligen-generator.workspace = true -ligen-utils.workspace = true +ligen.workspace = true is-tree.workspace = true diff --git a/ecosystem/rust/pyo3-importer/src/identifier/mod.rs b/ecosystem/rust/pyo3-importer/src/identifier/mod.rs index 5ccaca37..7cb3b215 100644 --- a/ecosystem/rust/pyo3-importer/src/identifier/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/identifier/mod.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; -use ligen_ir::Identifier; -use ligen_utils::mapper::LanguageMap; +use ligen::ir::Identifier; +use ligen::utils::mapper::LanguageMap; pub struct IdentifierGenerator { map: LanguageMap, diff --git a/ecosystem/rust/pyo3-importer/src/lib.rs b/ecosystem/rust/pyo3-importer/src/lib.rs index 01d2030e..3fe87364 100644 --- a/ecosystem/rust/pyo3-importer/src/lib.rs +++ b/ecosystem/rust/pyo3-importer/src/lib.rs @@ -7,9 +7,9 @@ pub mod type_; pub use module::*; use std::path::PathBuf; -use ligen_ir::{Library, Visitors}; +use ligen::ir::{Library, Visitors}; -use ligen_generator::file_generator::{FileGenerator, FileSet, Template}; +use ligen::generator::file_generator::{FileGenerator, FileSet, Template}; use is_tree::{HasBranch, TreeIterator}; diff --git a/ecosystem/rust/pyo3-importer/src/module/interface/function/mod.rs b/ecosystem/rust/pyo3-importer/src/module/interface/function/mod.rs index 7cdadb3a..9c6c5c0d 100644 --- a/ecosystem/rust/pyo3-importer/src/module/interface/function/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/module/interface/function/mod.rs @@ -1,6 +1,6 @@ -use ligen_generator::file_generator::FileSection; -use ligen_ir::{Function, Method, Identifier}; +use ligen::generator::file_generator::FileSection; +use ligen::ir::{Function, Method, Identifier}; use crate::{prelude::*, type_::TypeGenerator, identifier::IdentifierGenerator}; diff --git a/ecosystem/rust/pyo3-importer/src/module/interface/mod.rs b/ecosystem/rust/pyo3-importer/src/module/interface/mod.rs index c027154c..8aead63d 100644 --- a/ecosystem/rust/pyo3-importer/src/module/interface/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/module/interface/mod.rs @@ -4,8 +4,8 @@ pub use function::*; pub use structure::*; use is_tree::{HasBranch, Visitor}; -use ligen_generator::file_generator::File; -use ligen_ir::{Module, Visitors}; +use ligen::generator::file_generator::File; +use ligen::ir::{Module, Visitors}; #[derive(Default)] pub struct InterfaceGenerator { diff --git a/ecosystem/rust/pyo3-importer/src/module/interface/structure/mod.rs b/ecosystem/rust/pyo3-importer/src/module/interface/structure/mod.rs index c34fd02f..1db1a942 100644 --- a/ecosystem/rust/pyo3-importer/src/module/interface/structure/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/module/interface/structure/mod.rs @@ -1,5 +1,5 @@ -use ligen_generator::file_generator::FileSection; -use ligen_ir::TypeDefinition; +use ligen::generator::file_generator::FileSection; +use ligen::ir::TypeDefinition; pub use crate::prelude::*; diff --git a/ecosystem/rust/pyo3-importer/src/module/mod.rs b/ecosystem/rust/pyo3-importer/src/module/mod.rs index 83c22853..e251844a 100644 --- a/ecosystem/rust/pyo3-importer/src/module/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/module/mod.rs @@ -4,8 +4,8 @@ pub use interface::*; use std::path::PathBuf; use is_tree::{HasBranch, HasPath, Visitor}; -use ligen_generator::file_generator::FileSet; -use ligen_ir::{Identifier, Library, Module, Path, Visibility, Visitors}; +use ligen::generator::file_generator::FileSet; +use ligen::ir::{Identifier, Library, Module, Path, Visibility, Visitors}; #[derive(Default)] pub struct ModuleGenerator { diff --git a/ecosystem/rust/pyo3-importer/src/prelude.rs b/ecosystem/rust/pyo3-importer/src/prelude.rs index 18913d41..c71fb01f 100644 --- a/ecosystem/rust/pyo3-importer/src/prelude.rs +++ b/ecosystem/rust/pyo3-importer/src/prelude.rs @@ -1 +1 @@ -pub use ligen_generator::prelude::*; \ No newline at end of file +pub use ligen::generator::prelude::*; \ No newline at end of file diff --git a/ecosystem/rust/pyo3-importer/src/type_/mod.rs b/ecosystem/rust/pyo3-importer/src/type_/mod.rs index 443ae9e2..a3603789 100644 --- a/ecosystem/rust/pyo3-importer/src/type_/mod.rs +++ b/ecosystem/rust/pyo3-importer/src/type_/mod.rs @@ -1,4 +1,4 @@ -use ligen_ir::Type; +use ligen::ir::Type; use crate::identifier::IdentifierGenerator;