-
Notifications
You must be signed in to change notification settings - Fork 41
vroom #1380
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
Open
wjblanke
wants to merge
5
commits into
main
Choose a base branch
from
avx512wjb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
vroom #1380
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [submodule "vroom"] | ||
| path = vroom | ||
| url = https://github.com/SimonLangowski/VROOM.git | ||
| [submodule "blst-src"] | ||
| path = blst-src | ||
| url = https://github.com/supranational/blst.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| [package] | ||
| name = "blst" | ||
| version = "0.3.16" | ||
| authors = ["sean-sn <sean@supranational.net>"] | ||
| edition = "2018" | ||
| license = "Apache-2.0" | ||
| description = "Bindings for blst BLS12-381 library (with optional VROOM pairing)" | ||
| repository = "https://github.com/supranational/blst" | ||
| categories = ["cryptography"] | ||
| keywords = ["crypto", "bls", "signature", "asm", "wasm"] | ||
| links = "blst" | ||
|
|
||
| [features] | ||
| default = [] | ||
| portable = [] | ||
| force-adx = [] | ||
| no-threads = [] | ||
| serde-secret = ["serde"] | ||
| # Use VROOM's pairing implementation where supported (AVX512 RNS optimizations) | ||
| vroom = [] | ||
|
|
||
| [build-dependencies] | ||
| cc = "1.0" | ||
| [target.'cfg(target_env = "msvc")'.build-dependencies] | ||
| glob = "0.3" | ||
|
|
||
| [dependencies] | ||
| zeroize = { version = "^1.1", features = ["zeroize_derive"] } | ||
| serde = { version = "1.0.152", optional = true } | ||
|
|
||
| [target.'cfg(not(any(target_arch="wasm32", target_os="none", target_os="unknown", target_os="uefi")))'.dependencies] | ||
| threadpool = "^1.8.1" | ||
|
|
||
| [dev-dependencies] | ||
| rand = "0.8" | ||
| rand_chacha = "0.3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| #![allow(unused_imports)] | ||
|
|
||
| extern crate cc; | ||
|
|
||
| use std::env; | ||
| use std::fs; | ||
| use std::io; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| fn copy_dir_all(src: &Path, dst: &Path) -> io::Result<()> { | ||
| fs::create_dir_all(dst)?; | ||
| for entry in fs::read_dir(src)? { | ||
| let entry = entry?; | ||
| let ty = entry.file_type()?; | ||
| let dst_path = dst.join(entry.file_name()); | ||
| if ty.is_dir() { | ||
| copy_dir_all(&entry.path(), &dst_path)?; | ||
| } else { | ||
| fs::copy(entry.path(), dst_path)?; | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn assembly( | ||
| file_vec: &mut Vec<PathBuf>, | ||
| base_dir: &Path, | ||
| _arch: &str, | ||
| _is_msvc: bool, | ||
| ) { | ||
| #[cfg(target_env = "msvc")] | ||
| if _is_msvc { | ||
| let sfx = match _arch { | ||
| "x86_64" => "x86_64", | ||
| "aarch64" => "armv8", | ||
| _ => "unknown", | ||
| }; | ||
| let files = | ||
| glob::glob(&format!("{}/win64/*-{}.asm", base_dir.display(), sfx)) | ||
| .expect("unable to collect assembly files"); | ||
| for file in files { | ||
| file_vec.push(file.unwrap()); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| file_vec.push(base_dir.join("assembly.S")); | ||
| } | ||
|
|
||
| fn main() { | ||
| if env::var("CARGO_FEATURE_SERDE_SECRET").is_ok() { | ||
| println!( | ||
| "cargo:warning=blst: non-production feature serde-secret enabled" | ||
| ); | ||
| } | ||
|
|
||
| let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
| let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); | ||
| let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); | ||
| let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap_or_default(); | ||
|
|
||
| let target_no_std = target_os.eq("none") | ||
| || (target_os.eq("unknown") && target_arch.eq("wasm32")) | ||
| || target_os.eq("uefi") | ||
| || env::var("BLST_TEST_NO_STD").is_ok(); | ||
|
|
||
| if !target_no_std { | ||
| println!("cargo:rustc-cfg=feature=\"std\""); | ||
| if target_arch.eq("wasm32") || target_os.eq("unknown") { | ||
| println!("cargo:rustc-cfg=feature=\"no-threads\""); | ||
| } | ||
| } | ||
| println!("cargo:rerun-if-env-changed=BLST_TEST_NO_STD"); | ||
|
|
||
| let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
| let workspace_root = manifest_dir.parent().and_then(|p| p.parent()); | ||
|
|
||
| if Path::new("libblst.a").exists() { | ||
| println!("cargo:rustc-link-search=."); | ||
| println!("cargo:rustc-link-lib=blst"); | ||
| println!("cargo:rerun-if-changed=libblst.a"); | ||
| return; | ||
| } | ||
|
|
||
| let mut blst_base_dir = manifest_dir.join("blst"); | ||
| if !blst_base_dir.exists() { | ||
| blst_base_dir = workspace_root | ||
| .map(|r| r.join("blst-src")) | ||
| .unwrap_or_else(|| { | ||
| manifest_dir | ||
| .parent() | ||
| .and_then(|dir| dir.parent()) | ||
| .expect("can't access workspace root or blst repo") | ||
| .join("blst-src") | ||
| }); | ||
| } | ||
|
|
||
| // When vroom feature is enabled, build from a staging copy that uses VROOM's pairing.c | ||
| let use_vroom = env::var("CARGO_FEATURE_VROOM").is_ok(); | ||
| if use_vroom { | ||
| if let Some(ws) = workspace_root { | ||
| let vroom_pairing = ws.join("vroom").join("blst").join("pairing.c"); | ||
| let blst_src = ws.join("blst-src"); | ||
| if vroom_pairing.exists() && blst_src.exists() { | ||
| let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
| let staging = out_dir.join("blst_vroom_build"); | ||
| let staging_src = staging.join("src"); | ||
| let staging_build = staging.join("build"); | ||
|
|
||
| println!("cargo:warning=blst: building with VROOM pairing (vroom/blst/pairing.c)"); | ||
| fs::create_dir_all(&staging_src).expect("create staging src"); | ||
| fs::create_dir_all(&staging_build).expect("create staging build"); | ||
|
|
||
| copy_dir_all(&blst_src.join("src"), &staging_src) | ||
| .expect("copy blst src to staging"); | ||
| copy_dir_all(&blst_src.join("build"), &staging_build) | ||
| .expect("copy blst build to staging"); | ||
| fs::copy(&vroom_pairing, staging_src.join("pairing.c")) | ||
| .expect("copy VROOM pairing.c"); | ||
|
|
||
| println!("cargo:rerun-if-changed={}", vroom_pairing.display()); | ||
| blst_base_dir = staging; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !blst_base_dir.exists() { | ||
| panic!( | ||
| "blst source not found at {} (set vroom feature and init submodules, or add blst-src)", | ||
| blst_base_dir.display() | ||
| ); | ||
| } | ||
| println!("Using blst source directory {}", blst_base_dir.display()); | ||
|
|
||
| if target_os.eq("uefi") && env::var("CC").is_err() { | ||
| match std::process::Command::new("clang").arg("--version").output() { | ||
| Ok(_) => env::set_var("CC", "clang"), | ||
| Err(_) => {} | ||
| } | ||
| } | ||
|
|
||
| if target_env.eq("sgx") && env::var("CC").is_err() { | ||
| if let Ok(out) = std::process::Command::new("clang").arg("--version").output() { | ||
| let version = String::from_utf8(out.stdout).unwrap_or_default(); | ||
| if let Some(x) = version.find("clang version ") { | ||
| let x = x + 14; | ||
| let y = version[x..].find('.').unwrap_or(0); | ||
| if version[x..x + y].parse::<i32>().unwrap_or(0) >= 11 { | ||
| env::set_var("CC", "clang"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if target_env.eq("msvc") | ||
| && env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap().eq("32") | ||
| && env::var("CC").is_err() | ||
| { | ||
| if let Ok(out) = | ||
| std::process::Command::new("clang-cl").args(["-m32", "--version"]).output() | ||
| { | ||
| if String::from_utf8(out.stdout).unwrap_or_default() | ||
| .contains("Target: i386-pc-windows-msvc") | ||
| { | ||
| env::set_var("CC", "clang-cl"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let mut cc = cc::Build::new(); | ||
|
|
||
| let c_src_dir = blst_base_dir.join("src"); | ||
| println!("cargo:rerun-if-changed={}", c_src_dir.display()); | ||
| let mut file_vec = vec![c_src_dir.join("server.c")]; | ||
|
|
||
| if target_arch.eq("x86_64") || target_arch.eq("aarch64") { | ||
| let asm_dir = blst_base_dir.join("build"); | ||
| println!("cargo:rerun-if-changed={}", asm_dir.display()); | ||
| assembly( | ||
| &mut file_vec, | ||
| &asm_dir, | ||
| &target_arch, | ||
| cc.get_compiler().is_like_msvc(), | ||
| ); | ||
| } else { | ||
| cc.define("__BLST_NO_ASM__", None); | ||
| } | ||
| match (cfg!(feature = "portable"), cfg!(feature = "force-adx")) { | ||
| (true, false) => { | ||
| if target_arch.eq("x86_64") && target_env.eq("sgx") { | ||
| panic!("'portable' is not supported on SGX target"); | ||
| } | ||
| println!("cargo:warning=blst: compiling in portable mode"); | ||
| cc.define("__BLST_PORTABLE__", None); | ||
| } | ||
| (false, true) => { | ||
| if target_arch.eq("x86_64") { | ||
| cc.define("__ADX__", None); | ||
| } | ||
| } | ||
| (false, false) => { | ||
| if target_arch.eq("x86_64") { | ||
| if target_env.eq("sgx") { | ||
| cc.define("__ADX__", None); | ||
| } else if env::var("CARGO_ENCODED_RUSTFLAGS") | ||
| .unwrap_or_default() | ||
| .contains("target-cpu=") | ||
| { | ||
| let feat_list = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default(); | ||
| let features: Vec<_> = feat_list.split(',').collect(); | ||
| if !features.contains(&"ssse3") { | ||
| cc.define("__BLST_PORTABLE__", None); | ||
| } else if features.contains(&"adx") { | ||
| cc.define("__ADX__", None); | ||
| } | ||
| } else { | ||
| #[cfg(target_arch = "x86_64")] | ||
| if std::is_x86_feature_detected!("adx") { | ||
| cc.define("__ADX__", None); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| (true, true) => panic!("Cannot compile with both `portable` and `force-adx` features"), | ||
| } | ||
| if target_env.eq("msvc") && cc.get_compiler().is_like_msvc() { | ||
| cc.flag("-Zl"); | ||
| } | ||
| cc.flag_if_supported("-mno-avx") | ||
| .flag_if_supported("-fno-builtin") | ||
| .flag_if_supported("-Wno-unused-function") | ||
| .flag_if_supported("-Wno-unused-command-line-argument"); | ||
| if target_arch.eq("wasm32") || target_family.is_empty() { | ||
| cc.flag("-ffreestanding"); | ||
| } | ||
| if target_arch.eq("wasm32") || target_no_std { | ||
| cc.define("SCRATCH_LIMIT", "(45 * 1024)"); | ||
| } | ||
| if target_env.eq("sgx") { | ||
| cc.flag_if_supported("-mlvi-hardening"); | ||
| cc.define("__SGX_LVI_HARDENING__", None); | ||
| cc.define("__BLST_NO_CPUID__", None); | ||
| cc.define("__ELF__", None); | ||
| cc.define("SCRATCH_LIMIT", "(45 * 1024)"); | ||
| } | ||
| if !cfg!(debug_assertions) { | ||
| cc.opt_level(2); | ||
| } | ||
| cc.files(&file_vec).compile("blst"); | ||
|
|
||
| let bindings = blst_base_dir.join("bindings"); | ||
| if bindings.exists() { | ||
| println!("cargo:BINDINGS={}", bindings.to_string_lossy()); | ||
| } | ||
| println!("cargo:C_SRC={}", c_src_dir.to_string_lossy()); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| max_width = 80 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.