Use older version of a dependency

I am trying to compile an older version tide using a older version of rust compiler (1.45.2 2020-07-31). Current rustc version is 1.54. Current version is tide = "0.16.0", but I see that tide = 0.12.0 was released on 2020-07-17, so I think I must be able to compile the latter version with my older compiler. Tide 0.12.0 does not compile with my older compiler because one of the dependencies (socket2 0.4.1) uses match inside a const fn which I think was introduced after rustc 1.45.2.

How can I make cargo use older version of the socket2 dependency?

socket2 = "0.3" compiles with my older compiler. However, I can see using cargo tree that none of the versions of the dependencies change when I use tide 0.12.0 instead of tide 0.16.0.

In a project that depends on tide 0.12, you can run this command to see what is using socket2:

$ cargo tree --invert socket2         
socket2 v0.4.1
ā””ā”€ā”€ async-io v1.6.0
    ā”œā”€ā”€ async-global-executor v2.0.2
    ā”‚   ā””ā”€ā”€ async-std v1.9.0
    ā”‚       ā”œā”€ā”€ async-h1 v2.3.2
    ā”‚       ā”‚   ā””ā”€ā”€ tide v0.12.0
    ā”‚       ā”‚       ā””ā”€ā”€ tidetest v0.1.0 (/Users/mattbrubeck/src/test/tidetest)
    ā”‚       ā”œā”€ā”€ async-sse v4.1.0
    ā”‚       ā”‚   ā””ā”€ā”€ tide v0.12.0 (*)
    ā”‚       ā”œā”€ā”€ http-types v2.12.0
    ā”‚       ā”‚   ā”œā”€ā”€ async-h1 v2.3.2 (*)
    ā”‚       ā”‚   ā”œā”€ā”€ async-sse v4.1.0 (*)
    ā”‚       ā”‚   ā””ā”€ā”€ tide v0.12.0 (*)
    ā”‚       ā””ā”€ā”€ tide v0.12.0 (*)
    ā”œā”€ā”€ async-process v1.2.0
    ā”‚   ā””ā”€ā”€ async-std v1.9.0 (*)
    ā””ā”€ā”€ async-std v1.9.0 (*)

The only crate in my project that directly depends on socket2 is async-io. If I look at the list of async-io versions, it looks like the latest version that does not depend on socket2 0.4.x is async-io 1.1.0, so I try to downgrade to this version with cargo update:

$ cargo update --package async-io --precise 1.1.0
    Updating index
error: failed to select a version for the requirement `async-io = "^1.2"`
candidate versions found which didn't match: 1.1.0
location searched: index
required by package `async-global-executor v2.0.2`
    ... which is depended on by `async-std v1.9.0`
    ... which is depended on by `async-h1 v2.3.2`
    ... which is depended on by `tide v0.12.0`

Looks like I will also need to downgrade async-global-executor, but when I try to do that, I run into similar errors that lead me to also downgrade async-std. After doing that, I can finally dowgrade async-io:

$ cargo update --package async-std --precise 1.8.0
    Updating index
    Updating async-global-executor v2.0.2 -> v1.4.3
    Removing async-lock v2.4.0
    Updating async-std v1.9.0 -> v1.8.0
$ cargo update --package async-io --precise 1.1.0 
    Updating index
    Updating async-io v1.6.0 -> v1.1.0
    Updating polling v2.1.0 -> v1.1.0
    Updating socket2 v0.4.1 -> v0.3.19
      Adding vec-arena v1.2.0
    Removing wepoll-ffi v0.1.2
      Adding wepoll-sys-stjepang v1.0.8

You may need to repeat with any other dependencies that also fail to build with your old toolchain. Unfortunately, this manual process is the only solution I know. Perhaps someone could build a Cargo command that can automatically ignore versions newer than a specified date.

(Nightly Cargo has an experimental cargo update -Z minimal-versions command that could help with this in theory, though it downgrades more crates that necessary, and it also tends to break the build if any crates fail to specify accurate constraints on their dependencies.)


Thanks! I now understand that the process of finding the right version of dependencies is manual and needed to be done with a couple of cargo update commands to change the Cargo.lock file.

Once I have found the right versions of the dependencies, I can sometimes force the older dependencies to be generated from Cargo.toml in Cargo.lock. Adding this line in Cargo.toml made older tide compile with the older compiler:

async-io = { version = "=1.1.0" }

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.