Skip to content

Commit

Permalink
rust: move config files to src/rust
Browse files Browse the repository at this point in the history
It was in the root before because .cargo/config would not be resolved:

rust-lang/cargo#2930

Changing the working directory fixes it.

Putting those files to src/rust is good to keep it close to the rust
code.

This also allows to add another Rust project in e.g. /tools, with a
different config.
  • Loading branch information
benma committed Jun 28, 2020
1 parent 0668586 commit 4bdfdd2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
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/gh.neting.cc-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/gh.neting.cc-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"
File renamed without changes.

0 comments on commit 4bdfdd2

Please sign in to comment.