remove wasm helpers into the mod for reuse

This commit is contained in:
Folkert 2022-07-16 15:37:54 +02:00
parent 3ca24a6476
commit 71d80a08d2
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 30 additions and 25 deletions

View file

@ -18,6 +18,33 @@ pub fn zig_executable() -> String {
}
}
#[allow(dead_code)]
pub(crate) fn src_hash(src: &str) -> u64 {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let mut hash_state = DefaultHasher::new();
src.hash(&mut hash_state);
hash_state.finish()
}
#[allow(dead_code)]
pub(crate) fn save_wasm_file(app_module_bytes: &[u8], build_dir_hash: u64) {
use std::path::Path;
let debug_dir_str = format!("/tmp/roc/gen_wasm/{:016x}", build_dir_hash);
let debug_dir_path = Path::new(&debug_dir_str);
let final_wasm_file = debug_dir_path.join("final.wasm");
std::fs::create_dir_all(debug_dir_path).unwrap();
std::fs::write(&final_wasm_file, app_module_bytes).unwrap();
println!(
"Debug command:\n\twasm-objdump -dx {}",
final_wasm_file.to_str().unwrap()
);
}
/// Used in the with_larger_debug_stack() function, for tests that otherwise
/// run out of stack space in debug builds (but don't in --release builds)
#[allow(dead_code)]

View file

@ -5,10 +5,8 @@ use roc_gen_wasm::wasm32_result::Wasm32Result;
use roc_gen_wasm::wasm_module::{Export, ExportType};
use roc_gen_wasm::DEBUG_SETTINGS;
use roc_load::Threading;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Mutex;
use wasm3::{Environment, Module, Runtime};
@ -49,19 +47,13 @@ pub fn compile_to_wasm_bytes<'a, T: Wasm32Result>(
compile_roc_to_wasm_bytes(arena, platform_bytes, src, test_wrapper_type_info);
if DEBUG_SETTINGS.keep_test_binary {
let build_dir_hash = src_hash(src);
save_wasm_file(&compiled_bytes, build_dir_hash)
let build_dir_hash = crate::helpers::src_hash(src);
crate::helpers::save_wasm_file(&compiled_bytes, build_dir_hash)
};
compiled_bytes
}
fn src_hash(src: &str) -> u64 {
let mut hash_state = DefaultHasher::new();
src.hash(&mut hash_state);
hash_state.finish()
}
fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
arena: &'a bumpalo::Bump,
host_bytes: &[u8],
@ -155,20 +147,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
app_module_bytes
}
fn save_wasm_file(app_module_bytes: &[u8], build_dir_hash: u64) {
let debug_dir_str = format!("/tmp/roc/gen_wasm/{:016x}", build_dir_hash);
let debug_dir_path = Path::new(&debug_dir_str);
let final_wasm_file = debug_dir_path.join("final.wasm");
std::fs::create_dir_all(debug_dir_path).unwrap();
std::fs::write(&final_wasm_file, app_module_bytes).unwrap();
println!(
"Debug command:\n\twasm-objdump -dx {}",
final_wasm_file.to_str().unwrap()
);
}
#[allow(dead_code)]
pub fn assert_evals_to_help<T>(src: &str, phantom: PhantomData<T>) -> Result<T, String>
where