Skip to content
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

Build failed without standard library #208

Closed
gaojiaqi7 opened this issue Sep 23, 2022 · 1 comment · Fixed by #209 or #211
Closed

Build failed without standard library #208

gaojiaqi7 opened this issue Sep 23, 2022 · 1 comment · Fixed by #209 or #211

Comments

@gaojiaqi7
Copy link
Contributor

Hi,

I am trying to use mbedtls in no_std environment with x86_64-unknown-none target without standard library built-in, but I met the following errors when compiling mbedtls:

error[E0277]: the trait bound `rust_alloc::boxed::Box<SavedRawCipher>: Deserialize<'_>` is not satisfied
    --> mbedtls/src/cipher/raw/serde.rs:52:9
     |
52   |         inner_cipher_ctx: Box<SavedRawCipher>
     |         ^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `rust_alloc::boxed::Box<SavedRawCipher>`
     |
     = help: the following other types implement trait `Deserialize<'de>`:
               &'a [u8]
               &'a str
               ()
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
               (T0, T1, T2, T3, T4)
               (T0, T1, T2, T3, T4, T5)
             and 102 others
note: required by a bound in `next_value`
    --> /home/tdvf/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.101/src/de/mod.rs:1845:12
     |
1845 |         V: Deserialize<'de>,
     |            ^^^^^^^^^^^^^^^^ required by this bound in `next_value`

Some errors have detailed explanations: E0277, E0407.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `mbedtls` due to 4 previous errors
error[E0405]: cannot find trait `Default` in this scope
    --> /home/tdvf/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.3.2/src/lib.rs:1831:6
     |
1831 | impl Default for LittleEndian {
     |      ^^^^^^^ not found in this scope
     |
help: consider importing this trait
     |
83   | use core::default::Default;
     |

Some errors have detailed explanations: E0405, E0425, E0463.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `byteorder` due to 173 previous errors

The error message is too long, so I only pasted part of it here.
The build command I'm using is:

cargo build -p mbedtls -Zbuild-std=core,alloc,compiler_builtins --target=x86_64-unknown-none --no-default-features --features="no_std_deps,rdrand"

The same result applies to:

cargo build -p mbedtls -Zbuild-std=core,alloc,compiler_builtins --target=x86_64-unknown-linux-gnu--no-default-features --features="no_std_deps,rdrand"
@gaojiaqi7
Copy link
Contributor Author

gaojiaqi7 commented Sep 23, 2022

From the compiler output, it seems the default features of byteorder should not be enabled and the alloc feature of serde should be enabled under no_std.
https://github.com/BurntSushi/byteorder/blob/master/Cargo.toml#L25

I submitted a pull request #209 trying to fix this error. Please take a review, thanks🙂

@bors bors bot closed this as completed in 7e744d4 Oct 20, 2022
bors bot added a commit that referenced this issue Feb 21, 2023
211: Remove core_io dependency and add alternative interface for no_std environments r=zugzwang a=DrTobe

As already stated in #210, `core_io` "has not been updated for a long time, the latest rust version it supports is 2021-03-25." Since `no_std` usage of `rust-mbedtls` currently depends on `core_io`, this is a major barrier when adopting `rust-mbedtls` in `no_std` environments.

As opposed to #210, I propose to remove any `std::io` replacement altogether because we need a different interface (non `io::Write`, non `io::Read`) for DTLS anyways. So this interface can be used for TLS in `no_std` environments, too, which removes the necessity to have a `std::io` replacement at all. If you think the benefits are worth the effort, a `std::io` replacement could be added optionally with a feature. I have not had a detailed look at `core2` but I found working with `core_io` very limiting, so maybe `core2` could be a better option.

When working on these changes, I have also fixed some other minor issues with `no_std` usage. Specifically, this should also fix #208 (making #209 obsolete) while bringing `rust-mbedtls` to 32 bit targets (specifically the ARM `thumb...` targets commonly found on MCUs).

With the changes presented in this PR, I was finally able to successfully use `rust-mbedtls` on an STM32L452CCUx MCU.

Co-authored-by: Tobias Naumann <tobias.naumann@iml.fraunhofer.de>
bors bot added a commit that referenced this issue Mar 7, 2023
211: Remove core_io dependency and add alternative interface for no_std environments r=zugzwang a=DrTobe

As already stated in #210, `core_io` "has not been updated for a long time, the latest rust version it supports is 2021-03-25." Since `no_std` usage of `rust-mbedtls` currently depends on `core_io`, this is a major barrier when adopting `rust-mbedtls` in `no_std` environments.

As opposed to #210, I propose to remove any `std::io` replacement altogether because we need a different interface (non `io::Write`, non `io::Read`) for DTLS anyways. So this interface can be used for TLS in `no_std` environments, too, which removes the necessity to have a `std::io` replacement at all. If you think the benefits are worth the effort, a `std::io` replacement could be added optionally with a feature. I have not had a detailed look at `core2` but I found working with `core_io` very limiting, so maybe `core2` could be a better option.

When working on these changes, I have also fixed some other minor issues with `no_std` usage. Specifically, this should also fix #208 (making #209 obsolete) while bringing `rust-mbedtls` to 32 bit targets (specifically the ARM `thumb...` targets commonly found on MCUs).

With the changes presented in this PR, I was finally able to successfully use `rust-mbedtls` on an STM32L452CCUx MCU.

Co-authored-by: Tobias Naumann <tobias.naumann@iml.fraunhofer.de>
Co-authored-by: Tobbe <tobias.naumann@iml.fraunhofer.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant