Skip to content

Commit 391260c

Browse files
Detect target. enable flags only for rv32
1 parent 6b43416 commit 391260c

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

secp256k1-sys/build.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,25 @@ fn main() {
3939
// TODO these three should be changed to use libgmp, at least until secp PR 290 is merged
4040
.define("USE_NUM_NONE", Some("1"))
4141
.define("USE_FIELD_INV_BUILTIN", Some("1"))
42-
.define("USE_SCALAR_INV_BUILTIN", Some("1"))
43-
.compiler("/usr/local/opt/llvm/bin/clang")
44-
.flag("--sysroot=/opt/riscv/riscv32-unknown-elf") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
45-
.flag("--gcc-toolchain=/opt/riscv") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
46-
.no_default_flags(true)
47-
.flag("-O3")
48-
.flag("--target=riscv32-unknown-none-elf")
49-
.flag("-mabi=ilp32")
50-
.flag("-mcmodel=medany")
51-
.flag("-Os")
52-
.flag("-fdata-sections")
53-
.flag("-ffunction-sections")
54-
.flag("-dead_strip")
55-
.flag("-flto")
56-
.flag("-march=rv32im")
57-
.target("riscv32-unknown-none-elf");
42+
.define("USE_SCALAR_INV_BUILTIN", Some("1"));
43+
44+
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "riscv32" {
45+
base_config.compiler("/usr/local/opt/llvm/bin/clang")
46+
.flag("--sysroot=/opt/riscv/riscv32-unknown-elf") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
47+
.flag("--gcc-toolchain=/opt/riscv") // https://github.com/riscv-collab/riscv-gnu-toolchain has been built and stored in /opt/riscv
48+
.no_default_flags(true)
49+
.flag("-O3")
50+
.flag("--target=riscv32-unknown-none-elf")
51+
.flag("-mabi=ilp32")
52+
.flag("-mcmodel=medany")
53+
.flag("-Os")
54+
.flag("-fdata-sections")
55+
.flag("-ffunction-sections")
56+
.flag("-dead_strip")
57+
.flag("-flto")
58+
.flag("-march=rv32im")
59+
.target("riscv32-unknown-none-elf");
60+
}
5861

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

0 commit comments

Comments
 (0)