This commit is contained in:
Folkert 2021-11-09 20:57:36 +01:00
parent a9d561089a
commit a9ce02799c
6 changed files with 60 additions and 7 deletions

View file

@ -240,7 +240,7 @@ pub fn build_file<'a>(
app_o_file.to_str().unwrap(),
];
if matches!(opt_level, OptLevel::Development) {
inputs.push(bitcode::OBJ_PATH);
inputs.push(bitcode::BUILTINS_HOST_OBJ_PATH);
}
let (mut child, _) = // TODO use lld

View file

@ -97,7 +97,7 @@ pub fn build_zig_host_native(
"build-exe",
"-fPIE",
shared_lib_path.to_str().unwrap(),
bitcode::OBJ_PATH,
bitcode::BUILTINS_HOST_OBJ_PATH,
]);
} else {
command.args(&["build-obj", "-fPIC"]);
@ -282,7 +282,7 @@ pub fn build_c_host_native(
if let Some(shared_lib_path) = shared_lib_path {
command.args(&[
shared_lib_path.to_str().unwrap(),
bitcode::OBJ_PATH,
bitcode::BUILTINS_HOST_OBJ_PATH,
"-fPIE",
"-pie",
"-lm",

View file

@ -1,10 +1,15 @@
use std::ops::Index;
pub const OBJ_PATH: &str = env!(
pub const BUILTINS_HOST_OBJ_PATH: &str = env!(
"BUILTINS_HOST_O",
"Env var BUILTINS_HOST_O not found. Is there a problem with the build script?"
);
pub const BUILTINS_WASM32_OBJ_PATH: &str = env!(
"BUILTINS_WASM32_O",
"Env var BUILTINS_WASM32_O not found. Is there a problem with the build script?"
);
#[derive(Debug, Default)]
pub struct IntrinsicName {
pub options: [&'static str; 14],

View file

@ -78,6 +78,7 @@ impl<'a> WasmBackend<'a> {
},
init: ConstExpr::I32(MEMORY_INIT_SIZE as i32),
};
linker_symbols.push(SymInfo::Global(WasmObjectSymbol::Defined {
flags: 0,
index: 0,

View file

@ -1330,7 +1330,7 @@ fn pow_int() {
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn atan() {
assert_evals_to!("Num.atan 10", 1.4711276743037347, f64);
}

View file

@ -4,9 +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 tempfile::tempdir;
const TEST_WRAPPER_NAME: &str = "test_wrapper";
std::thread_local! {
@ -143,8 +146,52 @@ 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 = Module::from_binary(&store, &module_bytes).unwrap();
let wasmer_module = if false {
let dir = tempdir().unwrap();
// let dirpath = dir.path();
let dirpath = PathBuf::from("/home/folkertdev/roc/wasm");
let app_o_file = dirpath.join("app.wasm");
let final_wasm_file = dirpath.join("final.wasm");
std::fs::write(&app_o_file, &module_bytes).unwrap();
dbg!(bitcode::BUILTINS_WASM32_OBJ_PATH);
dbg!(&final_wasm_file);
dbg!(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",
// "--export",
// "__linear_memory",
])
.output())
.unwrap();
Module::from_file(&store, &final_wasm_file).unwrap()
} else {
Module::from_binary(&store, &module_bytes).unwrap()
};
// First, we create the `WasiEnv`
use wasmer_wasi::WasiState;