rustrust-cratesrust-bindgenbindgen

Local crate not found when trying to update edition via cargo fix


Context:
I have a local C library called 'libmaths' that then uses Bindgen to create a 'libmaths-sys' crate that is locally stored in the same directory as my project.

Issue:
I want to use some of the features in the 2021 edition of Rust and currently my project is built off 2018. I am trying to update the project by following the instructions at:

https://doc.rust-lang.org/cargo/commands/cargo-fix.html

Run cargo fix --edition. Consider also using the --all-features flag if your project has multiple features. You may also want to run cargo fix --edition multiple times with different --target flags if your project has platform-specific code gated by cfg attributes.

Modify Cargo.toml to set the edition field to the new edition.

Run your project tests to verify that everything still works. If new warnings are issued, you may want to consider running cargo fix again (without the --edition flag) to apply any suggestions given by the compiler.

To run cargo fix --edition I am told by the compiler to remove the edition="2018" in cargo toml. Following this I receive a compile error stating that libmaths-sys cannot be found. The code compiles and executes normally in 2018 but not without this edition tag.

I can not find anyone with a similar issue, this is my first stackoverflow question so not sure how best to show my code given its a context of a small project.

Error code

error[E0432]: unresolved import `libmaths_sys`

 --> src/main.rs:1:5
  |
1 | use libmaths_sys::*; // lib.rs in sys crate
  |     ^^^^^^^^^^^^ maybe a missing crate `libmaths_sys`?

File Structure and general overview of project

.
├── Cargo.lock
├── Cargo.toml
├── libmaths
│   ├── add.c
│   ├── add.h
│   └── subtract.c
├── libmaths-sys
│   ├── build.rs
│   ├── Cargo.lock
│   ├── Cargo.toml
│   ├── src
│   │   └── lib.rs
│   └── wrapper.h
├── README.md
└── src
    ├── lib.rs
    └── main.rs

libmaths contains add.c that returns a + b and subtract.c which returns a - b, with a header add.h directing to both .c files

The Rust code generated by bindgen is attached via lib.rs in the libmath-sys crate which links to the OUT DIR which I have omitted from the tree to save 200 lines of file names.


Solution

  • As @Solomon Ucko directed me to, rustup update held the key.

    Running rustup update produced:
    info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
    info: syncing channel updates for '1.48-x86_64-unknown-linux-gnu'
    info: checking for self-updates
    
      stable-x86_64-unknown-linux-gnu unchanged - rustc 1.59.0 (9d1b2106e 2022-02-23)
        1.48-x86_64-unknown-linux-gnu unchanged - rustc 1.48.0 (7eac88abb 2020-11-16)
    
    info: cleaning up downloads & tmp directories
    

    In the end, rustup was using the old 1.48 version and not the installed 1.59 version.
    To switch to the newer vesion I ran:

    rustup default stable
    

    I then could follow the instructions from the link in the original question to change the edition.