mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge branch 'trunk' into zig9-to-zig
This commit is contained in:
commit
56c7318cd9
9 changed files with 82 additions and 21 deletions
|
@ -193,7 +193,10 @@ pub fn helper(
|
|||
app_o_file.clone(),
|
||||
// Long term we probably want a smarter way to link in zig builtins.
|
||||
// With the current method all methods are kept and it adds about 100k to all outputs.
|
||||
&[app_o_file.to_str().unwrap(), bitcode::OBJ_PATH],
|
||||
&[
|
||||
app_o_file.to_str().unwrap(),
|
||||
bitcode::BUILTINS_HOST_OBJ_PATH,
|
||||
],
|
||||
LinkType::Dylib,
|
||||
)
|
||||
.expect("failed to link dynamic library");
|
||||
|
|
|
@ -4,8 +4,12 @@ use std::hash::{Hash, Hasher};
|
|||
|
||||
use crate::helpers::from_wasm32_memory::FromWasm32Memory;
|
||||
use crate::helpers::wasm32_test_result::Wasm32TestResult;
|
||||
use roc_builtins::bitcode;
|
||||
use roc_can::builtins::builtin_defs_map;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_gen_wasm::MEMORY_NAME;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
const TEST_WRAPPER_NAME: &str = "test_wrapper";
|
||||
|
||||
|
@ -143,8 +147,43 @@ pub fn helper_wasm<'a, T: Wasm32TestResult>(
|
|||
use wasmer::{Instance, Module, Store};
|
||||
|
||||
let store = Store::default();
|
||||
// let module = Module::from_file(&store, &test_wasm_path).unwrap();
|
||||
let wasmer_module = Module::from_binary(&store, &module_bytes).unwrap();
|
||||
|
||||
let wasmer_module = {
|
||||
let dir = tempdir().unwrap();
|
||||
let dirpath = dir.path();
|
||||
let final_wasm_file = dirpath.join("final.wasm");
|
||||
let app_o_file = dirpath.join("app.o");
|
||||
|
||||
// write the module to a file so the linker can access it
|
||||
std::fs::write(&app_o_file, &module_bytes).unwrap();
|
||||
|
||||
std::process::Command::new("zig")
|
||||
.args(&[
|
||||
"wasm-ld",
|
||||
// input files
|
||||
app_o_file.to_str().unwrap(),
|
||||
bitcode::BUILTINS_WASM32_OBJ_PATH,
|
||||
// output
|
||||
"-o",
|
||||
final_wasm_file.to_str().unwrap(),
|
||||
// we don't define `_start`
|
||||
"--no-entry",
|
||||
// If you only specify test_wrapper, it will stop at the call to UserApp_main_1
|
||||
// But if you specify both exports, you get all the dependencies.
|
||||
//
|
||||
// It seems that it will not write out an export you didn't explicitly specify,
|
||||
// even if it's a dependency of another export!
|
||||
// In our case we always export main and test_wrapper so that's OK.
|
||||
"--export",
|
||||
"test_wrapper",
|
||||
"--export",
|
||||
"#UserApp_main_1",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
Module::from_file(&store, &final_wasm_file).unwrap()
|
||||
};
|
||||
|
||||
// First, we create the `WasiEnv`
|
||||
use wasmer_wasi::WasiState;
|
||||
|
@ -171,7 +210,7 @@ where
|
|||
|
||||
let instance = crate::helpers::wasm::helper_wasm(&arena, src, stdlib, &expected);
|
||||
|
||||
let memory = instance.exports.get_memory("__linear_memory").unwrap();
|
||||
let memory = instance.exports.get_memory(MEMORY_NAME).unwrap();
|
||||
|
||||
let test_wrapper = instance.exports.get_function(TEST_WRAPPER_NAME).unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue