-
Notifications
You must be signed in to change notification settings - Fork 119
Support compiling to wasm32-wasi target #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
37490e4
61fe587
f15d7d7
d700220
8bed287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes these commands are included in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this patch be written without requiring those tools? Without knowing what they do it seems like they could introduce hidden dependencies we aren't aware of. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I dont think so, but this only requires the user to install the wasienv toolchain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I do not want to land this with a dependency on the wasienv toolchain. I don't know why it's necessary as opposed to the standard wasi-sdk. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried compiling using the standard wasi-sdk but it didnt work no matter what i tried, this seems to be the proper way to configure the build for wasi as far as i know. |
||
} 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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this condition here added for wasm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This condition is required for building OpenSSL 1.1.1d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No this repository only has one version of OpenSSL via a submodule, which is currently 3+ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes this repo only contains openssl 3, but right now only OpenSSL 1.1.1d is supported with specific patches for wasm32-wasi, see #113 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that's the case then I don't think this can land right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I will try patching the latest OpenSSL 3 and see if this works with that or not. |
||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some comments for what's going on here for wasm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure |
||
} | ||
|
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can wrap this in a single else if statement