Skip to content

rust: move config files to src/rust #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ENV PATH /opt/lcov-1.14/bin:$PATH
# Install rust compiler
ENV PATH /opt/cargo/bin:$PATH
ENV RUSTUP_HOME=/opt/rustup
COPY rust-toolchain /tmp/rust-toolchain
COPY src/rust/rust-toolchain /tmp/rust-toolchain
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
RUN rustup target add thumbv7em-none-eabi
RUN rustup component add rustfmt
Expand Down
44 changes: 23 additions & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,15 @@ if(NOT CMAKE_CROSSCOMPILING)
# see src/rust/bitbox02-rust-c/src/lib.rs.
# https://github.com/rust-lang/rust/issues/66740
RUSTC_BOOTSTRAP=1
${CARGO} test --all-features --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG}
${CARGO} test --all-features --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rust/
)
add_dependencies(rust-test rust-bindgen)

add_custom_target(rust-clippy
COMMAND
# Force clippy to fully re-run. It is bad at figuring out when to run again and when to use caches.
${CARGO} clean --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml --target-dir ${RUST_BINARY_DIR}
${CARGO} clean --target-dir ${RUST_BINARY_DIR}
COMMAND
${CMAKE_COMMAND} -E env
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
Expand All @@ -420,7 +421,6 @@ if(NOT CMAKE_CROSSCOMPILING)
RUSTC_BOOTSTRAP=1
${CARGO} clippy
--all-features
--manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml
--target-dir ${RUST_BINARY_DIR}
--release
-- # disabled linters:
Expand All @@ -431,7 +431,7 @@ if(NOT CMAKE_CROSSCOMPILING)
-A clippy::single_match
-A clippy::iter_nth_zero
-A clippy::redundant_clone

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/rust/
)
add_dependencies(rust-clippy rust-bindgen)
endif()
Expand Down Expand Up @@ -477,25 +477,26 @@ foreach(type ${RUST_LIBS})
add_custom_target(${type}-rust
# Build rust library
COMMAND
${CMAKE_COMMAND} -E env
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
RUSTFLAGS=${RUSTFLAGS}
# enable nightly features in the stable release - needed to activate alloc_error_handler.
# see src/rust/bitbox02-rust-c/src/lib.rs.
# https://github.com/rust-lang/rust/issues/66740
RUSTC_BOOTSTRAP=1
${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}
# Rust packages stdlib functions which we must remove/weaken on the arm target
# Currently the removed symbols only clash in device-tests for some reason. Without this command, compiling device tests would result in errors like:
# Linking C executable ../../bin/fw_test_usb_cmd_process.elf
# /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':
# (.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
${CMAKE_COMMAND} -E env
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
RUSTFLAGS=${RUSTFLAGS}
# enable nightly features in the stable release - needed to activate alloc_error_handler.
# see src/rust/bitbox02-rust-c/src/lib.rs.
# https://github.com/rust-lang/rust/issues/66740
RUSTC_BOOTSTRAP=1
${CARGO} build -v --features target-${type} --target-dir ${RUST_BINARY_DIR} ${RUST_CARGO_FLAG} ${RUST_TARGET_ARCH_ARG}
COMMAND
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
# Rust packages stdlib functions which we must remove/weaken on the arm target
# Currently the removed symbols only clash in device-tests for some reason. Without this command, compiling device tests would result in errors like:
# Linking C executable ../../bin/fw_test_usb_cmd_process.elf
# /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':
# (.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
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
COMMAND
${CMAKE_COMMAND} -E copy ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
${CMAKE_COMMAND} -E copy ${lib} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
BYPRODUCTS
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/lib${type}_rust_c.a
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
)
add_dependencies(${type}-rust rust-bindgen rust-cbindgen)
add_library(${type}_rust_c STATIC IMPORTED)
Expand All @@ -515,9 +516,10 @@ if(CMAKE_CROSSCOMPILING)
CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
SYSROOT=${CMAKE_SYSROOT}
INCLUDES="${RUST_INCLUDES}"
${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
${CARGO} doc --document-private-items --target-dir ${CMAKE_BINARY_DIR}/docs-rust ${RUST_CARGO_FLAG} --target thumbv7em-none-eabi
COMMAND
${CMAKE_COMMAND} -E echo "See docs at file://${CMAKE_BINARY_DIR}/docs-rust/thumbv7em-none-eabi/doc/bitbox02_rust/index.html"
WORKING_DIRECTORY ${LIBBITBOX02_RUST_SOURCE_DIR}
)
add_dependencies(rust-docs rust-bindgen)

Expand Down
2 changes: 1 addition & 1 deletion .cargo/config → src/rust/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "src/rust/vendor"
directory = "vendor"
10 changes: 0 additions & 10 deletions src/rust/bitbox02-rust-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ license = "Apache-2.0"
[lib]
crate-type = ["staticlib"]

[profile.release]
debug = true
opt-level = 'z'
codegen-units = 1
panic = 'abort'
lto = true

[profile.dev]
opt-level = 'z'

[dependencies]
bitbox02-rust = { path = "../bitbox02-rust" }
bitbox02 = { path = "../bitbox02" }
Expand Down
4 changes: 0 additions & 4 deletions src/rust/bitbox02-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@ edition = "2018"
description = "Rust bindings for C code in bitbox02-firmware"
license = "Apache-2.0"

[profile.dev]
opt-level = 'z'
panic = 'abort'

[dependencies]
util = {path = "../util"}
4 changes: 0 additions & 4 deletions src/rust/bitbox02/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ edition = "2018"
description = "Idiomatic rust bindings for C code in bitbox02-firmware"
license = "Apache-2.0"

[profile.dev]
opt-level = 'z'
panic = 'abort'

[dependencies]
bitbox02-sys = {path="../bitbox02-sys"}
util = {path = "../util"}
Expand Down
File renamed without changes.