Skip to content

Commit 3200e17

Browse files
committed
Merge remote-tracking branch 'benma/rust-config'
2 parents 9729368 + 1058353 commit 3200e17

File tree

7 files changed

+25
-41
lines changed

7 files changed

+25
-41
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ ENV PATH /opt/lcov-1.14/bin:$PATH
125125
# Install rust compiler
126126
ENV PATH /opt/cargo/bin:$PATH
127127
ENV RUSTUP_HOME=/opt/rustup
128-
COPY rust-toolchain /tmp/rust-toolchain
128+
COPY src/rust/rust-toolchain /tmp/rust-toolchain
129129
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/cargo sh -s -- --default-toolchain $(cat /tmp/rust-toolchain | tr -d '\r\n\t') -y
130130
RUN rustup target add thumbv7em-none-eabi
131131
RUN rustup component add rustfmt

src/CMakeLists.txt

+23-21
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,15 @@ if(NOT CMAKE_CROSSCOMPILING)
403403
# see src/rust/bitbox02-rust-c/src/lib.rs.
404404
# https://github.com/rust-lang/rust/issues/66740
405405
RUSTC_BOOTSTRAP=1
406-
${CARGO} test --all-features --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG}
406+
${CARGO} test --all-features --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG}
407+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rust/
407408
)
408409
add_dependencies(rust-test rust-bindgen)
409410

410411
add_custom_target(rust-clippy
411412
COMMAND
412413
# Force clippy to fully re-run. It is bad at figuring out when to run again and when to use caches.
413-
${CARGO} clean --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml --target-dir ${RUST_BINARY_DIR}
414+
${CARGO} clean --target-dir ${RUST_BINARY_DIR}
414415
COMMAND
415416
${CMAKE_COMMAND} -E env
416417
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
@@ -420,7 +421,6 @@ if(NOT CMAKE_CROSSCOMPILING)
420421
RUSTC_BOOTSTRAP=1
421422
${CARGO} clippy
422423
--all-features
423-
--manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml
424424
--target-dir ${RUST_BINARY_DIR}
425425
--release
426426
-- # disabled linters:
@@ -431,7 +431,7 @@ if(NOT CMAKE_CROSSCOMPILING)
431431
-A clippy::single_match
432432
-A clippy::iter_nth_zero
433433
-A clippy::redundant_clone
434-
434+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rust/
435435
)
436436
add_dependencies(rust-clippy rust-bindgen)
437437
endif()
@@ -477,25 +477,26 @@ foreach(type ${RUST_LIBS})
477477
add_custom_target(${type}-rust
478478
# Build rust library
479479
COMMAND
480-
${CMAKE_COMMAND} -E env
481-
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
482-
RUSTFLAGS=${RUSTFLAGS}
483-
# enable nightly features in the stable release - needed to activate alloc_error_handler.
484-
# see src/rust/bitbox02-rust-c/src/lib.rs.
485-
# https://github.com/rust-lang/rust/issues/66740
486-
RUSTC_BOOTSTRAP=1
487-
${CARGO} build --manifest-path ${LIBBITBOX02_RUST_SOURCE_DIR}/Cargo.toml --features target-${type} --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
488-
# Rust packages stdlib functions which we must remove/weaken on the arm target
489-
# Currently the removed symbols only clash in device-tests for some reason. Without this command, compiling device tests would result in errors like:
490-
# Linking C executable ../../bin/fw_test_usb_cmd_process.elf
491-
# /usr/local/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /usr/local/bin/../lib/gcc/arm-none-eabi/8.2.1/thumb/v7e-m+fp/softfp/libgcc.a(_arm_addsubdf3.o): in function `__aeabi_dsub':
492-
# (.text+0x8): multiple definition of `__aeabi_dsub'; ../../lib/libfirmware_rust_c.a(compiler_builtins-5829be534503bd8e.compiler_builtins.cthmhl66-cgu.175.rcgu.o):/cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.27/src/macros.rs:226: first defined here
480+
${CMAKE_COMMAND} -E env
481+
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
482+
RUSTFLAGS=${RUSTFLAGS}
483+
# enable nightly features in the stable release - needed to activate alloc_error_handler.
484+
# see src/rust/bitbox02-rust-c/src/lib.rs.
485+
# https://github.com/rust-lang/rust/issues/66740
486+
RUSTC_BOOTSTRAP=1
487+
${CARGO} build -v --features target-${type} --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
493488
COMMAND
494-
if test "x${RUST_TARGET_ARCH}" = "xthumbv7em-none-eabi" \; then ${CMAKE_OBJCOPY} -W __aeabi_dsub -W __aeabi_dadd -W__aeabi_i2d -W __aeabi_f2d -W __aeabi_dmul ${lib} \; fi
489+
# Rust packages stdlib functions which we must remove/weaken on the arm target
490+
# Currently the removed symbols only clash in device-tests for some reason. Without this command, compiling device tests would result in errors like:
491+
# Linking C executable ../../bin/fw_test_usb_cmd_process.elf
492+
# /usr/local/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /usr/local/bin/../lib/gcc/arm-none-eabi/8.2.1/thumb/v7e-m+fp/softfp/libgcc.a(_arm_addsubdf3.o): in function `__aeabi_dsub':
493+
# (.text+0x8): multiple definition of `__aeabi_dsub'; ../../lib/libfirmware_rust_c.a(compiler_builtins-5829be534503bd8e.compiler_builtins.cthmhl66-cgu.175.rcgu.o):/cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.27/src/macros.rs:226: first defined here
494+
if test "x${RUST_TARGET_ARCH}" = "xthumbv7em-none-eabi" \; then ${CMAKE_OBJCOPY} -W __aeabi_dsub -W __aeabi_dadd -W__aeabi_i2d -W __aeabi_f2d -W __aeabi_dmul ${lib} \; fi
495495
COMMAND
496-
${CMAKE_COMMAND} -E copy ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
496+
${CMAKE_COMMAND} -E copy ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
497497
BYPRODUCTS
498-
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
498+
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
499+
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
499500
)
500501
add_dependencies(${type}-rust rust-bindgen rust-cbindgen)
501502
add_library(${type}_rust_c STATIC IMPORTED)
@@ -515,9 +516,10 @@ if(CMAKE_CROSSCOMPILING)
515516
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
516517
SYSROOT=${CMAKE_SYSROOT}
517518
INCLUDES="${RUST_INCLUDES}"
518-
${CARGO} doc --document-private-items --manifest-path ${LIBBITBOX02_RUST_SOURCE_DIR}/Cargo.toml --target-dir ${CMAKE_BINARY_DIR}/docs-rust ${RUST_CARGO_FLAG} --target thumbv7em-none-eabi
519+
${CARGO} doc --document-private-items --target-dir ${CMAKE_BINARY_DIR}/docs-rust ${RUST_CARGO_FLAG} --target thumbv7em-none-eabi
519520
COMMAND
520521
${CMAKE_COMMAND} -E echo "See docs at file://${CMAKE_BINARY_DIR}/docs-rust/thumbv7em-none-eabi/doc/bitbox02_rust/index.html"
522+
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
521523
)
522524
add_dependencies(rust-docs rust-bindgen)
523525

