mirror of
https://github.com/exoticorn/curlywas.git
synced 2026-01-20 11:46:43 +01:00
always return dependencies, even when hitting an error
This commit is contained in:
24
src/lib.rs
24
src/lib.rs
@@ -28,10 +28,12 @@ pub struct CompiledModule {
|
||||
pub dependencies: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
pub fn compile_file<P: AsRef<Path>>(path: P, options: Options) -> Result<CompiledModule> {
|
||||
let mut dependencies = HashSet::new();
|
||||
|
||||
let path = path.as_ref();
|
||||
pub fn compile_file<P: AsRef<Path>>(path: P, options: Options) -> (Result<Vec<u8>>, Vec<PathBuf>) {
|
||||
fn compile_file_inner(
|
||||
path: &Path,
|
||||
options: Options,
|
||||
dependencies: &mut HashSet<PathBuf>,
|
||||
) -> Result<Vec<u8>> {
|
||||
let mut script = ast::Script::default();
|
||||
|
||||
let mut sources = Sources::new();
|
||||
@@ -46,7 +48,7 @@ pub fn compile_file<P: AsRef<Path>>(path: P, options: Options) -> Result<Compile
|
||||
Err(_) => bail!("Parse failed"),
|
||||
};
|
||||
|
||||
includes::resolve_includes(&mut new_script, &mut dependencies, &path)?;
|
||||
includes::resolve_includes(&mut new_script, dependencies, &path)?;
|
||||
|
||||
for include in std::mem::take(&mut new_script.includes) {
|
||||
let mut path = path
|
||||
@@ -85,8 +87,12 @@ pub fn compile_file<P: AsRef<Path>>(path: P, options: Options) -> Result<Compile
|
||||
.to_string_lossy(),
|
||||
&options,
|
||||
);
|
||||
Ok(CompiledModule {
|
||||
wasm,
|
||||
dependencies: dependencies.into_iter().collect(),
|
||||
})
|
||||
Ok(wasm)
|
||||
}
|
||||
|
||||
let mut dependencies = HashSet::new();
|
||||
|
||||
let result = compile_file_inner(path.as_ref(), options, &mut dependencies);
|
||||
|
||||
(result, dependencies.into_iter().collect())
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ fn main() -> Result<()> {
|
||||
|
||||
let mut filename = args.free_from_os_str::<PathBuf, bool>(|s| Ok(s.into()))?;
|
||||
|
||||
let module = compile_file(&filename, options)?;
|
||||
let wasm = compile_file(&filename, options).0?;
|
||||
|
||||
wasmparser::validate(&module.wasm)?;
|
||||
wasmparser::validate(&wasm)?;
|
||||
|
||||
filename.set_extension("wasm");
|
||||
File::create(filename)?.write_all(&module.wasm)?;
|
||||
File::create(filename)?.write_all(&wasm)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user