From e5b53d33e36620562bb13dd77cb5ce3f601e0acf Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Fri, 27 May 2022 21:33:06 -0700 Subject: [PATCH] building secp256k1-sys for RISCV --- riscv.md | 57 +++++++++++++++++++++++++++++++++++++++ signer/.cargo/config.toml | 14 ++++------ signer/Cargo.toml | 3 ++- signer/src/main.rs | 3 +++ 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/riscv.md b/riscv.md index e830143..b0c914b 100644 --- a/riscv.md +++ b/riscv.md @@ -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" } +``` diff --git a/signer/.cargo/config.toml b/signer/.cargo/config.toml index 7803996..18e6f62 100644 --- a/signer/.cargo/config.toml +++ b/signer/.cargo/config.toml @@ -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"] diff --git a/signer/Cargo.toml b/signer/Cargo.toml index b39dde9..67aa487 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -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" diff --git a/signer/src/main.rs b/signer/src/main.rs index 2d3bfaf..83be9e4 100644 --- a/signer/src/main.rs +++ b/signer/src/main.rs @@ -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!"); }