Latest suricata 6.0.2 with rustc has trouble installing with error: could not compile `lexical-core`

I’m using Debian 10 and tried to install suricata build from source and I got the following log message:

....
error[E0277]: cannot subtract `usize` from `u32`
    --> /root/temp/src/suricata-6.0.2/rust/vendor/lexical-core/src/atof/algorithm/math.rs:2071:25
     |
2071 |     let rs = Limb::BITS - s;
     |                         ^ no implementation for `u32 - usize`
     |
     = help: the trait `Sub<usize>` is not implemented for `u32`

error: aborting due to 27 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `lexical-core`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
make[2]: *** [Makefile:544: all-local] Error 101
make[2]: Leaving directory '/root/temp/src/suricata-6.0.2/rust'
make[1]: *** [Makefile:492: install-recursive] Error 1
make[1]: Leaving directory '/root/temp/src/suricata-6.0.2'
make: *** [Makefile:908: install-full] Error 2

I think lexical-core is the culprit here. If anyone know if I should downgrade something in order to pass this error message? I’m not really familiar with this rustc thing. I actually followed the similar installation procedure that I’ve written in here: Install suricata 6.0.1 on Debian 10 from source

1 Like

Can you tell me what version of Rust ./configure found? This is listed in the output when ./configure is finished. Thanks!

I have the same error with suricata 6.0.2 on OpenBSD, using rustc 1.53.0 (released recently). The build was fine with previous rustc version (1.52.1).

The problem is related to lexical-core and integer::BITS stabilization on rust side. A fix landed in lexical-core but only on 0.7 branch (release 0.7.5 fixed it). suricata 6.0.2 tarball ships lexical-core 0.6.7 which is affected.

Related issues:

Other then downgrading your Rust, one work-around is to rm -rf rust/vendor before running ./configure. That will cause the Rust deps to be pulled from the internet instead of the vendored.

No real graceful way to handle Rust deciding to make some new reserved keywords unfortunately.

that might be unacceptable for downstream distribution if they want to ship updated rustc and suricata versions.

lexical-core comes from nom 5.1.1 requirement in suricata. nom has a 5.1.2 version published and this version allows lexical-core 0.7.x. updating nom to 5.1.2 might be a migration path for this issue.

Yes, thats a valid concern, but its hard to get right for everyone. We vendor the sources to allow building offline which is a requirement for some downstream distributions, and just in general to provide the more classic unix software install experience without having to go out to the network… It also has the affect of doing a Cargo.lock without having a Cargo.lock - even if we didn’t vendor and shipped a Cargo.lock, you’d run into the same situation, however it is easier to patch.

One thing we could do is provide a ./configure argument like --without-rust-vendored to always fetch from the internet. That may have issues as well, as you could end up with versions we didn’t use during QA, etc. We’ve seen patch releases in dependencies break APIs as well, but in this case its rust.

So the best we can do is handle what we know when we stamp a release archive, and unfortunately deal with these breakages from time to time.

I agree that there is no simple solution here.

I also just saw commit 639f3d26 on suricata which pin nom to 5.1.1 on purpose (5.1.2 pulls in dependencies that don’t build on Rust 1.34).

