In python, when you install stuff with pip, it is recommended to use a venv, to avoid breaking dependencies for a program when uninstalling another one, or when two programs need two different versions of the same dependence.

I was wondering if with Rust is the same, or if Cargo manages it all on its own (kind of like apt does), and I shouldn’t care about it.

Also since I know Linux kernel is using some Rust, isn’t there a risk of breaking my system if I uninstall a program that need some deps that the system itsel needs?

  • Rogue@feddit.uk
    link
    fedilink
    arrow-up
    12
    ·
    4 hours ago

    Rust is very different to Python and Cargo is very different to apt.

    When you build your rust/Cargo project it compiles all the dependencies specified in Cargo.toml into a single executable.

    That executable (with some exceptions) can then be run without any dependencies. You don’t even need Rust or cargo installed. Therefore the Rust running in the kernel is entirely isolated from whatever your Rust app is doing.

    There’s no need for virtual environments etc

  • pr06lefs@lemmy.ml
    link
    fedilink
    arrow-up
    3
    ·
    3 hours ago

    Typically rust programs are statically linked, meaning the executable contains all the dependencies needed to run it, with the exception of libc, unless you’re using musl. So no dependency worries basically.

    Probably wise to install something like cargo-cleaner (on crates.io). Those target/ folders in rust projects can get pretty big.

  • nous@programming.dev
    link
    fedilink
    English
    arrow-up
    3
    ·
    4 hours ago

    You don’t need to worry about that in rust. Cargo is built from the ground up to understand package versions and downloads/builds the right versions for each project. The global package caches understand versions and can cache multiple versions of each package. Where as python just uses one or more global stores of packages shared by all projects. venv is basically there to isolated these package stores along with the version of python which can have breaking changes between different releases (this is something rust avoids at all costs so you can upgrade it without worrying as much as with python).

  • paperemail@links.rocks
    link
    fedilink
    arrow-up
    4
    ·
    4 hours ago

    No, you don’t need to do that.

    All the source code of your dependencies are stored in ~/.cargo/registry^1. Which doesn’t lead to conflicts.

    And the compiled versions are stored in the target/ directory in your project directory^2, so there’s no conflict there.

    1: that is configurable with CARGO_HOME, I have that set to ~/.cache/cargo

    2: That is configurable with the build.target-dir option. I have that set to ~/.cache/cargo/target so that build artifacts don’t end up in my backups :)

  • Justin@lemmy.jlh.name
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 hours ago

    Go and try out cargo. It always uses separate environments for installing dependencies.

    It’s worth nothing that Rust doesn’t have system dependencies like Python or C, as all depdencies are statically linked with the binary. There’s no .so files like C (usually), and there’s no pip store like Python for Rust programs to read from.

    I think virtual environments are more of a interpreted language thing, as I only know of them existing for Python and PHP. (NPM also uses separated environments by default)