diff --git a/src/lib.rs b/src/lib.rs index 51ccfdca..30afd3e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,7 @@ impl Build { fn cmd_make(&self) -> Command { let host = &self.host.as_ref().expect("HOST dir not set")[..]; + let target = &self.target.as_ref().expect("TARGET dir not set")[..]; if host.contains("dragonfly") || host.contains("freebsd") || host.contains("openbsd") @@ -61,7 +62,13 @@ impl Build { { Command::new("gmake") } else { - Command::new("make") + if target.contains("wasm") { + let mut cmd = Command::new("wasimake"); + + std::mem::replace(cmd.arg("make"), Command::new("wasimake")) + } else { + Command::new("make") + } } } @@ -129,10 +136,17 @@ impl Build { let inner_dir = build_dir.join("src"); fs::create_dir_all(&inner_dir).unwrap(); cp_r(&source_dir(), &inner_dir); + let mut program = String::new(); - let perl_program = - env::var("OPENSSL_SRC_PERL").unwrap_or(env::var("PERL").unwrap_or("perl".to_string())); - let mut configure = Command::new(perl_program); + // use wasiconfigure when targeting wasm + if target.contains("wasm") { + program = String::from("wasiconfigure"); + } else { + program = env::var("OPENSSL_SRC_PERL") + .unwrap_or(env::var("PERL").unwrap_or("perl".to_string())); + } + + let mut configure = Command::new(program); configure.arg("./Configure"); if host.contains("pc-windows-gnu") { configure.arg(&format!("--prefix={}", sanitize_sh(&install_dir))); @@ -155,7 +169,7 @@ impl Build { // Avoid multilib-postfix for build targets that specify it .arg("--libdir=lib"); - if cfg!(not(feature = "legacy")) { + if cfg!(not(feature = "legacy")) && !target.contains("wasm") { configure.arg("no-legacy"); } @@ -203,6 +217,21 @@ impl Build { configure.arg("no-stdio"); } + if target.contains("wasm") { + // -no-threads we dont have thread support in WASI + configure.arg("no-threads"); + // -no-sock we dont have sockets in WASI + configure.arg("no-sock"); + configure.arg("no-afalgeng"); + configure.arg("-DOPENSSL_SYS_NETWARE"); + configure.arg("-DSIG_DFL=0"); + configure.arg("-DSIG_IGN=0"); + configure.arg("-DHAVE_FORK=0"); + configure.arg("-DOPENSSL_NO_AFALGENG=1"); + // --with-rand-seed=getrandom (needed to force using getentropy because WASI has no /dev/random or getrandom) + configure.arg("--with-rand-seed=getrandom"); + } + if target.contains("msvc") { // On MSVC we need nasm.exe to compile the assembly files. // ASM compiling will be enabled if nasm.exe is installed, unless