Fix linking for --object-format serialized

This commit is contained in:
Felix Schütt
2022-12-23 15:04:06 +01:00
parent acdc7e2498
commit 358296f353

View File

@@ -405,7 +405,6 @@ fn conpile_atoms(
}
/// Compile the C code.
#[allow(dead_code)]
fn run_c_compile(path_to_c_src: &Path, output_name: &Path, target: &Triple) -> anyhow::Result<()> {
#[cfg(not(windows))]
let c_compiler = "cc";
@@ -657,15 +656,17 @@ fn link_exe_from_dir(
directory.display()
)
})?;
link_c_compilation()
} else {
Err(anyhow::anyhow!(
return Err(anyhow::anyhow!(
"ObjectFormat::Serialized + cross compilation not implemented"
))
));
}
}
ObjectFormat::Symbols => {
ObjectFormat::Symbols => {}
}
// compilation done, now link
let zig_binary_path = cross_compilation.zig_binary_path.as_ref().ok_or_else(|| {
anyhow::anyhow!(
"could not write wasmer_main.c in dir {}",
@@ -713,7 +714,15 @@ fn link_exe_from_dir(
cmd.arg(&format!("-femit-bin={}", out_path.display()));
cmd.args(&object_paths);
cmd.arg(&library_path);
cmd.arg(directory.join("wasmer_main.c").canonicalize().unwrap());
cmd.arg(
directory
.join(match entrypoint.object_format {
ObjectFormat::Serialized => "wasmer_main.o",
ObjectFormat::Symbols => "wasmer_main.c",
})
.canonicalize()
.expect("could not find wasmer_main.c / wasmer_main.o"),
);
if zig_triple.contains("windows") {
let mut winsdk_path = library_path.clone();
@@ -753,14 +762,6 @@ fn link_exe_from_dir(
)
})?;
Ok(())
}
}
}
/// Link compiled objects together using the system linker
fn link_c_compilation() -> Result<(), anyhow::Error> {
// TODO
Ok(())
}
@@ -771,12 +772,8 @@ fn generate_wasmer_main_c(entrypoint: &Entrypoint) -> Result<String, anyhow::Err
const WASMER_MAIN_C_SOURCE: &str = include_str!("wasmer_create_exe_main.c");
match entrypoint.object_format {
ObjectFormat::Serialized => {
Ok(WASMER_MAIN_C_SOURCE.replace("// WASI_DEFINES", "#define WASI"))
}
ObjectFormat::Symbols => {
let compile_static = true;
let compile_static = entrypoint.object_format == ObjectFormat::Symbols;
// always with compile zig + static_defs.h
let atom_names = entrypoint
.atoms
@@ -794,8 +791,6 @@ fn generate_wasmer_main_c(entrypoint: &Entrypoint) -> Result<String, anyhow::Err
let atom_name_uppercase = atom_name.to_uppercase();
let module_name = format!("WASMER_MODULE_{atom_name_uppercase}");
extra_headers.push(format!("#include \"static_defs_{atom_name}.h\""));
write!(
c_code_to_add,
"
@@ -805,6 +800,8 @@ fn generate_wasmer_main_c(entrypoint: &Entrypoint) -> Result<String, anyhow::Err
)?;
if compile_static {
extra_headers.push(format!("#include \"static_defs_{atom_name}.h\""));
write!(c_code_to_instantiate, "
wasm_module_t *atom_{atom_name} = wasmer_object_module_new_{atom_name}(store, \"{atom_name}\");
if (!atom_{atom_name}) {{
@@ -814,6 +811,7 @@ fn generate_wasmer_main_c(entrypoint: &Entrypoint) -> Result<String, anyhow::Err
}}
")?;
} else {
extra_headers.push(format!("const extern unsigned char {module_name}[];\r\n"));
write!(c_code_to_instantiate, "
wasm_byte_vec_t atom_{atom_name}_byte_vec = {{
.size = {module_name}_LENGTH,
@@ -892,8 +890,6 @@ fn generate_wasmer_main_c(entrypoint: &Entrypoint) -> Result<String, anyhow::Err
)?;
Ok(return_str.replace("// INSTANTIATE_MODULES", &c_code_to_instantiate))
}
}
}
#[allow(dead_code)]
@@ -901,7 +897,6 @@ pub(super) mod utils {
use super::{CrossCompile, CrossCompileSetup};
use anyhow::Context;
use std::env;
use std::path::{Path, PathBuf};
use target_lexicon::{Architecture, OperatingSystem, Triple};
use wasmer_types::{CpuFeature, Target};