Skip to content

Commit 0cb5cf2

Browse files
committed
rust: fix vendored compilation of the git dep bip32-ed25519
Somehow, as bip32-ed25519 is a git dep, it was not actually compiled from the local vendor folder but it was checked out into a git repo in ~/.cargo/git/ceckouts and compiled from there. `cargo vendor` helpfully shows what needs to be added to the config.toml so it is used. We add the `--offline` flags to cargo build and cargo metadata to prevent this from happening by accident in the future.
1 parent 4bf0289 commit 0cb5cf2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ else()
213213
# For binary reproducibility, strip path prefixes that can be different depending on environment (e.g. /home/<user>, etc.).
214214
set(RUSTFLAGS "--remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src --remap-path-prefix=$ENV{HOME}=")
215215
endif()
216+
216217
# Use libsecp256k1 that we link ourselves (included via external/libwally-core).
217218
# See https://github.com/rust-bitcoin/rust-secp256k1/tree/7c8270a8506e31731e540fab7ee1abde1f48314e/secp256k1-sys#linking-to-external-symbols
218219
set(RUSTFLAGS "${RUSTFLAGS} --cfg=rust_secp_no_symbol_renaming")
@@ -244,8 +245,19 @@ set(LIBBITBOX02_RUST ${LIBBITBOX02_RUST} PARENT_SCOPE)
244245

245246
# Generate c-headers for the rust library
246247
add_custom_target(rust-cbindgen
248+
# cbindgen can automatically create the metadata, but it does so without the `--offline` flag.
249+
# The workaround is to manually create and pass the metadata.
250+
COMMAND
251+
${CARGO} metadata --offline > ${CMAKE_CURRENT_BINARY_DIR}/rust-metadata
247252
COMMAND
248-
${CBINDGEN} --quiet --config ${CMAKE_CURRENT_SOURCE_DIR}/rust/bitbox02-cbindgen.toml --output ${CMAKE_CURRENT_BINARY_DIR}/rust/rust.h ${LIBBITBOX02_RUST_SOURCE_DIR}
253+
${CBINDGEN}
254+
--quiet
255+
--config ${CMAKE_CURRENT_SOURCE_DIR}/rust/bitbox02-cbindgen.toml
256+
--output ${CMAKE_CURRENT_BINARY_DIR}/rust/rust.h
257+
--profile release
258+
--metadata ${CMAKE_CURRENT_BINARY_DIR}/rust-metadata
259+
${LIBBITBOX02_RUST_SOURCE_DIR}
260+
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
249261
BYPRODUCTS
250262
${CMAKE_CURRENT_BINARY_DIR}/rust/rust.h
251263
)
@@ -511,7 +523,7 @@ foreach(type ${RUST_LIBS})
511523
RUSTFLAGS=${RUSTFLAGS}
512524
FIRMWARE_VERSION_SHORT=${FIRMWARE_VERSION}
513525
$<$<BOOL:${SCCACHE_PROGRAM}>:RUSTC_WRAPPER=${SCCACHE_PROGRAM}>
514-
${CARGO} build $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-v> --features target-${type} --target-dir ${RUST_BINARY_DIR}/feature-${type} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
526+
${CARGO} build $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-vv> --offline --features target-${type} --target-dir ${RUST_BINARY_DIR}/feature-${type} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
515527
COMMAND
516528
${CMAKE_COMMAND} -E copy_if_different ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
517529
# DEPFILES are only supported with the Ninja build tool

src/rust/.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
[source.crates-io]
22
replace-with = "vendored-sources"
33

4+
[source."git+https://github.com/digitalbitbox/rust-bip32-ed25519?tag=v0.1.2"]
5+
git = "https://github.com/digitalbitbox/rust-bip32-ed25519"
6+
tag = "v0.1.2"
7+
replace-with = "vendored-sources"
8+
49
[source.vendored-sources]
510
directory = "vendor"

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ digest = "0.10.6"
3737
zeroize = "1.6.0"
3838
num-bigint = { version = "0.4.3", default-features = false, optional = true }
3939
num-traits = { version = "0.2", default-features = false, optional = true }
40+
# If you change this, also change src/rust/.cargo/config.toml.
4041
bip32-ed25519 = { git = "https://github.com/digitalbitbox/rust-bip32-ed25519", tag = "v0.1.2", optional = true }
4142
bech32 = { version = "0.10.0-beta", default-features = false, optional = true }
4243
blake2 = { version = "0.10.6", default-features = false, optional = true }

0 commit comments

Comments
 (0)