Skip to content

Install Rust tools with --locked by default or add a parameter to allow this #3162

Open

Description

@mlegner

search you tried in the issue tracker

rust locked

describe your actual problem

Many (most?) Rust projects come with lock files that specify the exact versions of dependencies with which they are tested. Sometimes, they don't work with newer versions, which is why Cargo offers the --locked parameter to build with the dependency versions specified in the lock files.

Currently, pre-commit installs Rust tools without the --locked parameter. I suggest to use this parameter by default or offer a way to specify that a hook should be built using that parameter.

pre-commit --version

pre-commit 3.6.2

Activity

  1. asottile commented on Mar 21, 2024

    @asottile
    Member

    does cargo not use the lock file if present by default? I was under the impression that --locked is only necessary to produce an error if it is missing

  2. mlegner commented on Mar 21, 2024

    @mlegner
    Author

    does cargo not use the lock file if present by default?

    No, the lock file is ignored by default.

  3. asottile commented on Mar 21, 2024

    @asottile
    Member

    hmmmmm I think additional_dependencies: [--locked] will work

  4. mlegner commented on Mar 21, 2024

    @mlegner
    Author

    No, unfortunately this doesn't seem to work as an @* is added automatically:

    An unexpected error has occurred: CalledProcessError: command: ('~/.cargo/bin/cargo', 'add', '--locked@*')
    return code: 1
    stdout: (none)
    stderr:
        error: unexpected argument '--locked@*' found
        
          tip: a similar argument exists: '--locked'
        
        Usage: cargo add [OPTIONS] <DEP>[@<VERSION>] ...
               cargo add [OPTIONS] --path <PATH> ...
               cargo add [OPTIONS] --git <URL> ...
        
        For more information, try '--help'.
    
  5. Timmmm commented on Jul 8, 2024

    @Timmmm

    Yeah this is a bit awkward. I have resorted to using =1.2.3 style dependencies in my Cargo.toml file, but this isn't a full solution because it doesn't lock transitive dependencies.

  6. added a commit that references this issue on Jul 11, 2024
    558793b
  7. bbannier commented on Sep 11, 2024

    @bbannier

    This issue basically makes it impossible for me to package a linter in a pre-commit hook since to build this linter one has to use locked dependencies, and there is no officially supported way to pull in pre-built binaries, see #1453.

  8. added a commit that references this issue on Sep 11, 2024
  9. eltos commented on Feb 17, 2026

    @eltos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions