mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
remove wasm helpers into the mod for reuse
This commit is contained in:
parent
3ca24a6476
commit
71d80a08d2
2 changed files with 30 additions and 25 deletions
|
@ -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
|
/// 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)
|
/// run out of stack space in debug builds (but don't in --release builds)
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -5,10 +5,8 @@ use roc_gen_wasm::wasm32_result::Wasm32Result;
|
||||||
use roc_gen_wasm::wasm_module::{Export, ExportType};
|
use roc_gen_wasm::wasm_module::{Export, ExportType};
|
||||||
use roc_gen_wasm::DEBUG_SETTINGS;
|
use roc_gen_wasm::DEBUG_SETTINGS;
|
||||||
use roc_load::Threading;
|
use roc_load::Threading;
|
||||||
use std::collections::hash_map::DefaultHasher;
|
|
||||||
use std::hash::{Hash, Hasher};
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wasm3::{Environment, Module, Runtime};
|
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);
|
compile_roc_to_wasm_bytes(arena, platform_bytes, src, test_wrapper_type_info);
|
||||||
|
|
||||||
if DEBUG_SETTINGS.keep_test_binary {
|
if DEBUG_SETTINGS.keep_test_binary {
|
||||||
let build_dir_hash = src_hash(src);
|
let build_dir_hash = crate::helpers::src_hash(src);
|
||||||
save_wasm_file(&compiled_bytes, build_dir_hash)
|
crate::helpers::save_wasm_file(&compiled_bytes, build_dir_hash)
|
||||||
};
|
};
|
||||||
|
|
||||||
compiled_bytes
|
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>(
|
fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
|
||||||
arena: &'a bumpalo::Bump,
|
arena: &'a bumpalo::Bump,
|
||||||
host_bytes: &[u8],
|
host_bytes: &[u8],
|
||||||
|
@ -155,20 +147,6 @@ fn compile_roc_to_wasm_bytes<'a, T: Wasm32Result>(
|
||||||
app_module_bytes
|
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)]
|
#[allow(dead_code)]
|
||||||
pub fn assert_evals_to_help<T>(src: &str, phantom: PhantomData<T>) -> Result<T, String>
|
pub fn assert_evals_to_help<T>(src: &str, phantom: PhantomData<T>) -> Result<T, String>
|
||||||
where
|
where
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue