Skip to content

Commit

Permalink
Modify to cross compile for riscv32im
Browse files Browse the repository at this point in the history
* Update C compiler flags for riscv32im
* Detect target. enable flags only for rv32
  • Loading branch information
preston-evans98 authored and citizen-stig committed Mar 19, 2024
1 parent a1d8c90 commit 97d7528
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion secp256k1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ fn main() {
// just #define it away.
.define("printf(...)", Some(""));

if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "riscv32" {
base_config.compiler("/usr/local/opt/llvm/bin/clang")
.flag("--sysroot=/opt/riscv/riscv32-unknown-elf") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
.flag("--gcc-toolchain=/opt/riscv") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
.no_default_flags(true)
.flag("-O3")
.flag("--target=riscv32-unknown-none-elf")
.flag("-mabi=ilp32")
.flag("-mcmodel=medany")
.flag("-Os")
.flag("-fdata-sections")
.flag("-ffunction-sections")
.flag("-dead_strip")
.flag("-flto")
.flag("-march=rv32im")
.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 Expand Up @@ -62,4 +80,3 @@ fn main() {
base_config.compile("libsecp256k1.a");
}
}

0 comments on commit 97d7528

Please sign in to comment.