.cargo/config renamed to src/rust/.cargo/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
replace-with = "vendored-sources"
33

44
[source.vendored-sources]
5-
directory = "src/rust/vendor"
5+
directory = "vendor"

src/rust/bitbox02-rust-c/Cargo.toml

-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@ license = "Apache-2.0"
2222
[lib]
2323
crate-type = ["staticlib"]
2424

25-
[profile.release]
26-
debug = true
27-
opt-level = 'z'
28-
codegen-units = 1
29-
panic = 'abort'
30-
lto = true
31-
32-
[profile.dev]
33-
opt-level = 'z'
34-
3525
[dependencies]
3626
bitbox02-rust = { path = "../bitbox02-rust" }
3727
bitbox02 = { path = "../bitbox02" }

src/rust/bitbox02-sys/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ edition = "2018"
2020
description = "Rust bindings for C code in bitbox02-firmware"
2121
license = "Apache-2.0"
2222

23-
[profile.dev]
24-
opt-level = 'z'
25-
panic = 'abort'
26-
2723
[dependencies]
2824
util = {path = "../util"}

src/rust/bitbox02/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ edition = "2018"
2020
description = "Idiomatic rust bindings for C code in bitbox02-firmware"
2121
license = "Apache-2.0"
2222

23-
[profile.dev]
24-
opt-level = 'z'
25-
panic = 'abort'
26-
2723
[dependencies]
2824
bitbox02-sys = {path="../bitbox02-sys"}
2925
util = {path = "../util"}
File renamed without changes.

0 commit comments

Comments
 (0)