Skip to content
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

Small change for RISCV compilation #701

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions secp256k1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@ fn main() {
// just #define it away.
.define("printf(...)", Some(""));

if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "riscv32" {
const DEFAULT_RISCV_GNU_TOOLCHAIN: &str = "/opt/riscv";
println!("cargo:rerun-if-env-changed=RISCV_GNU_TOOLCHAIN");

let riscv_gnu_toolchain_path = env::var("RISCV_GNU_TOOLCHAIN").unwrap_or_else(|_| {
println!("cargo:warning=Variable RISCV_GNU_TOOLCHAIN unset. Assuming '{DEFAULT_RISCV_GNU_TOOLCHAIN}'");
println!("cargo:warning=Please make sure to build riscv toolchain:");
println!("cargo:warning= git clone https://github.com/riscv-collab/riscv-gnu-toolchain && cd riscv-gnu-toolchain");
println!("cargo:warning= export RISCV_GNU_TOOLCHAIN={DEFAULT_RISCV_GNU_TOOLCHAIN}");
println!("cargo:warning= configure --prefix=\"$RISCV_GNU_TOOLCHAIN\" --with-arch=rv32im --with-abi=ilp32");
println!("cargo:warning= make -j$(nproc)");

// if unset, try the default and fail eventually
DEFAULT_RISCV_GNU_TOOLCHAIN.into()
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's appropriate to force every RISCV compilation to use the GNU toolchains - are there not other toolchains?


base_config
.compiler("clang")
.no_default_flags(true)
.flag(&format!("--sysroot={riscv_gnu_toolchain_path}/riscv32-unknown-elf"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this is beyond our MSRV.

.flag(&format!("--gcc-toolchain={riscv_gnu_toolchain_path}"))
.flag("--target=riscv32-unknown-none-elf")
.flag("-march=rv32im")
.flag("-mabi=ilp32")
.flag("-mcmodel=medany")
.flag("-Os")
.flag("-fdata-sections")
.flag("-ffunction-sections")
.flag("-flto")
.target("riscv32-unknown-none-elf");
}

if cfg!(feature = "lowmemory") {
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume negligible memory
base_config.define("ECMULT_GEN_PREC_BITS", Some("2"));
Expand Down
Loading