create-exe: fix linking for macos

This commit is contained in:
Manos Pitsidianakis
2022-08-03 13:31:56 +03:00
parent e2de53c0a9
commit 1ad352610a
2 changed files with 49 additions and 29 deletions

View File

@@ -186,14 +186,19 @@ impl CreateExe {
fn link( fn link(
output_path: PathBuf, output_path: PathBuf,
object_path: PathBuf, object_path: PathBuf,
header_code_path: PathBuf, mut header_code_path: PathBuf,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let linkcode = LinkCode {
object_paths: vec![object_path, "main_obj.obj".into()],
output_path,
..Default::default()
};
let c_src_path = Path::new("wasmer_main.c"); let c_src_path = Path::new("wasmer_main.c");
let mut libwasmer_path = get_libwasmer_path()? let mut libwasmer_path = get_libwasmer_path()?
.canonicalize() .canonicalize()
.context("Failed to find libwasmer")?; .context("Failed to find libwasmer")?;
println!("Using libwasmer: {}", libwasmer_path.display()); println!("Using libwasmer: {}", libwasmer_path.display());
let lib_filename = libwasmer_path let _lib_filename = libwasmer_path
.file_name() .file_name()
.unwrap() .unwrap()
.to_str() .to_str()
@@ -209,15 +214,23 @@ fn link(
c_src_file.write_all(WASMER_STATIC_MAIN_C_SOURCE)?; c_src_file.write_all(WASMER_STATIC_MAIN_C_SOURCE)?;
} }
println!( if !header_code_path.is_dir() {
"link output {:?}", header_code_path.pop();
Command::new("cc") }
.arg(&object_path)
.arg(&header_code_path) /* Compile main function */
let compilation = Command::new("cc")
.arg("-c")
.arg(&c_src_path) .arg(&c_src_path)
.arg(if linkcode.optimization_flag.is_empty() {
"-O2"
} else {
linkcode.optimization_flag.as_str()
})
.arg(&format!("-L{}", libwasmer_path.display())) .arg(&format!("-L{}", libwasmer_path.display()))
.arg(&format!("-I{}", get_wasmer_include_directory()?.display())) .arg(&format!("-I{}", get_wasmer_include_directory()?.display()))
.arg(&format!("-l:{}", lib_filename)) //.arg(&format!("-l:{}", lib_filename))
.arg("-lwasmer")
// Add libraries required per platform. // Add libraries required per platform.
// We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers. // We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers.
//#[cfg(windows)] //#[cfg(windows)]
@@ -230,11 +243,18 @@ fn link(
.arg("-ldl") .arg("-ldl")
.arg("-lm") .arg("-lm")
.arg("-pthread") .arg("-pthread")
//.arg(&format!("-I{}", header_code_path.display())) .arg(&format!("-I{}", header_code_path.display()))
.arg("-v")
.arg("-o") .arg("-o")
.arg(&output_path) .arg("main_obj.obj")
.output()? .output()?;
); if !compilation.status.success() {
return Err(anyhow::anyhow!(String::from_utf8_lossy(
&compilation.stderr
)
.to_string()));
}
linkcode.run().context("Failed to link objects together")?;
Ok(()) Ok(())
} }

View File

@@ -205,7 +205,7 @@ impl MetadataHeader {
/// Parses the header and returns the length of the metadata following it. /// Parses the header and returns the length of the metadata following it.
pub fn parse(bytes: &[u8]) -> Result<usize, DeserializeError> { pub fn parse(bytes: &[u8]) -> Result<usize, DeserializeError> {
if bytes.as_ptr() as usize % 16 != 0 { if bytes.as_ptr() as usize % 8 != 0 {
return Err(DeserializeError::CorruptedBinary( return Err(DeserializeError::CorruptedBinary(
"misaligned metadata".to_string(), "misaligned metadata".to_string(),
)); ));