Amanieu / cstr_core

Implementation of CStr and CString for no_std environments
Apache License 2.0
41 stars 17 forks source link

Made the memchr dependency optional #21

Closed VictorKoenders closed 3 years ago

VictorKoenders commented 3 years ago

I love cstr_core, however in every embedded project I try to use it, the memchr dependency tries to pull in std and it fails.

I'm not sure why it does this, the use_libc feature should fix this but it doesn't. This compiles:

[dependencies.cstr_core]
git = "https://github.com/victorkoenders/cstr_core"
default-features = false
+ cargo build --target riscv32i-unknown-none-elf
   Compiling esp32c3_test v0.1.0 (/home/trangar/development/rust/esp32c3_test)
    Finished dev [unoptimized + debuginfo] target(s) in 0.62s

And this doesn't:

[dependencies.cstr_core]
git = "https://github.com/victorkoenders/cstr_core"
default-features = false
features = ["use_libc"]
+ cargo build --target riscv32i-unknown-none-elf
    Blocking waiting for file lock on build directory
   Compiling esp32c3_test v0.1.0 (/home/trangar/development/rust/esp32c3_test)
   Compiling memchr v2.4.0
   Compiling riscv-rt v0.8.0
   Compiling esp32c3 v0.1.2
error[E0463]: can't find crate for `std`
  |
  = note: the `riscv32i-unknown-none-elf` target may not support the standard library
  = note: `std` is required by `memchr` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

Since memchr is only used in 2 places, and in my usecase I don't need the performance increase, it would be nice if I could completely disable the memchr dependency.

Amanieu commented 3 years ago

cstr_core shouldn't cause std to be picked up by default. You should disable the use_libc feature to avoid picking up std.

VictorKoenders commented 3 years ago

Oh it seems to be an issue with including bindgen

Cargo.toml

[package]
name = "test_"
version = "0.1.0"
authors = ["Trangar <victor.koenders@gmail.com>"]
edition = "2018"

[dependencies]

[dependencies.cstr_core]
version = "*"
default-features = false

[build-dependencies]
bindgen = "*"

lib.rs

#![no_std]

extern crate cstr_core;

pub extern "C" fn foo(){}

Output

trangar@trangar-home:~/development/rust/test$ cargo build --target riscv32i-unknown-none-elf
   Compiling memchr v2.3.3
error[E0463]: can't find crate for `std`
  |
  = note: the `riscv32i-unknown-none-elf` target may not support the standard library
  = note: `std` is required by `memchr` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `memchr`

To learn more, run the command again with --verbose.

I guess this is a limitation with Cargo?

Amanieu commented 3 years ago

That shouldn't be happening...

Can you try adding resolver = "2" to the [package] section to see if this fixes the problem?

VictorKoenders commented 3 years ago

Oh today I learned about resolver, that seems to solve it. Thanks!

paulrouget commented 2 years ago

I have to use resolver = "2" as well. Even with edition 2021. Any idea why?

Amanieu commented 2 years ago

You need to specify a resolver in the 2021 edition if you use a virtual Cargo workspace.