Skip to content

Commit

Permalink
refactor: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit committed Oct 30, 2024
1 parent 72ed1e5 commit 7820c1b
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 144 deletions.
57 changes: 42 additions & 15 deletions rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
message(STATUS "compile rust")

set(CARGO_ARM_TARGET thumbv7em-none-eabihf)
set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust)

find_program(RUST_CARGO_EXECUTABLE cargo)
find_program(BINDGEN_EXE bindgen)
find_program(CBINDGEN_EXE cbindgen)
include(rust_c.cmake)

if(NOT BUILD_TYPE STREQUAL "Simulator")
set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds)
if(BTC_ONLY)
set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware-btc-only)
else()
set(CARGO_FLAG --release --target ${CARGO_ARM_TARGET} -p rust_c --no-default-features --features firmware)
endif()


if(DEFINED DEBUG_MEMORY)
message(STATUS "build with DEBUG_MEMORY")
set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory)
endif()

message(STATUS "cargo build command: " ${CARGO_FLAG})
message(STATUS ${TARGET_PATH})

set(COPY_COMMAND cp ${RUST_DIR}/target/${CARGO_ARM_TARGET}/release/${LIB_NAME} ${TARGET_PATH})

add_custom_target(rust_c ALL
COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG}
COMMAND rustup run nightly-2023-12-01 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG}
COMMAND ${COPY_COMMAND}
WORKING_DIRECTORY ${RUST_DIR}
)
else()
set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds)
endif()
if(BTC_ONLY)
set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator_btc_only)
else()
set(CARGO_FLAG --release -p rust_c --no-default-features --features simulator)
endif()

message(STATUS "build target path: " ${TARGET_PATH})
if(DEFINED DEBUG_MEMORY)
message(STATUS "build with DEBUG_MEMORY")
set(CARGO_FLAG ${CARGO_FLAG} --features debug-memory)
endif()

option(LIB_RUST_C "Set to switch to Compile the RUST_C library" OFF)
message(STATUS "Cargo Flags: ${CARGO_FLAG}")

if(NOT EXISTS ${TARGET_PATH})
file(MAKE_DIRECTORY ${TARGET_PATH})
endif()
set(COPY_COMMAND cp ${RUST_DIR}/target/release/${LIB_NAME} ${TARGET_PATH})

add_subdirectory(rust_c)
add_custom_target(rust_c ALL
COMMAND ${CBINDGEN_EXE} ${CBINDGEN_FLAG}
COMMAND rustup run nightly-2023-12-01 ${RUST_CARGO_EXECUTABLE} build ${CARGO_FLAG}
COMMAND ${COPY_COMMAND}
WORKING_DIRECTORY ${RUST_DIR}
)
endif()
19 changes: 1 addition & 18 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ app_utils = { path = "apps/utils" }
app_wallets = { path = "apps/wallets" }
app_xrp = { path = "apps/xrp" }

aptos_rust_c = { path = "rust_c/src/aptos" }
arweave_rust_c = { path = "rust_c/src/arweave" }
bitcoin_rust_c = { path = "rust_c/src/bitcoin", default-features = false }
cardano_rust_c = { path = "rust_c/src/cardano" }
common_rust_c = { path = "rust_c/src/common", default-features = false }
cosmos_rust_c = { path = "rust_c/src/cosmos" }
ethereum_rust_c = { path = "rust_c/src/ethereum" }
near_rust_c = { path = "rust_c/src/near" }
solana_rust_c = { path = "rust_c/src/solana" }
stellar_rust_c = { path = "rust_c/src/stellar" }
sui_rust_c = { path = "rust_c/src/sui" }
ton_rust_c = { path = "rust_c/src/ton" }
tron_rust_c = { path = "rust_c/src/tron" }
xrp_rust_c = { path = "rust_c/src/xrp" }
wallet_rust_c = { path = "rust_c/src/wallet", default-features = false }
simulator_rust_c = { path = "rust_c/src/simulator", default-features = false }

