diff --git a/src/ast/sprite.rs b/src/ast/sprite.rs index 51b0fc2..fb5e19c 100644 --- a/src/ast/sprite.rs +++ b/src/ast/sprite.rs @@ -16,10 +16,12 @@ pub struct Sprite { pub costumes: Vec, pub sounds: Vec, pub procs: FxHashMap, + #[serde(skip)] pub proc_definitions: FxHashMap>, pub proc_references: FxHashMap, pub proc_args: FxHashMap>, pub funcs: FxHashMap, + #[serde(skip)] pub func_definitions: FxHashMap>, pub func_references: FxHashMap, pub func_args: FxHashMap>, @@ -29,6 +31,7 @@ pub struct Sprite { pub proc_locals: FxHashMap>, pub func_locals: FxHashMap>, pub lists: FxHashMap, + #[serde(skip)] pub events: Vec, pub used_procs: FxHashSet, pub used_funcs: FxHashSet, diff --git a/src/codegen/debug_info.rs b/src/codegen/debug_info.rs index 2d0b3df..fd52b46 100644 --- a/src/codegen/debug_info.rs +++ b/src/codegen/debug_info.rs @@ -6,6 +6,12 @@ use serde::{ }; use tsify::Tsify; +use crate::{ + ast::Project, + diagnostic::SpriteDiagnostics, + misc::SmolStr, +}; + #[derive(Tsify, Serialize, Deserialize, Default)] #[tsify(into_wasm_abi, from_wasm_abi)] pub struct DebugInfo { @@ -15,3 +21,11 @@ pub struct DebugInfo { pub procs: FxHashMap, pub funcs: FxHashMap, } + +#[derive(Tsify, Serialize)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct ArtifactRef<'a> { + pub project: &'a Project, + pub stage_diagnostics: &'a SpriteDiagnostics, + pub sprites_diagnostics: &'a FxHashMap, +} diff --git a/src/codegen/sb3.rs b/src/codegen/sb3.rs index 3f7f224..ba85113 100644 --- a/src/codegen/sb3.rs +++ b/src/codegen/sb3.rs @@ -27,6 +27,7 @@ use zip::{ use super::{ cmd::cmd_to_list, + debug_info::ArtifactRef, node::Node, node_id::NodeID, node_id_factory::NodeIDFactory, @@ -38,6 +39,7 @@ use crate::{ codegen::mutation::Mutation, config::Config, diagnostic::{ + Artifact, DiagnosticKind, SpriteDiagnostics, }, @@ -278,6 +280,7 @@ where T: Write + Seek pub costumes: FxHashMap, pub srcpkg_hash: Option, pub srcpkg: Option>, + pub release: bool, } impl Write for Sb3 @@ -295,7 +298,7 @@ where T: Write + Seek impl Sb3 where T: Write + Seek { - pub fn new(file: T) -> Self { + pub fn new(file: T, release: bool) -> Self { Self { zip: ZipWriter::new(file), id: NodeIDFactory::new(), @@ -304,6 +307,7 @@ where T: Write + Seek costumes: FxHashMap::default(), srcpkg_hash: None, srcpkg: None, + release, } } @@ -432,6 +436,19 @@ where T: Write + Seek write!(self, "}}")?; // meta write!(self, "}}")?; // project self.assets(fs.clone(), input)?; + if !self.release { + self.zip + .start_file("artifact.json", SimpleFileOptions::default())?; + write!( + self.zip, + "{}", + json!(ArtifactRef { + project, + stage_diagnostics, + sprites_diagnostics, + }) + )?; + } Ok(()) } diff --git a/src/frontend.rs b/src/frontend.rs index 3e89d7f..b88fd90 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -26,7 +26,11 @@ use crate::{ pub fn frontend() -> ExitCode { match Cli::parse().command { - Command::Build { input, output } => match build::build(input, output) { + Command::Build { + input, + output, + release, + } => match build::build(input, output, release) { Ok(artifact) => { artifact.eprint(); eprintln!(); diff --git a/src/frontend/build.rs b/src/frontend/build.rs index 6428f94..2bcabe2 100644 --- a/src/frontend/build.rs +++ b/src/frontend/build.rs @@ -39,12 +39,16 @@ use crate::{ visitor, }; -pub fn build(input: Option, output: Option) -> anyhow::Result { +pub fn build( + input: Option, + output: Option, + release: bool, +) -> anyhow::Result { let input = input.unwrap_or_else(|| env::current_dir().unwrap()); let canonical_input = input.canonicalize()?; let project_name = canonical_input.file_name().unwrap().to_str().unwrap(); let output = output.unwrap_or_else(|| input.join(format!("{project_name}.sb3"))); - let sb3 = Sb3::new(BufWriter::new(File::create(&output)?)); + let sb3 = Sb3::new(BufWriter::new(File::create(&output)?), release); let fs = Rc::new(RefCell::new(RealFS::new())); build_impl(fs, canonical_input, sb3, None) } diff --git a/src/frontend/cli.rs b/src/frontend/cli.rs index ae2edba..1df725a 100644 --- a/src/frontend/cli.rs +++ b/src/frontend/cli.rs @@ -25,6 +25,8 @@ pub enum Command { #[arg(short, long)] /// Output file, if not given, it will be the project directory's name + `.sb3` output: Option, + #[arg(short, long)] + release: bool, }, /// Run a goboscript file using the experimental interpreter. diff --git a/src/translation_unit.rs b/src/translation_unit.rs index 521d9b3..efbcb07 100644 --- a/src/translation_unit.rs +++ b/src/translation_unit.rs @@ -46,7 +46,8 @@ pub struct Include { #[derive(Tsify, Serialize, Deserialize)] #[tsify(into_wasm_abi, from_wasm_abi)] pub struct TranslationUnit { - pub path: PathBuf, + path: PathBuf, + #[serde(skip)] text: Vec, defines: FxHashSet, includes: Vec, diff --git a/src/wasm.rs b/src/wasm.rs index 243de7a..6e2243c 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -40,7 +40,7 @@ pub struct Build { pub fn build(fs: JsValue) -> JsValue { let fs: MemFS = serde_wasm_bindgen::from_value(fs).unwrap(); let mut file = Vec::new(); - let sb3 = Sb3::new(Cursor::new(&mut file)); + let sb3 = Sb3::new(Cursor::new(&mut file), true); let stdlib = StandardLibrary { path: "stdlib".into(), version: Version::new(0, 0, 0),