Skip to content

Commit

Permalink
Remove separate debug artifact from wasm build output
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Jan 10, 2024
1 parent 672bded commit 2ab38fa
Showing 1 changed file with 12 additions and 40 deletions.
52 changes: 12 additions & 40 deletions noir/compiler/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use gloo_utils::format::JsValueSerdeExt;
use js_sys::{JsString, Object};
use nargo::artifacts::{
contract::{ContractArtifact, ContractFunctionArtifact},
debug::DebugArtifact,
program::ProgramArtifact,
};
use noirc_driver::{
Expand Down Expand Up @@ -33,28 +32,25 @@ export type CompiledContract = {
name: string;
functions: Array<any>;
events: Array<any>;
file_map: Record<number, any>;
warnings: Array<any>;
};
export type CompiledProgram = {
noir_version: string;
abi: any;
bytecode: string;
}
export type DebugArtifact = {
debug_symbols: Array<any>;
debug_symbols: any;
file_map: Record<number, any>;
warnings: Array<any>;
};
}
export type CompileResult = (
| {
contract: CompiledContract;
debug: DebugArtifact;
}
| {
program: CompiledProgram;
debug: DebugArtifact;
}
);
"#;
Expand All @@ -76,40 +72,25 @@ extern "C" {
impl JsCompileResult {
const CONTRACT_PROP: &'static str = "contract";
const PROGRAM_PROP: &'static str = "program";
const DEBUG_PROP: &'static str = "debug";

pub fn new(resp: CompileResult) -> JsCompileResult {
let obj = JsCompileResult::constructor();
match resp {
CompileResult::Contract { contract, debug } => {
CompileResult::Contract { contract } => {
js_sys::Reflect::set(
&obj,
&JsString::from(JsCompileResult::CONTRACT_PROP),
&<JsValue as JsValueSerdeExt>::from_serde(&contract).unwrap(),
)
.unwrap();

js_sys::Reflect::set(
&obj,
&JsString::from(JsCompileResult::DEBUG_PROP),
&<JsValue as JsValueSerdeExt>::from_serde(&debug).unwrap(),
)
.unwrap();
}
CompileResult::Program { program, debug } => {
CompileResult::Program { program } => {
js_sys::Reflect::set(
&obj,
&JsString::from(JsCompileResult::PROGRAM_PROP),
&<JsValue as JsValueSerdeExt>::from_serde(&program).unwrap(),
)
.unwrap();

js_sys::Reflect::set(
&obj,
&JsString::from(JsCompileResult::DEBUG_PROP),
&<JsValue as JsValueSerdeExt>::from_serde(&debug).unwrap(),
)
.unwrap();
}
};

Expand Down Expand Up @@ -148,8 +129,8 @@ impl PathToFileSourceMap {
}

pub enum CompileResult {
Contract { contract: ContractArtifact, debug: DebugArtifact },
Program { program: ProgramArtifact, debug: DebugArtifact },
Contract { contract: ContractArtifact },
Program { program: ProgramArtifact },
}

#[wasm_bindgen]
Expand Down Expand Up @@ -273,31 +254,22 @@ fn add_noir_lib(context: &mut Context, library_name: &CrateName) -> CrateId {
}

pub(crate) fn generate_program_artifact(program: CompiledProgram) -> CompileResult {
let debug_artifact = DebugArtifact {
debug_symbols: vec![program.debug.clone()],
file_map: program.file_map.clone(),
warnings: program.warnings.clone(),
};

CompileResult::Program { program: program.into(), debug: debug_artifact }
CompileResult::Program { program: program.into() }
}

pub(crate) fn generate_contract_artifact(contract: CompiledContract) -> CompileResult {
let debug_artifact = DebugArtifact {
debug_symbols: contract.functions.iter().map(|function| function.debug.clone()).collect(),
file_map: contract.file_map,
warnings: contract.warnings,
};
let functions = contract.functions.into_iter().map(ContractFunctionArtifact::from).collect();

let contract_artifact = ContractArtifact {
noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING),
name: contract.name,
functions,
events: contract.events,
file_map: contract.file_map,
warnings: contract.warnings,
};

CompileResult::Contract { contract: contract_artifact, debug: debug_artifact }
CompileResult::Contract { contract: contract_artifact }
}

#[cfg(test)]
Expand Down

0 comments on commit 2ab38fa

Please sign in to comment.