building secp256k1-sys for RISCV

This commit is contained in:
Evan Feenstra
2022-05-27 21:33:06 -07:00
parent ce45eccde3
commit e5b53d33e3
4 changed files with 67 additions and 10 deletions

View File

@@ -26,3 +26,60 @@ brew tap riscv-software-src/riscv
brew install riscv-tools
```
### path
CC=/usr/local/Cellar/riscv-gnu-toolchain/main/bin/riscv64-unknown-elf-gcc cargo build --target=riscv32imc-esp-espidf
CC=/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc-8.4.0 cargo build --target=riscv32imc-esp-espidf
### point to local dep
```sh
git clone https://github.com/devrandom/rust-secp256k1.git secp256k1
cd secp256k1
checkout 4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71
cd secp256k1-sys
```
rust-toolchain.toml:
```yaml
[toolchain]
channel = "nightly"
```
.cargo/config.toml
```yaml
[build]
target = "riscv32imc-esp-espidf"
[target.riscv32imc-esp-espidf]
linker = "ldproxy"
rustflags = ["-C", "default-linker-libraries"]
[unstable]
build-std = ["std", "panic_abort"]
[env]
ESP_IDF_VERSION = { value = "branch:release/v4.4" }
```
in build.rs:
```rs
// Actual build
let mut base_config = cc::Build::new();
// add this with your path to embuild gcc:
base_config.compiler(std::path::PathBuf::from(
"/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc"
));
```
and use path dep in Cargo.toml
```yaml
secp256k1-sys = { path = "../../secp256k1/secp256k1-sys" }
```

View File

@@ -1,15 +1,6 @@
[build]
target = "riscv32imc-esp-espidf"
[target.xtensa-esp32-espidf]
linker = "ldproxy"
[target.xtensa-esp32s2-espidf]
linker = "ldproxy"
[target.xtensa-esp32s3-espidf]
linker = "ldproxy"
[target.riscv32imc-esp-espidf]
linker = "ldproxy"
@@ -17,6 +8,11 @@ linker = "ldproxy"
# See also https://github.com/ivmarkov/embuild/issues/16
rustflags = ["-C", "default-linker-libraries"]
# [target.riscv32imc-esp-espidf.rustsecp256k1_v0_5_0]
# linker = "/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc"
# rustc-link-search = ["/Users/evanfeenstra/code/sphinx-key/rust-secp256k1/target/riscv32imc-esp-espidf/debug/libsecp256k1_sys.rlib"]
# rustc-link-lib = ["rustsecp256k1_v0_5_0"]
[unstable]
build-std = ["std", "panic_abort"]

View File

@@ -17,7 +17,8 @@ pio = ["esp-idf-sys/pio"]
[dependencies]
esp-idf-sys = { version = "0.31.5", features = ["binstart"] }
vls-protocol-signer = { path = "../../validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["secp-lowmemory"] }
# vls-protocol-signer = { path = "../../validating-lightning-signer/vls-protocol-signer", features = ["secp-lowmemory"] }
secp256k1-sys = { path = "../../rust-secp256k1/secp256k1-sys" }
[build-dependencies]
embuild = "0.29"

View File

@@ -1,9 +1,12 @@
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported
// use vls_protocol_signer;
fn main() {
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
esp_idf_sys::link_patches();
let mut parity: secp256k1_sys::types::c_int = 0;
println!("Hello, world!");
}