keystore = { path = "keystore", default-features = false }
tools = { path = "tools" }
sim_qr_reader = { path = "sim_qr_reader" }
Expand Down Expand Up @@ -112,7 +95,7 @@ ur-parse-lib = { git = "https://[email protected]/KeystoneHQ/keystone-sdk-rust.git"
ed25519-bip32-core = { version = "0.1.1", default-features = false }
cryptoxide = "0.4"
arrayref = "0.3.6"
num-bigint-dig = { version = "0.8.2", default-features=false }
num-bigint-dig = { version = "0.8.2", default-features = false }
base64 = { version = "0.11.0", default-features = false, features = ["alloc"] }
unicode-blocks = "0.1.6"
bcs = { git = "https://github.com/KeystoneHQ/bcs.git", tag = "0.1.1" }
Expand Down
38 changes: 38 additions & 0 deletions rust/rust_c.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set(LIB_NAME librust_c.a)

find_program(RUST_CARGO_EXECUTABLE cargo)
find_program(BINDGEN_EXE bindgen)
find_program(CBINDGEN_EXE cbindgen)

if(NOT BUILD_TYPE STREQUAL "Simulator")
set(TARGET_PATH ${CMAKE_BINARY_DIR}/rust-builds)
else()
set(TARGET_PATH ${CMAKE_SOURCE_DIR}/ui_simulator/lib/rust-builds)
endif()

message(STATUS "build target path: " ${TARGET_PATH})

option(LIB_RUST_C "Set to switch to Compile the RUST_C library" OFF)

if(NOT EXISTS ${TARGET_PATH})
file(MAKE_DIRECTORY ${TARGET_PATH})
endif()

set(RUST_DIR ${CMAKE_SOURCE_DIR}/rust)
set(RUST_C_DIR ${RUST_DIR}/rust_c)
set(CARGO_ARM_TARGET thumbv7em-none-eabihf)

if(COMPILE_SIMULATOR)
if(BTC_ONLY)
set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/btc_only.toml)
else()
set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/simulator/multi_coin.toml)
endif()
else()
if(BTC_ONLY)
set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/btc_only.toml)
else()
set(CBINDGEN_CONFIG_PATH ${RUST_C_DIR}/cbindgens/release/multi_coin.toml)
endif()
endif()
set(CBINDGEN_FLAG ${RUST_C_DIR} --config ${CBINDGEN_CONFIG_PATH} --output ${TARGET_PATH}/librust_c.h --lang c)
47 changes: 0 additions & 47 deletions rust/rust_c/CMakeLists.txt

This file was deleted.

38 changes: 21 additions & 17 deletions rust/rust_c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
common_rust_c = { workspace = true, default-features = false, optional = true }
bitcoin_rust_c = { workspace = true, default-features = false, optional = true }
wallet_rust_c = { workspace = true, default-features = false, optional = true }
common_rust_c = { path = "./src/common", optional = true, default-features = false }
bitcoin_rust_c = { path = "./src/bitcoin", default-features = false, optional = true }
wallet_rust_c = { path = "./src/wallet", default-features = false, optional = true }
test_cmd = { path = "./src/test_cmd", default-features = false, optional = true }
simulator_rust_c = { path = "./src/simulator", optional = true, default-features = false }

ethereum_rust_c = { workspace = true, optional = true }
solana_rust_c = { workspace = true, optional = true }
aptos_rust_c = { workspace = true, optional = true }
near_rust_c = { workspace = true, optional = true }
cosmos_rust_c = { workspace = true, optional = true }
cardano_rust_c = { workspace = true, optional = true }
sui_rust_c = { workspace = true, optional = true }
tron_rust_c = { workspace = true, optional = true }
xrp_rust_c = { workspace = true, optional = true }
arweave_rust_c = { workspace = true, optional = true }
stellar_rust_c = { workspace = true, optional = true }
ton_rust_c = { workspace = true, optional = true }
simulator_rust_c = { workspace = true, optional = true, default-features = false }
ethereum_rust_c = { path = "./src/ethereum", optional = true }
solana_rust_c = { path = "./src/solana", optional = true }
aptos_rust_c = { path = "./src/aptos", optional = true }
near_rust_c = { path = "./src/near", optional = true }
cosmos_rust_c = { path = "./src/cosmos", optional = true }
cardano_rust_c = { path = "./src/cardano", optional = true }
sui_rust_c = { path = "./src/sui", optional = true }
tron_rust_c = { path = "./src/tron", optional = true }
xrp_rust_c = { path = "./src/xrp", optional = true }
arweave_rust_c = { path = "./src/arweave", optional = true }
stellar_rust_c = { path = "./src/stellar", optional = true }
ton_rust_c = { path = "./src/ton", optional = true }

