knurling-rs / defmt

Efficient, deferred formatting for logging on embedded systems
https://defmt.ferrous-systems.com/
Apache License 2.0
750 stars 69 forks source link

defmt 0.3.7 breaks build for older versions of rust #833

Closed astapleton closed 1 month ago

astapleton commented 1 month ago

It seems the change to deprecate the defmt ip_in_core feature #805 breaks compilation of defmt using older versions of rust that do not have the feature enabled (I assume <1.77, but I'm seeing the failure on 1.69) and it doesn't seem like there's an option to opt out of compiling that support in? I see defmt makes no guarantees around what version it supports, so is this just a case where we should pin the version of defmt to an older version?

Error message:

Running `rustc --crate-name defmt --edition=2021 /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=s -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 -C metadata=b27a5ecf916ca307 -C extra-filename=-b27a5ecf916ca307 --out-dir /home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps --target thumbv8m.main-none-eabihf -L dependency=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps -L dependency=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/release/deps --extern bitflags=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps/libbitflags-b1517aef8673b8a3.rmeta --extern defmt_macros=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/release/deps/libdefmt_macros-e5f01e789cc59d6d.so --cap-lints allow -C link-arg=-Tlink.x -L /home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/build/defmt-38e3dd9c889695b3/out`
error[E0658]: use of unstable library feature 'ip_in_core'
Error:  --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:1:5
  |
1 | use core::net;
  |     ^^^^^^^^^
  |
  = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:  --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:5:17
  |
5 | impl Format for net::AddrParseError {
  |                 ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:11:17
   |
11 | impl Format for net::Ipv4Addr {
   |                 ^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:18:17
   |
18 | impl Format for net::SocketAddrV4 {
   |                 ^^^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:24:17
   |
24 | impl Format for net::Ipv6Addr {
   |                 ^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:50:17
   |
50 | impl Format for net::SocketAddrV6 {
   |                 ^^^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:56:17
   |
56 | impl Format for net::IpAddr {
   |                 ^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:65:17
   |
65 | impl Format for net::SocketAddr {
   |                 ^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:59:13
   |
59 |             net::IpAddr::V4(a) => crate::write!(fmt, "{}", a),
   |             ^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:60:13
   |
60 |             net::IpAddr::V6(a) => crate::write!(fmt, "{}", a),
   |             ^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:68:13
   |
68 |             net::SocketAddr::V4(a) => crate::write!(fmt, "{}", a),
   |             ^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

error[E0658]: use of unstable library feature 'ip_in_core'
Error:   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/impls/core_/net.rs:69:13
   |
69 |             net::SocketAddr::V6(a) => crate::write!(fmt, "{}", a),
   |             ^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #108443 <https://github.com/rust-lang/rust/issues/108443> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `defmt` due to 12 previous errors
Error: could not compile `defmt` due to 12 previous errors
Caused by:
  process didn't exit successfully: `rustc --crate-name defmt --edition=2021 /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/defmt-0.3.7/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=s -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 -C metadata=b27a5ecf916ca307 -C extra-filename=-b27a5ecf916ca307 --out-dir /home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps --target thumbv8m.main-none-eabihf -L dependency=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps -L dependency=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/release/deps --extern bitflags=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/deps/libbitflags-b[151](https://github.com/UTVATE/stm32h5xx-hal/actions/runs/9069005576/job/24917610183#step:6:153)7aef8673b8a3.rmeta --extern defmt_macros=/home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/release/deps/libdefmt_macros-e5f01e789cc59d6d.so --cap-lints allow -C link-arg=-Tlink.x -L /home/runner/work/stm32h5xx-hal/stm32h5xx-hal/target/thumbv8m.main-none-eabihf/release/build/defmt-38e3dd9c889695b3/out` (exit status: 1)
Error: The process 'cross' failed with exit code 101
Urhengulas commented 1 month ago

Can you please share the error message?

astapleton commented 1 month ago

Sorry! Should have included that to begin with. Updated the top level comment with the error message

Urhengulas commented 1 month ago

@astapleton, @arctic-alpaca, @thvdveld Can you please try if it works for you with https://github.com/knurling-rs/defmt/pull/840?

You can use the version of the branch by adding a patch section to your Cargo.toml:

[patch.crates-io]
defmt = { git = "https://github.com/knurling-rs/defmt", branch = "support-pre-1.77" }
# <add other knurling-rs depencies as well, in case you use them>
thvdveld commented 1 month ago

This seems to work, but I had to remove the heapless defmt-03 feature in smoltcp to make it work.

error: failed to select a version for `defmt`.
    ... required by package `heapless v0.8.0`
    ... which satisfies dependency `heapless = "^0.8"` of package `smoltcp v0.11.0 (/home/thvdveld/source/vub/smoltcp)`
versions that meet the requirements `>=0.2.0, <0.4` are: 0.3.7, 0.3.6, 0.3.5, 0.3.4, 0.3.2, 0.3.0, 0.2.3, 0.2.2, 0.2.1, 0.2.0

the package `defmt` links to the native library `defmt`, but it conflicts with a previous package which links to `defmt` as well:
package `defmt v0.3.7 (https://github.com/knurling-rs/defmt?branch=support-pre-1.77#e9290117)`
    ... which satisfies git dependency `defmt` of package `smoltcp v0.11.0 (/home/thvdveld/source/vub/smoltcp)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "defmt"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `defmt` which could resolve this conflict

I think this is because the support-pre-1.77 branch still uses 0.3.7 as a version.

arctic-alpaca commented 1 month ago

I think adding ip_in_core to the default features is a breaking change, but the reference has no clear answer for this. Since this will break compilation for every project using defmt (without default-features = false) with older Rust versions, I would consider this breaking.

I'm seeing the same issue as @thvdveld with other dependencies depending on defmt.

Urhengulas commented 1 month ago

@thvdveld

I think this is because the support-pre-1.77 branch still uses 0.3.7 as a version.

@arctic-alpaca

I'm seeing the same issue as @thvdveld with other dependencies depending on defmt.

Yes, the problem is that there can only be one version of defmt in your dependency tree and heapless depends on the published version while you use the git version. This will go away as soon as it is published.

Urhengulas commented 1 month ago

I think adding ip_in_core to the default features is a breaking change, but the reference has no clear answer for this. Since this will break compilation for every project using defmt (without default-features = false) with older Rust versions, I would consider this breaking.

I am fine with making it opt-in instead.

arctic-alpaca commented 1 month ago

I am fine with making it opt-in instead.

Thanks, that would be great!

Urhengulas commented 1 month ago

@arctic-alpaca @thvdveld I changed the PR to opt-in. I think it should work for you, but maybe you wanna try again?

thvdveld commented 1 month ago

Checked it and it works. Thank you!

arctic-alpaca commented 1 month ago

Also works on my end, thank you!

Urhengulas commented 1 month ago

Nice. Gonna merge, release defmt 0.3.8 and yank 0.3.7.

Urhengulas commented 1 month ago

defmt 0.3.8 was just released

astapleton commented 1 month ago

Also works here. Thanks!