This commit is contained in:
Chen Xijun 2022-07-27 15:21:15 +08:00
commit d64afb7a1f
5 changed files with 33 additions and 12 deletions

2
zeroidc/Cargo.lock generated
View file

@ -846,8 +846,6 @@ dependencies = [
[[package]] [[package]]
name = "ring" name = "ring"
version = "0.16.20" version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",

View file

@ -21,3 +21,6 @@ thiserror = "1"
[build-dependencies] [build-dependencies]
cbindgen = "0.20" cbindgen = "0.20"
[patch.crates-io]
ring = { path = "vendor/ring" }

View file

@ -64,7 +64,7 @@ wasm32_c = []
version = "0.3.37" version = "0.3.37"
features = ["Crypto", "Window"] features = ["Crypto", "Window"]
default-features = false default-features = false
[target."cfg(any(target_arch = \"x86\",target_arch = \"x86_64\", all(any(target_arch = \"aarch64\", target_arch = \"arm\"), any(target_os = \"android\", target_os = \"fuchsia\", target_os = \"linux\"))))".dependencies.spin] [target."cfg(any(target_arch = \"x86\",target_arch = \"x86_64\", all(any(target_arch = \"aarch64\", target_arch = \"arm\"), any(target_os = \"android\", target_os = \"fuchsia\", target_os = \"linux\", target_os = \"windows\"))))".dependencies.spin]
version = "0.5.2" version = "0.5.2"
default-features = false default-features = false
[target."cfg(any(target_os = \"android\", target_os = \"linux\"))".dependencies.libc] [target."cfg(any(target_os = \"android\", target_os = \"linux\"))".dependencies.libc]

View file

@ -221,6 +221,7 @@ const ASM_TARGETS: &[(&str, Option<&str>, Option<&str>)] = &[
("aarch64", Some("ios"), Some("ios64")), ("aarch64", Some("ios"), Some("ios64")),
("aarch64", Some("macos"), Some("ios64")), ("aarch64", Some("macos"), Some("ios64")),
("aarch64", None, Some("linux64")), ("aarch64", None, Some("linux64")),
("aarch64", Some(WINDOWS), Some("win64")),
("x86", Some(WINDOWS), Some("win32n")), ("x86", Some(WINDOWS), Some("win32n")),
("x86", Some("ios"), Some("macosx")), ("x86", Some("ios"), Some("macosx")),
("x86", None, Some("elf")), ("x86", None, Some("elf")),
@ -384,7 +385,7 @@ fn build_c_code(target: &Target, pregenerated: PathBuf, out_dir: &Path) {
// For Windows we also pregenerate the object files for non-Git builds so // For Windows we also pregenerate the object files for non-Git builds so
// the user doesn't need to install the assembler. On other platforms we // the user doesn't need to install the assembler. On other platforms we
// assume the C compiler also assembles. // assume the C compiler also assembles.
if use_pregenerated && target.os == WINDOWS { if use_pregenerated && (target.os == WINDOWS && target.arch != "aarch64") {
// The pregenerated object files always use ".obj" as the extension, // The pregenerated object files always use ".obj" as the extension,
// even when the C/C++ compiler outputs files with the ".o" extension. // even when the C/C++ compiler outputs files with the ".o" extension.
asm_srcs = asm_srcs asm_srcs = asm_srcs
@ -503,7 +504,7 @@ fn compile(
let mut out_path = out_dir.join(p.file_name().unwrap()); let mut out_path = out_dir.join(p.file_name().unwrap());
assert!(out_path.set_extension(target.obj_ext)); assert!(out_path.set_extension(target.obj_ext));
if need_run(&p, &out_path, includes_modified) { if need_run(&p, &out_path, includes_modified) {
let cmd = if target.os != WINDOWS || ext != "asm" { let cmd = if !(target.os == WINDOWS && target.arch != "aarch64") || ext != "asm" {
cc(p, ext, target, warnings_are_errors, &out_path) cc(p, ext, target, warnings_are_errors, &out_path)
} else { } else {
nasm(p, &target.arch, &out_path) nasm(p, &target.arch, &out_path)
@ -675,7 +676,7 @@ fn perlasm_src_dsts(
let mut src_dsts = srcs let mut src_dsts = srcs
.iter() .iter()
.filter(|p| is_perlasm(p)) .filter(|p| is_perlasm(p))
.map(|src| (src.clone(), asm_path(out_dir, src, os, perlasm_format))) .map(|src| (src.clone(), asm_path(out_dir, src, arch, os, perlasm_format)))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// Some PerlAsm source files need to be run multiple times with different // Some PerlAsm source files need to be run multiple times with different
@ -688,7 +689,7 @@ fn perlasm_src_dsts(
let synthesized_path = PathBuf::from(synthesized); let synthesized_path = PathBuf::from(synthesized);
src_dsts.push(( src_dsts.push((
concrete_path, concrete_path,
asm_path(out_dir, &synthesized_path, os, perlasm_format), asm_path(out_dir, &synthesized_path, arch, os, perlasm_format),
)) ))
} }
}; };
@ -710,11 +711,11 @@ fn is_perlasm(path: &PathBuf) -> bool {
path.extension().unwrap().to_str().unwrap() == "pl" path.extension().unwrap().to_str().unwrap() == "pl"
} }
fn asm_path(out_dir: &Path, src: &Path, os: Option<&str>, perlasm_format: &str) -> PathBuf { fn asm_path(out_dir: &Path, src: &Path, arch: &str, os: Option<&str>, perlasm_format: &str) -> PathBuf {
let src_stem = src.file_stem().expect("source file without basename"); let src_stem = src.file_stem().expect("source file without basename");
let dst_stem = src_stem.to_str().unwrap(); let dst_stem = src_stem.to_str().unwrap();
let dst_extension = if os == Some("windows") { "asm" } else { "S" }; let dst_extension = if os == Some("windows") && arch != "aarch64" { "asm" } else { "S" };
let dst_filename = format!("{}-{}.{}", dst_stem, perlasm_format, dst_extension); let dst_filename = format!("{}-{}.{}", dst_stem, perlasm_format, dst_extension);
out_dir.join(dst_filename) out_dir.join(dst_filename)
} }

View file

@ -31,7 +31,7 @@ pub(crate) fn features() -> Features {
target_arch = "x86_64", target_arch = "x86_64",
all( all(
any(target_arch = "aarch64", target_arch = "arm"), any(target_arch = "aarch64", target_arch = "arm"),
any(target_os = "android", target_os = "fuchsia", target_os = "linux") any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows")
) )
))] ))]
{ {
@ -49,7 +49,7 @@ pub(crate) fn features() -> Features {
#[cfg(all( #[cfg(all(
any(target_arch = "aarch64", target_arch = "arm"), any(target_arch = "aarch64", target_arch = "arm"),
any(target_os = "android", target_os = "fuchsia", target_os = "linux") any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows")
))] ))]
{ {
arm::setup(); arm::setup();
@ -162,6 +162,25 @@ pub(crate) mod arm {
} }
} }
#[cfg(all(target_os = "windows", target_arch = "aarch64"))]
pub fn setup() {
// We do not need to check for the presence of NEON, as Armv8-A always has it
let mut features = NEON.mask;
let result = unsafe {
winapi::um::processthreadsapi::IsProcessorFeaturePresent(
winapi::um::winnt::PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE,
)
};
if result != 0 {
// These are all covered by one call in Windows
features |= AES.mask;
features |= PMULL.mask;
features |= SHA256.mask;
}
}
macro_rules! features { macro_rules! features {
{ {
$( $(
@ -237,7 +256,7 @@ pub(crate) mod arm {
} }
#[cfg(all( #[cfg(all(
any(target_os = "android", target_os = "fuchsia", target_os = "linux"), any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows"),
any(target_arch = "arm", target_arch = "aarch64") any(target_arch = "arm", target_arch = "aarch64")
))] ))]
{ {