mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 22:28:21 +00:00
Implement caching + add integration test
This commit is contained in:
@@ -199,6 +199,7 @@ impl CreateExe {
|
|||||||
object_format,
|
object_format,
|
||||||
&self.precompiled_atom,
|
&self.precompiled_atom,
|
||||||
AllowMultiWasm::Allow,
|
AllowMultiWasm::Allow,
|
||||||
|
self.debug_dir.is_some(),
|
||||||
)?;
|
)?;
|
||||||
get_module_infos(&tempdir, &atoms)?;
|
get_module_infos(&tempdir, &atoms)?;
|
||||||
let mut entrypoint = get_entrypoint(&tempdir)?;
|
let mut entrypoint = get_entrypoint(&tempdir)?;
|
||||||
@@ -228,6 +229,7 @@ impl CreateExe {
|
|||||||
&self.cpu_features,
|
&self.cpu_features,
|
||||||
object_format,
|
object_format,
|
||||||
&self.precompiled_atom,
|
&self.precompiled_atom,
|
||||||
|
self.debug_dir.is_some(),
|
||||||
)?;
|
)?;
|
||||||
get_module_infos(&tempdir, &atoms)?;
|
get_module_infos(&tempdir, &atoms)?;
|
||||||
let mut entrypoint = get_entrypoint(&tempdir)?;
|
let mut entrypoint = get_entrypoint(&tempdir)?;
|
||||||
@@ -317,6 +319,7 @@ pub(super) fn compile_pirita_into_directory(
|
|||||||
object_format: ObjectFormat,
|
object_format: ObjectFormat,
|
||||||
prefixes: &[String],
|
prefixes: &[String],
|
||||||
allow_multi_wasm: AllowMultiWasm,
|
allow_multi_wasm: AllowMultiWasm,
|
||||||
|
debug: bool,
|
||||||
) -> anyhow::Result<Vec<(String, Vec<u8>)>> {
|
) -> anyhow::Result<Vec<(String, Vec<u8>)>> {
|
||||||
let all_atoms = match &allow_multi_wasm {
|
let all_atoms = match &allow_multi_wasm {
|
||||||
AllowMultiWasm::Allow | AllowMultiWasm::Reject(None) => {
|
AllowMultiWasm::Allow | AllowMultiWasm::Reject(None) => {
|
||||||
@@ -420,6 +423,7 @@ pub(super) fn compile_pirita_into_directory(
|
|||||||
target,
|
target,
|
||||||
object_format,
|
object_format,
|
||||||
&prefix_map,
|
&prefix_map,
|
||||||
|
debug,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// target_dir
|
// target_dir
|
||||||
@@ -678,6 +682,7 @@ fn conpile_atoms(
|
|||||||
target: &Target,
|
target: &Target,
|
||||||
object_format: ObjectFormat,
|
object_format: ObjectFormat,
|
||||||
prefixes: &PrefixMapCompilation,
|
prefixes: &PrefixMapCompilation,
|
||||||
|
debug: bool,
|
||||||
) -> Result<BTreeMap<String, ModuleInfo>, anyhow::Error> {
|
) -> Result<BTreeMap<String, ModuleInfo>, anyhow::Error> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
@@ -688,9 +693,17 @@ fn conpile_atoms(
|
|||||||
let prefix = prefixes
|
let prefix = prefixes
|
||||||
.get_prefix_for_atom(a)
|
.get_prefix_for_atom(a)
|
||||||
.ok_or_else(|| anyhow::anyhow!("no prefix given for atom {a}"))?;
|
.ok_or_else(|| anyhow::anyhow!("no prefix given for atom {a}"))?;
|
||||||
let (store, _) = compiler.get_store_for_target(target.clone())?;
|
|
||||||
let atom_name = utils::normalize_atom_name(a);
|
let atom_name = utils::normalize_atom_name(a);
|
||||||
let output_object_path = output_dir.join(format!("{atom_name}.o"));
|
let output_object_path = output_dir.join(format!("{atom_name}.o"));
|
||||||
|
if let Some(atom) = prefixes.get_compilation_object_for_atom(a) {
|
||||||
|
std::fs::write(&output_object_path, atom)
|
||||||
|
.map_err(|e| anyhow::anyhow!("{}: {e}", output_object_path.display()))?;
|
||||||
|
if debug {
|
||||||
|
println!("cache hit for atom {a:?}");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let (store, _) = compiler.get_store_for_target(target.clone())?;
|
||||||
let module_name = format!("WASMER_{}_METADATA", prefix.to_uppercase());
|
let module_name = format!("WASMER_{}_METADATA", prefix.to_uppercase());
|
||||||
match object_format {
|
match object_format {
|
||||||
ObjectFormat::Symbols => {
|
ObjectFormat::Symbols => {
|
||||||
@@ -829,6 +842,7 @@ pub(super) fn prepare_directory_from_single_wasm_file(
|
|||||||
cpu_features: &[CpuFeature],
|
cpu_features: &[CpuFeature],
|
||||||
object_format: ObjectFormat,
|
object_format: ObjectFormat,
|
||||||
prefix: &[String],
|
prefix: &[String],
|
||||||
|
debug: bool,
|
||||||
) -> anyhow::Result<Vec<(String, Vec<u8>)>, anyhow::Error> {
|
) -> anyhow::Result<Vec<(String, Vec<u8>)>, anyhow::Error> {
|
||||||
let bytes = std::fs::read(wasm_file)?;
|
let bytes = std::fs::read(wasm_file)?;
|
||||||
let target = &utils::target_triple_to_target(triple, cpu_features);
|
let target = &utils::target_triple_to_target(triple, cpu_features);
|
||||||
@@ -870,6 +884,7 @@ pub(super) fn prepare_directory_from_single_wasm_file(
|
|||||||
target,
|
target,
|
||||||
object_format,
|
object_format,
|
||||||
&prefix_map,
|
&prefix_map,
|
||||||
|
debug,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut atoms = Vec::new();
|
let mut atoms = Vec::new();
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ impl CreateObj {
|
|||||||
object_format,
|
object_format,
|
||||||
&prefix,
|
&prefix,
|
||||||
crate::commands::AllowMultiWasm::Reject(self.atom.clone()),
|
crate::commands::AllowMultiWasm::Reject(self.atom.clone()),
|
||||||
|
self.debug_dir.is_some(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
crate::commands::create_exe::prepare_directory_from_single_wasm_file(
|
crate::commands::create_exe::prepare_directory_from_single_wasm_file(
|
||||||
@@ -119,6 +120,7 @@ impl CreateObj {
|
|||||||
&self.cpu_features,
|
&self.cpu_features,
|
||||||
object_format,
|
object_format,
|
||||||
&prefix,
|
&prefix,
|
||||||
|
self.debug_dir.is_some(),
|
||||||
)
|
)
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ fn create_exe_with_object_input(mut args: Vec<String>) -> anyhow::Result<()> {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let executable_path = operating_dir.join("wasm.exe");
|
let executable_path = operating_dir.join("wasm.exe");
|
||||||
|
|
||||||
WasmerCreateExe {
|
let create_exe_stdout = WasmerCreateExe {
|
||||||
current_dir: std::env::current_dir().unwrap(),
|
current_dir: std::env::current_dir().unwrap(),
|
||||||
wasm_path,
|
wasm_path,
|
||||||
native_executable_path: executable_path.clone(),
|
native_executable_path: executable_path.clone(),
|
||||||
@@ -435,6 +435,12 @@ fn create_exe_with_object_input(mut args: Vec<String>) -> anyhow::Result<()> {
|
|||||||
.run()
|
.run()
|
||||||
.context("Failed to create-exe wasm with Wasmer")?;
|
.context("Failed to create-exe wasm with Wasmer")?;
|
||||||
|
|
||||||
|
let create_exe_stdout = std::str::from_utf8(&create_exe_stdout).unwrap();
|
||||||
|
assert!(
|
||||||
|
create_exe_stdout.contains("cache hit for atom \"qjs\""),
|
||||||
|
"missed cache hit"
|
||||||
|
);
|
||||||
|
|
||||||
let result = run_code(
|
let result = run_code(
|
||||||
&operating_dir,
|
&operating_dir,
|
||||||
&executable_path,
|
&executable_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user