cty = { workspace = true }
cstr_core = { workspace = true }
Expand All @@ -35,7 +35,11 @@ crate-type = ["staticlib"]
use-allocator = []
firmware = ["use-allocator", "multi-coins"]
firmware-btc-only = ["use-allocator", "btc-only"]
simulator = ["multi-coins", "sui_rust_c/simulator", "simulator_rust_c/multi-coins"]
simulator = [
"multi-coins",
"sui_rust_c/simulator",
"simulator_rust_c/multi-coins",
]
simulator_btc_only = ["btc-only", "simulator_rust_c/btc-only"]
default = ["simulator"]

Expand Down
7 changes: 0 additions & 7 deletions rust/rust_c/cbindgens/simulator/btc_only.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ after_includes = "#define SIMPLERESPONSE_C_CHAR_MAX_LEN 2048\n#define ADDRESS_MA
parse_deps = true
include = [
"rust_c",
"common_rust_c",
"bitcoin_rust_c",
"wallet_rust_c",
"btc_only_wallet_rust_c",
"test_cmd",
"btc_test_cmd",
"simulator_rust_c"
]
extra_bindings = [
"common_rust_c",
Expand Down
18 changes: 0 additions & 18 deletions rust/rust_c/rust_c.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion rust/rust_c/src/aptos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ app_utils = { workspace = true }
rust_tools = { workspace = true }
cty = { workspace = true }
cstr_core = { workspace = true }
common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }
serde_json = { workspace = true }
hex = { workspace = true }
bitcoin = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rust/rust_c/src/arweave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keystore = { workspace = true }
app_utils = { workspace = true }
app_arweave = { workspace = true }
rust_tools = { workspace = true }
common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }
cty = { workspace = true }
cstr_core = { workspace = true }
serde_json = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rust/rust_c/src/bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bitcoin = { workspace = true }
cryptoxide = { workspace = true }
hex = { workspace = true }

common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = ["default"]
Expand Down
2 changes: 1 addition & 1 deletion rust/rust_c/src/cardano/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ur-registry = { workspace = true }
bitcoin = { workspace = true }
ed25519-bip32-core = { workspace = true }

common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = []
2 changes: 1 addition & 1 deletion rust/rust_c/src/cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ either = { workspace = true }
serde_json = { workspace = true }
ur-registry = { workspace = true }

common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = []
2 changes: 1 addition & 1 deletion rust/rust_c/src/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ur-registry = { workspace = true }
core2 = { workspace = true }
cryptoxide = { workspace = true }
bitcoin = { workspace = true }
common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = []
2 changes: 1 addition & 1 deletion rust/rust_c/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(feature = "use-allocator", no_std)]
#![cfg_attr(feature = "use-allocator", feature(alloc_error_handler))]
#![cfg(feature = "use-allocator")]
#[cfg(feature = "use-allocator")]
extern crate alloc;

#[cfg(feature = "use-allocator")]
Expand Down
2 changes: 1 addition & 1 deletion rust/rust_c/src/near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cstr_core = { workspace = true }
itertools = { workspace = true }
ur-registry = { workspace = true }

common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = []
2 changes: 1 addition & 1 deletion rust/rust_c/src/solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rust_tools = { workspace = true }
cty = { workspace = true }
cstr_core = { workspace = true }
itertools = { workspace = true }
common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }
ur-registry = { workspace = true }
app_utils = { workspace = true }

Expand Down
8 changes: 4 additions & 4 deletions rust/rust_c/src/stellar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2021"
keystore = { workspace = true }
app_utils = { workspace = true }
app_stellar = { workspace = true }
common_rust_c = { workspace = true }
cty = "0.2.2"
cstr_core = "0.2.6"
common_rust_c = { path = "../common" }
cty = { workspace = true }
cstr_core = { workspace = true }
hex = { workspace = true }
ur-registry = { workspace = true }
ur-registry = { workspace = true }
2 changes: 1 addition & 1 deletion rust/rust_c/src/sui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cty = { workspace = true }
cstr_core = { workspace = true }
serde_json = { workspace = true }
ur-registry = { workspace = true }
common_rust_c = { workspace = true }
common_rust_c = { path = "../common" }

[features]
debug-memory = []
Expand Down
4 changes: 2 additions & 2 deletions rust/rust_c/src/test_cmd/src/general_test_cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cty = { workspace = true }
cstr_core = { workspace = true }
hex = { workspace = true }
ur-registry = { workspace = true }
common_rust_c = { workspace = true }
wallet_rust_c = { workspace = true }
common_rust_c = { path = "../../../common" }
wallet_rust_c = { path = "../../../wallet" }

[features]
default = ["multi-coins"]
Expand Down
Loading

0 comments on commit 7820c1b

Please sign in to comment.