Please note that not using vendored crates might not be enough to build suricata with Rust 1.53: nom 5.1.1 is bound to lexical-core 0.6 (see nom Cargo.toml and so it is not buildable with Rust >=1.53.

For downstream usage, I will go on the road to (partially) backport lexical-core patch.

Thanks for your help.

Both 6.0.2 (with rust/vendor removed) and git master build for me with Rust 1.53.0 with nom 5.1.1 and lexical-core 0.6.8.

@ish Sorry for late reply. My rustc version is same like @semarie 1.53.0

Rust support: yes
Rust strict mode: no
Rust compiler path: /root/.cargo/bin/rustc
Rust compiler version: rustc 1.53.0 (53cb7b09b 2021-06-17)
Cargo path: /root/.cargo/bin/cargo
Cargo version: cargo 1.53.0 (4369396ce 2021-04-27)
Cargo vendor: yes

I’m going to try the work around that you have suggested by removing rm -rf rust/vendor before running ./configure

EDIT: well the solution removing rust/vendor does not work (similar error). Here is the log:

error[E0277]: cannot divide usize by u32
→ /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lexical-core-0.6.7/src/atof/algorithm/math.rs:1260:17
|
1260 | let div = n / bits;
| ^ no implementation for usize / u32
|
= help: the trait Div<u32> is not implemented for usize

error[E0308]: mismatched types
→ /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lexical-core-0.6.7/src/atof/algorithm/math.rs:2071:27
|
2071 | let rs = Limb::BITS - s;
| ^ expected u32, found usize

error[E0277]: cannot subtract usize from u32
→ /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lexical-core-0.6.7/src/atof/algorithm/math.rs:2071:25
|
2071 | let rs = Limb::BITS - s;
| ^ no implementation for u32 - usize
|
= help: the trait Sub<usize> is not implemented for u32

error: aborting due to 27 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile lexical-core

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish…
error: build failed
make[2]: *** [Makefile:544: all-local] Error 101
make[2]: Leaving directory ‘/root/temp/src/suricata-6.0.2/rust’
make[1]: *** [Makefile:492: install-recursive] Error 1
make[1]: Leaving directory ‘/root/temp/src/suricata-6.0.2’
make: *** [Makefile:908: install-full] Error 2

How do you downgrade the rust version before building suricata ? I want to try the version 1.52.1

For the rm -rf rust/vendor to work you might have to unpack into a clean directory, then remove, then ./configure.

I think I saw in another post that you were using rustup? If so, you could:

rustup install 1.52.0
export RUSTUP_TOOLCHAIN=1.52.0
./configure && make && make install
3 Likes

Thank you @ish, I was able to use a rust binary of 1.52 earlier this week, and now build with rustup using your suggested variable version pass to compile.

Guys are you sure this issue related to rustc? I still get the same error even I downgraded my rustc version to 1.52. Here is my step

First, I install rustup as normal in order to have rustup command to downgrade itself

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"

At this point rustc - V shows the latest version 1.53

Now as suggested, to downgrade, I ran the following:

rustup install 1.52.0
export RUSTUP_TOOLCHAIN=1.52.0
source "$HOME/.cargo/env"

I can see it downgraded. When I run rustc -V, it shows version 1.52

Now I install suricata like this:

suricata_preferred_version="6.0.2"
INST_TEMP_DIR="/root/temp/src"

# Remove existing downloaded file:
rm -fv "${INST_TEMP_DIR}/suricata-${suricata_preferred_version}.tar.gz"

# Download suricata
wget "https://www.openinfosecfoundation.org/download/suricata-${suricata_preferred_version}.tar.gz"

#Extract
tar xzvf "suricata-${suricata_preferred_version}.tar.gz"

cd "suricata-${suricata_preferred_version}/"

./configure --libdir=/usr/lib64 --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var --datarootdir=/usr/local/share --enable-lua --enable-rust

At this point I still got the same error and the installer terminated:

error[E0277]: cannot subtract `usize` from `u32`
    --> /root/temp/src/suricata-6.0.2/rust/vendor/lexical-core/src/atof/algorithm/math.rs:2071:25
     |
2071 |     let rs = Limb::BITS - s;
     |                         ^ no implementation for `u32 - usize`
     |
     = help: the trait `Sub<usize>` is not implemented for `u32`

error: aborting due to 27 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `lexical-core`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
make[2]: *** [Makefile:544: all-local] Error 101
make[2]: Leaving directory '/root/temp/src/suricata-6.0.2/rust'
make[1]: *** [Makefile:492: install-recursive] Error 1
make[1]: Leaving directory '/root/temp/src/suricata-6.0.2'
make: *** [Makefile:908: install-full] Error 2

Is there anything else I can provide to debug this. Thanks for helping …

./configure will output the version of Rust found in its summary, can you check if that is also 1.52.0?

1 Like

Updated:

Here is the rust version after I ran ./configure


  Rust support:                            yes
  Rust strict mode:                        no
  Rust compiler path:                      /root/.cargo/bin/rustc
  Rust compiler version:                   rustc 1.52.0 (88f19c6da 2021-05-03)
  Cargo path:                              /root/.cargo/bin/cargo
  Cargo version:                           cargo 1.52.0 (69767412a 2021-04-21)
  Cargo vendor:                            yes

And here is the rust version if I run rustc -V

root@sun:~# rustc -V
rustc 1.52.0 (88f19c6da 2021-05-03)

Seems both are the same commit version but the installation still did not go through

My only guess is that somehow some environment is getting lost when you do make… How about simply:

RUSTUP_TOOLCHAIN=1.52.0 make

in the top source directory?

2 Likes

Thanks putting that RUSTUP_TOOLCHAIN infront works perfectly:

sudo RUSTUP_TOOLCHAIN=1.52.0 make install-full