Compare commits
	
		
			No commits in common. "618559183635f8dfc5a814c76670bee4c7e29f2d" and "6f8a49dc3293e8c44ab947884ba3bf06abfc0356" have entirely different histories.
		
	
	
		
			6185591836
			...
			6f8a49dc32
		
	
		
|  | @ -249,7 +249,6 @@ pub mod rust { | ||||||
|     use itertools::Itertools; |     use itertools::Itertools; | ||||||
|     use proc_macro2::{Ident, TokenStream}; |     use proc_macro2::{Ident, TokenStream}; | ||||||
|     use quote::{format_ident, quote}; |     use quote::{format_ident, quote}; | ||||||
|     use rayon::prelude::{IntoParallelIterator, ParallelIterator}; |  | ||||||
|     use unreal_sdk::sdk::repr::{ |     use unreal_sdk::sdk::repr::{ | ||||||
|         Class, ClassField, ClassMethod, Enum, ObjectRef, PackageRef, PrimitiveType, |         Class, ClassField, ClassMethod, Enum, ObjectRef, PackageRef, PrimitiveType, | ||||||
|         ProcessedPackage, Sdk, StructKind, Type, UnrealType, |         ProcessedPackage, Sdk, StructKind, Type, UnrealType, | ||||||
|  | @ -366,7 +365,7 @@ pub mod rust { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         pub fn build(self, args: &super::Build) -> anyhow::Result<BTreeMap<String, String>> { |         pub fn build(self, args: &super::Build) -> anyhow::Result<BTreeMap<String, TokenStream>> { | ||||||
|             let pkgs = if let Some(packages) = &args.packages { |             let pkgs = if let Some(packages) = &args.packages { | ||||||
|                 let deps = self.dependencies_for_package_names(packages); |                 let deps = self.dependencies_for_package_names(packages); | ||||||
|                 log::debug!("all dependencies: {deps:?}"); |                 log::debug!("all dependencies: {deps:?}"); | ||||||
|  | @ -379,73 +378,18 @@ pub mod rust { | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             let packages = pkgs |             let packages = pkgs | ||||||
|                 .into_par_iter() |                 .into_iter() | ||||||
|                 .map(|pkg| { |                 .map(|pkg| { | ||||||
|                     let (ident, tokens) = self.generate_package(pkg, args.feature_gate)?; |                     let name = canonicalize_name(&pkg.name).to_string(); | ||||||
|  |                     let tokens = self.generate_package(pkg, args.feature_gate)?; | ||||||
| 
 | 
 | ||||||
|                     let tokens = if args.single_file { |                     anyhow::Ok((name, tokens)) | ||||||
|                         tokens |  | ||||||
|                     } else { |  | ||||||
|                         quote! { |  | ||||||
|                             pub mod #ident { |  | ||||||
|                                 #tokens |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     }; |  | ||||||
| 
 |  | ||||||
|                     anyhow::Ok((ident.to_string(), tokens.to_string())) |  | ||||||
|                 }) |                 }) | ||||||
|                 .collect::<Result<BTreeMap<_, _>, _>>()?; |                 .collect::<Result<BTreeMap<_, _>, _>>()?; | ||||||
| 
 | 
 | ||||||
|             Ok(packages) |             Ok(packages) | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         pub fn build_in_dir<P: AsRef<Path>>( |  | ||||||
|             self, |  | ||||||
|             path: P, |  | ||||||
|             args: &super::Build, |  | ||||||
|         ) -> anyhow::Result<()> { |  | ||||||
|             let packages = self.build(args)?; |  | ||||||
| 
 |  | ||||||
|             let path = path.as_ref(); |  | ||||||
|             std::fs::create_dir_all(&path)?; |  | ||||||
| 
 |  | ||||||
|             let mut mod_rs = TokenStream::new(); |  | ||||||
| 
 |  | ||||||
|             for (name, tokens) in packages { |  | ||||||
|                 let name = format_ident!("{name}"); |  | ||||||
|                 if args.single_file { |  | ||||||
|                     mod_rs.extend(quote! { |  | ||||||
|                         pub mod #name { |  | ||||||
|                             #tokens |  | ||||||
|                         } |  | ||||||
|                     }); |  | ||||||
|                 } else { |  | ||||||
|                     let path = path.join(format!("{name}.rs")); |  | ||||||
| 
 |  | ||||||
|                     log::info!("parsing {name}.."); |  | ||||||
|                     let file = |  | ||||||
|                         syn::parse_file(&tokens).context("syn failed to parse generated code")?; |  | ||||||
| 
 |  | ||||||
|                     log::info!("pretty printing {name}.."); |  | ||||||
|                     let contents = prettyplease::unparse(&file); |  | ||||||
|                     log::info!("writing to {}..", path.display()); |  | ||||||
|                     std::fs::write(path, contents)?; |  | ||||||
| 
 |  | ||||||
|                     mod_rs.extend(quote! { |  | ||||||
|                         pub mod #name; |  | ||||||
|                     }); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             let contents = prettyplease::unparse( |  | ||||||
|                 &syn::parse_file(&mod_rs.to_string()).context("syn failed to parse root module")?, |  | ||||||
|             ); |  | ||||||
|             std::fs::write(path.join("mod.rs"), contents)?; |  | ||||||
| 
 |  | ||||||
|             Ok(()) |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         fn get_package_by_name(&self, name: &str) -> Option<PackageRef> { |         fn get_package_by_name(&self, name: &str) -> Option<PackageRef> { | ||||||
|             self.sdk |             self.sdk | ||||||
|                 .packages |                 .packages | ||||||
|  | @ -483,6 +427,52 @@ pub mod rust { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         pub fn build_in_dir<P: AsRef<Path>>( | ||||||
|  |             self, | ||||||
|  |             path: P, | ||||||
|  |             args: &super::Build, | ||||||
|  |         ) -> anyhow::Result<()> { | ||||||
|  |             let packages = self.build(args)?; | ||||||
|  | 
 | ||||||
|  |             let path = path.as_ref(); | ||||||
|  |             std::fs::create_dir_all(&path)?; | ||||||
|  | 
 | ||||||
|  |             let mut mod_rs = TokenStream::new(); | ||||||
|  | 
 | ||||||
|  |             for (name, tokens) in packages { | ||||||
|  |                 let name = format_ident!("{name}"); | ||||||
|  |                 if args.single_file { | ||||||
|  |                     mod_rs.extend(quote! { | ||||||
|  |                         pub mod #name { | ||||||
|  |                             #tokens | ||||||
|  |                         } | ||||||
|  |                     }); | ||||||
|  |                 } else { | ||||||
|  |                     let path = path.join(format!("{name}.rs")); | ||||||
|  | 
 | ||||||
|  |                     log::info!("parsing {name}.."); | ||||||
|  |                     let file = syn::parse_file(&tokens.to_string()) | ||||||
|  |                         .context("syn failed to parse generated code")?; | ||||||
|  | 
 | ||||||
|  |                     log::info!("pretty printing {name}.."); | ||||||
|  |                     let contents = prettyplease::unparse(&file); | ||||||
|  |                     log::info!("writing to {}..", path.display()); | ||||||
|  |                     std::fs::write(path, contents)?; | ||||||
|  | 
 | ||||||
|  |                     mod_rs.extend(quote! { | ||||||
|  |                         pub mod #name; | ||||||
|  |                     }); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             let contents = prettyplease::unparse( | ||||||
|  |                 &syn::parse_file(&mod_rs.to_string()).context("syn failed to parse root module")?, | ||||||
|  |             ); | ||||||
|  |             std::fs::write(path.join("mod.rs"), contents)?; | ||||||
|  | 
 | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         fn generate_enum(&self, enum0: &Enum) -> anyhow::Result<TokenStream> { |         fn generate_enum(&self, enum0: &Enum) -> anyhow::Result<TokenStream> { | ||||||
|             let name = self |             let name = self | ||||||
|                 .get_type_ident(&enum0.obj_ref) |                 .get_type_ident(&enum0.obj_ref) | ||||||
|  | @ -619,7 +609,6 @@ pub mod rust { | ||||||
|             let methods = class |             let methods = class | ||||||
|                 .methods |                 .methods | ||||||
|                 .iter() |                 .iter() | ||||||
|                 .filter(|method| !method.unique_name().is_empty()) |  | ||||||
|                 .map(|method| self.generate_method(name, method)) |                 .map(|method| self.generate_method(name, method)) | ||||||
|                 .collect::<Result<Vec<_>, _>>()?; |                 .collect::<Result<Vec<_>, _>>()?; | ||||||
| 
 | 
 | ||||||
|  | @ -981,7 +970,7 @@ pub mod rust { | ||||||
|             &self, |             &self, | ||||||
|             pkg: &ProcessedPackage, |             pkg: &ProcessedPackage, | ||||||
|             feature_gate: bool, |             feature_gate: bool, | ||||||
|         ) -> anyhow::Result<(Ident, TokenStream)> { |         ) -> anyhow::Result<TokenStream> { | ||||||
|             let pkg_name = canonicalize_ident(&pkg.name); |             let pkg_name = canonicalize_ident(&pkg.name); | ||||||
|             log::info!( |             log::info!( | ||||||
|                 "generating package \"{pkg_name}\" with {} types..", |                 "generating package \"{pkg_name}\" with {} types..", | ||||||
|  | @ -1019,15 +1008,14 @@ pub mod rust { | ||||||
|                 None |                 None | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             Ok(( |             Ok(quote! { | ||||||
|                 pkg_name, |                 pub mod #pkg_name { | ||||||
|                 quote! { |  | ||||||
|                     #feature_gate |                     #feature_gate | ||||||
|                     #![allow(dead_code, unused_imports, non_snake_case, non_camel_case_types)] |                     #![allow(dead_code, unused_imports, non_snake_case, non_camel_case_types)] | ||||||
| 
 | 
 | ||||||
|                     #pkg_tokens |                     #pkg_tokens | ||||||
|                 }, |                 } | ||||||
|             )) |             }) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -160,7 +160,7 @@ impl Package { | ||||||
|             .get_full_name() |             .get_full_name() | ||||||
|             .context("failed to get struct or class full name")?; |             .context("failed to get struct or class full name")?; | ||||||
| 
 | 
 | ||||||
|         let _is_actor = strct |         let is_actor = strct | ||||||
|             .iter_super_structs() |             .iter_super_structs() | ||||||
|             .contains(&unsafe { actor_static_class().unwrap().cast() }) |             .contains(&unsafe { actor_static_class().unwrap().cast() }) | ||||||
|             || Some(strct) == actor_static_class().map(|class| unsafe { class.cast() }); |             || Some(strct) == actor_static_class().map(|class| unsafe { class.cast() }); | ||||||
|  | @ -176,8 +176,8 @@ impl Package { | ||||||
|             None |             None | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         let _properties_size = *strct.property_size(); |         let properties_size = *strct.property_size(); | ||||||
|         let _min_alignment = *strct.min_alignment(); |         let min_alignment = *strct.min_alignment(); | ||||||
| 
 | 
 | ||||||
|         let (fields, methods) = self.process_children(strct)?; |         let (fields, methods) = self.process_children(strct)?; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue