-
Notifications
You must be signed in to change notification settings - Fork 723
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
Added support for compiling against wasm32-wasi #1499
Changes from all commits
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 |
---|---|---|
|
@@ -30,6 +30,8 @@ const X86: &str = "x86"; | |
const X86_64: &str = "x86_64"; | ||
const AARCH64: &str = "aarch64"; | ||
const ARM: &str = "arm"; | ||
const WASM32: &str = "wasm32"; | ||
const WASM64: &str = "wasm64"; | ||
|
||
#[rustfmt::skip] | ||
const RING_SRCS: &[(&[&str], &str)] = &[ | ||
|
@@ -41,13 +43,13 @@ const RING_SRCS: &[(&[&str], &str)] = &[ | |
(&[], "crypto/mem.c"), | ||
(&[], "crypto/poly1305/poly1305.c"), | ||
|
||
(&[AARCH64, ARM, X86_64, X86], "crypto/crypto.c"), | ||
(&[AARCH64, ARM, X86_64, X86, WASM32, WASM64], "crypto/crypto.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/ecp_nistz.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p256.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/gfp_p384.c"), | ||
(&[AARCH64, ARM, X86_64, X86], "crypto/fipsmodule/ec/p256.c"), | ||
|
||
(&[X86_64, X86], "crypto/cpu-intel.c"), | ||
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. It doesn't make sense to compile these cpu-intel.c for wasm targets. |
||
(&[X86_64, X86, WASM32, WASM64], "crypto/cpu-intel.c"), | ||
|
||
(&[X86], "crypto/fipsmodule/aes/asm/aesni-x86.pl"), | ||
(&[X86], "crypto/fipsmodule/aes/asm/vpaes-x86.pl"), | ||
|
@@ -64,7 +66,7 @@ const RING_SRCS: &[(&[&str], &str)] = &[ | |
(&[X86_64], "crypto/fipsmodule/ec/asm/p256-x86_64-asm.pl"), | ||
(&[X86_64], "crypto/fipsmodule/modes/asm/aesni-gcm-x86_64.pl"), | ||
(&[X86_64], "crypto/fipsmodule/modes/asm/ghash-x86_64.pl"), | ||
(&[X86_64], "crypto/poly1305/poly1305_vec.c"), | ||
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. All this code is guarded by |
||
(&[X86_64, WASM32, WASM64], "crypto/poly1305/poly1305_vec.c"), | ||
(&[X86_64], SHA512_X86_64), | ||
(&[X86_64], "crypto/cipher_extra/asm/chacha20_poly1305_x86_64.pl"), | ||
|
||
|
@@ -491,6 +493,17 @@ fn build_c_code( | |
); | ||
} | ||
|
||
fn cc_builder() -> cc::Build { | ||
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. Is there a more generic convention for |
||
let mut c = cc::Build::new(); | ||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
if target_os == "wasi" { | ||
let wasi_sdk_path = | ||
&std::env::var("WASI_SDK_DIR").expect("missing environment variable: WASI_SDK_DIR"); | ||
c.flag(format!("--sysroot={}", wasi_sdk_path).as_str()); | ||
} | ||
c | ||
} | ||
|
||
fn build_library( | ||
target: &Target, | ||
out_dir: &Path, | ||
|
@@ -508,7 +521,7 @@ fn build_library( | |
// Rebuild the library if necessary. | ||
let lib_path = PathBuf::from(out_dir).join(format!("lib{}.a", lib_name)); | ||
|
||
let mut c = cc::Build::new(); | ||
let mut c = cc_builder(); | ||
|
||
for f in LD_FLAGS { | ||
let _ = c.flag(f); | ||
|
@@ -568,7 +581,7 @@ fn obj_path(out_dir: &Path, src: &Path) -> PathBuf { | |
} | ||
|
||
fn cc(file: &Path, ext: &str, target: &Target, include_dir: &Path, out_file: &Path) -> Command { | ||
let mut c = cc::Build::new(); | ||
let mut c = cc_builder(); | ||
|
||
// FIXME: On Windows AArch64 we currently must use Clang to compile C code | ||
if target.os == WINDOWS && target.arch == AARCH64 && !c.get_compiler().is_like_clang() { | ||
|
@@ -595,6 +608,7 @@ fn cc(file: &Path, ext: &str, target: &Target, include_dir: &Path, out_file: &Pa | |
&& target.os != "redox" | ||
&& target.os != "windows" | ||
&& target.arch != "wasm32" | ||
&& target.arch != "wasm64" | ||
{ | ||
let _ = c.flag("-fstack-protector"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#![cfg_attr(target_os = "wasi", allow(unused, dead_code))] | ||
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'm not understanding why we suddenly have some code becoming dead code, but this doesn't seem right. |
||
use super::{quic::Sample, Nonce}; | ||
use crate::{ | ||
cpu, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ impl crate::sealed::Sealed for SystemRandom {} | |
any(target_os = "android", target_os = "linux"), | ||
not(feature = "dev_urandom_fallback") | ||
), | ||
target_arch = "wasm32", | ||
target_family = "wasm", | ||
windows | ||
))] | ||
use self::sysrand::fill as fill_impl; | ||
|
@@ -229,6 +229,22 @@ mod sysrand_chunk { | |
} | ||
} | ||
|
||
#[cfg(target_os = "wasi")] | ||
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. All the changes to |
||
mod sysrand_chunk { | ||
use crate::{error}; | ||
|
||
#[inline] | ||
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> { | ||
unsafe { | ||
let base = dest as *mut [u8] as *mut u8; | ||
let len = dest.len(); | ||
wasi::random_get(base, len) | ||
.map(|_| len as usize) | ||
.map_err(|_| error::Unspecified) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(all( | ||
feature = "wasm32_unknown_unknown_js", | ||
target_arch = "wasm32", | ||
|
@@ -285,7 +301,7 @@ mod sysrand_chunk { | |
#[cfg(any( | ||
target_os = "android", | ||
target_os = "linux", | ||
target_arch = "wasm32", | ||
target_family = "wasm", | ||
windows | ||
))] | ||
mod sysrand { | ||
|
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.
The subject of the PR says "wasm32-wasi" but the changes here seem to be trying to also add wasm64-* support. Let's split the changes that are only needed for wasm64 support into a separate PR. That is, let's not switch to
target_family = "wasm"
in this PR.