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,32 +214,47 @@ 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 */
.arg(&c_src_path) let compilation = Command::new("cc")
.arg(&format!("-L{}", libwasmer_path.display())) .arg("-c")
.arg(&format!("-I{}", get_wasmer_include_directory()?.display())) .arg(&c_src_path)
.arg(&format!("-l:{}", lib_filename)) .arg(if linkcode.optimization_flag.is_empty() {
// Add libraries required per platform. "-O2"
// We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers. } else {
//#[cfg(windows)] linkcode.optimization_flag.as_str()
// .arg("-luserenv") })
// .arg("-lWs2_32") .arg(&format!("-L{}", libwasmer_path.display()))
// .arg("-ladvapi32") .arg(&format!("-I{}", get_wasmer_include_directory()?.display()))
// .arg("-lbcrypt") //.arg(&format!("-l:{}", lib_filename))
// On unix we need dlopen-related symbols, libmath for a few things, and pthreads. .arg("-lwasmer")
//#[cfg(not(windows))] // Add libraries required per platform.
.arg("-ldl") // We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers.
.arg("-lm") //#[cfg(windows)]
.arg("-pthread") // .arg("-luserenv")
//.arg(&format!("-I{}", header_code_path.display())) // .arg("-lWs2_32")
.arg("-o") // .arg("-ladvapi32")
.arg(&output_path) // .arg("-lbcrypt")
.output()? // On unix we need dlopen-related symbols, libmath for a few things, and pthreads.
); //#[cfg(not(windows))]
.arg("-ldl")
.arg("-lm")
.arg("-pthread")
.arg(&format!("-I{}", header_code_path.display()))
.arg("-v")
.arg("-o")
.arg("main_obj.obj")
.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(),
)); ));