Compare commits

..

No commits in common. "618559183635f8dfc5a814c76670bee4c7e29f2d" and "6f8a49dc3293e8c44ab947884ba3bf06abfc0356" have entirely different histories.

2 changed files with 59 additions and 71 deletions

View file

@ -249,7 +249,6 @@ pub mod rust {
use itertools::Itertools;
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use unreal_sdk::sdk::repr::{
Class, ClassField, ClassMethod, Enum, ObjectRef, PackageRef, PrimitiveType,
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 deps = self.dependencies_for_package_names(packages);
log::debug!("all dependencies: {deps:?}");
@ -379,73 +378,18 @@ pub mod rust {
};
let packages = pkgs
.into_par_iter()
.into_iter()
.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 {
tokens
} else {
quote! {
pub mod #ident {
#tokens
}
}
};
anyhow::Ok((ident.to_string(), tokens.to_string()))
anyhow::Ok((name, tokens))
})
.collect::<Result<BTreeMap<_, _>, _>>()?;
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> {
self.sdk
.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> {
let name = self
.get_type_ident(&enum0.obj_ref)
@ -619,7 +609,6 @@ pub mod rust {
let methods = class
.methods
.iter()
.filter(|method| !method.unique_name().is_empty())
.map(|method| self.generate_method(name, method))
.collect::<Result<Vec<_>, _>>()?;
@ -981,7 +970,7 @@ pub mod rust {
&self,
pkg: &ProcessedPackage,
feature_gate: bool,
) -> anyhow::Result<(Ident, TokenStream)> {
) -> anyhow::Result<TokenStream> {
let pkg_name = canonicalize_ident(&pkg.name);
log::info!(
"generating package \"{pkg_name}\" with {} types..",
@ -1019,15 +1008,14 @@ pub mod rust {
None
};
Ok((
pkg_name,
quote! {
Ok(quote! {
pub mod #pkg_name {
#feature_gate
#![allow(dead_code, unused_imports, non_snake_case, non_camel_case_types)]
#pkg_tokens
},
))
}
})
}
}
}

View file

@ -160,7 +160,7 @@ impl Package {
.get_full_name()
.context("failed to get struct or class full name")?;
let _is_actor = strct
let is_actor = strct
.iter_super_structs()
.contains(&unsafe { actor_static_class().unwrap().cast() })
|| Some(strct) == actor_static_class().map(|class| unsafe { class.cast() });
@ -176,8 +176,8 @@ impl Package {
None
};
let _properties_size = *strct.property_size();
let _min_alignment = *strct.min_alignment();
let properties_size = *strct.property_size();
let min_alignment = *strct.min_alignment();
let (fields, methods) = self.process_children(strct)?;