-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor out RISCV support from the guts_api branch
TODO: figure out what environment variable should enable this
- Loading branch information
1 parent
5558fa4
commit f4ffbbc
Showing
5 changed files
with
1,977 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,59 @@ | ||
use std::env; | ||
|
||
fn defined(var: &str) -> bool { | ||
println!("cargo:rerun-if-env-changed={}", var); | ||
env::var_os(var).is_some() | ||
} | ||
|
||
fn is_pure() -> bool { | ||
defined("CARGO_FEATURE_PURE") | ||
} | ||
|
||
fn target_components() -> Vec<String> { | ||
let target = env::var("TARGET").unwrap(); | ||
target.split("-").map(|s| s.to_string()).collect() | ||
} | ||
|
||
fn is_riscv64gc() -> bool { | ||
target_components()[0] == "riscv64gc" | ||
} | ||
|
||
fn new_build() -> cc::Build { | ||
let build = cc::Build::new(); | ||
build | ||
} | ||
|
||
fn build_riscv_rva23u64_assembly() { | ||
println!("cargo:rustc-cfg=blake3_riscv_rva23u64_ffi"); | ||
let mut build = new_build(); | ||
let asm_path = "src/riscv_rva23u64.S"; | ||
build.file(asm_path); | ||
build.flag("--target=riscv64"); | ||
build.flag("-march=rv64gcv_zbb_zvbb1p0"); | ||
build.flag("-menable-experimental-extensions"); | ||
build.compile("blake3_riscv_rva23u64_assembly"); | ||
println!("cargo:rerun-if-changed={asm_path}"); | ||
} | ||
|
||
fn main() { | ||
// TODO: This implementation assumes some bleeding-edge extensions, and it should probably be | ||
// gated by a Cargo feature. | ||
if is_riscv64gc() && !is_pure() { | ||
build_riscv_rva23u64_assembly(); | ||
} | ||
|
||
// The `cc` crate doesn't automatically emit rerun-if directives for the | ||
// environment variables it supports, in particular for $CC. We expect to | ||
// do a lot of benchmarking across different compilers, so we explicitly | ||
// add the variables that we're likely to need. | ||
println!("cargo:rerun-if-env-changed=CC"); | ||
println!("cargo:rerun-if-env-changed=CFLAGS"); | ||
|
||
// Ditto for source files, though these shouldn't change as often. | ||
for file in std::fs::read_dir("../../c").unwrap() { | ||
println!( | ||
"cargo:rerun-if-changed={}", | ||
file.unwrap().path().to_str().expect("utf-8") | ||
); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.