Aller au contenu

rust

Installation:

$ brew install rustup-init

Installer le compilateur et Cargo, le gestionnaire de paquet:

$ rustup-init

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /Users/bruno/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /Users/bruno/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /Users/bruno/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /Users/bruno/.profile
  /Users/bruno/.bash_profile
  /Users/bruno/.bashrc
  /Users/bruno/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: aarch64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

Cargo:

Cargo est le gestionnaire de paquets de Rust.

Installer un paquet:

$ cargo install kiro-editor
    Updating crates.io index
  Downloaded kiro-editor v0.4.3
  Downloaded 1 crate (38.2 KB) in 1.59s
  Installing kiro-editor v0.4.3
  Downloaded dirs-sys-next v0.1.2
  Downloaded getopts v0.2.21
  Downloaded term_size v0.3.2
  Downloaded unicode-width v0.1.9
  Downloaded termios v0.3.3
  Downloaded term v0.7.0
  Downloaded jemallocator v0.3.2
  Downloaded libc v0.2.117
  Downloaded jemalloc-sys v0.3.2
  Downloaded signal-hook-registry v1.4.0
  Downloaded signal-hook v0.3.13
  Downloaded fs_extra v1.2.0
  Downloaded cfg-if v1.0.0
  Downloaded cc v1.0.72
  Downloaded dirs-next v2.0.0
  Downloaded 15 crates (2.2 MB) in 0.68s (largest was `jemalloc-sys` at 1.3 MB)
   Compiling libc v0.2.117
   Compiling fs_extra v1.2.0
   Compiling cc v1.0.72
   Compiling cfg-if v1.0.0
   Compiling signal-hook v0.3.13
   Compiling unicode-width v0.1.9
   Compiling getopts v0.2.21
   Compiling jemalloc-sys v0.3.2
   Compiling dirs-sys-next v0.1.2
   Compiling signal-hook-registry v1.4.0
   Compiling termios v0.3.3
   Compiling term_size v0.3.2
   Compiling dirs-next v2.0.0
   Compiling term v0.7.0
   Compiling jemallocator v0.3.2
   Compiling kiro-editor v0.4.3
    Finished release [optimized + debuginfo] target(s) in 1m 05s
  Installing /Users/bruno/.cargo/bin/kiro
   Installed package `kiro-editor v0.4.3` (executable `kiro`)

Les paquets sont installés dans ~/.cargo/bin

~/.cargo/bin                                                                                                                                         11:33:15
❯ ls -la
total 3492
drwxr-xr-x 16 bruno staff     512 mai  9  2022 .
drwxr-xr-x  8 bruno staff     256 fév  4  2022 ..
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 cargo -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 cargo-clippy -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 cargo-fmt -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 cargo-miri -> /opt/homebrew/bin/rustup-init
-rwxr-xr-x  1 bruno staff 2483315 mai  9  2022 cavif
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 clippy-driver -> /opt/homebrew/bin/rustup-init
-rwxr-xr-x  1 bruno staff 1088162 fév  4  2022 kiro
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rls -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rust-gdb -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rust-lldb -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rustc -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rustdoc -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rustfmt -> /opt/homebrew/bin/rustup-init
lrwxr-xr-x 12 bruno staff      29 fév  4  2022 rustup -> /opt/homebrew/bin/rustup-init

Chercher un paquet:

$ cargo search avif
avif = "0.0.0"              # RESERVED. Open for adoption by projects that fulfill some criteria. Please see the gist in the home…
avif-serialize = "0.7.6"    # Minimal writer for AVIF header structure (MPEG/HEIF/MIAF/ISO-BMFF)
avif-decode = "0.2.2"       # Convert AVIF images to PNG or decompressed pixel data
avif-parse = "1.0.0"        # Parser for AVIF image files
cavif = "1.4.0"             # Encodes images in AVIF format (image2avif converter) using a pure-Rust encoder.
ravif = "0.9.1"             # rav1e-based pure Rust library for encoding images in AVIF format (powers the `cavif` tool)
libavif = "0.10.1"          # High-level API for AVIF image files
libavif-image = "0.9.0"     # Load AVIF files into the `image` crate
aom-decode = "0.2.4"        # Minimal safe wrapper for libaom AV1 decoder
libavif-sys = "0.13.1"      # Unsafe wrapper around libavif, the image codec
... and 23 crates more (use --limit N to see more)

Supprimer un paquet:

 $ cargo uninstall kiro-editor

    Removing /Users/bruno/.cargo/bin/kiro

Mettre à jour un paquet:

$ cargo install <crate>

Installe la dernière version du paquet si nécessaire, sinon ne fait rien.

Force la réinstallation:

-> Supprime le paquet -> télécharge la dernière version -> installe

$ cargo install --force <crate>

Liste des paquets installés:

$ cargo install --list
cavif v1.3.4:
    cavif
kiro-editor v0.4.3:
    kiro
$ cat .crates2.json | jq .
{
  "installs": {
    "cavif 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)": {
      "version_req": null,
      "bins": [
        "cavif"
      ],
      "features": [],
      "all_features": false,
      "no_default_features": false,
      "profile": "release",
      "target": "aarch64-apple-darwin",
      "rustc": "rustc 1.58.1 (db9d1b20b 2022-01-20)\nbinary: rustc\ncommit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b\ncommit-date: 2022-01-20\nhost: aarch64-apple-darwin\nrelease: 1.58.1\nLLVM version: 13.0.0\n"
    }
  }
}

Mettre à jour les paquets:

$ cargo install $(cargo install --list | ggrep -E '^[a-z0-9_-]+ v[0-9.]+:$' | cut -f1 -d' ')
    Updating crates.io index
     Ignored package `cavif v1.4.0` is already installed, use --force to override

https://github.com/kbknapp/cargo-outdated

# https://lib.rs/crates/cargo-cache

$ cargo install cargo-cache
$ cargo cache --autoclean
Clearing cache...

Cargo cache '/Users/bruno/.cargo':

Total:                                  737.91 MB => 594.18 MB
  15 installed binaries:                             103.16 MB
  Registry:                             634.75 MB => 491.01 MB
    Registry index:                                  457.35 MB
    291 crate archives:                               33.67 MB
    291 => 0 crate source checkouts:         143.73 MB => 0  B
  Git db:                                                 0  B
    0 bare git repos:                                     0  B
    0 git repo checkouts:                                 0  B

Size changed 737.91 MB => 594.18 MB (-143.73 MB, -19.47%)
$ rm -rf ~/.cargo/registry
# https://lib.rs/crates/cargo-prune

$ cargo install cargo-prune
$ cargo prune

rustup:

$ rustup check
stable-aarch64-apple-darwin - Update available : 1.61.0 (fe5b13d68 2022-05-18) -> 1.65.0 (897e37553 2022-11-02)
rustup - Up to date : 1.25.1
$ rustup show
Default host: aarch64-apple-darwin
rustup home:  /Users/bruno/.rustup

stable-aarch64-apple-darwin (default)
rustc 1.61.0 (fe5b13d68 2022-05-18)

M-à-J de rustup (réalisée par brew):

$ rustup self update
error: self-update is disabled for this build of rustup
error: you should probably use your system package manager to update rustup

M-à-J de Rust:

$ rustup update
info: syncing channel updates for 'stable-aarch64-apple-darwin'
info: latest update on 2022-11-03, rust version 1.65.0 (897e37553 2022-11-02)
info: downloading component 'cargo'
  4.2 MiB /   4.2 MiB (100 %)   1.0 MiB/s in  4s ETA:  0s
info: downloading component 'clippy'
  2.0 MiB /   2.0 MiB (100 %)   1.2 MiB/s in  1s ETA:  0s
info: downloading component 'rust-std'
 27.6 MiB /  27.6 MiB (100 %)   1.1 MiB/s in 28s ETA:  0s
info: downloading component 'rustc'
 52.2 MiB /  52.2 MiB (100 %) 801.6 KiB/s in  1m  7s ETA:  0s
info: downloading component 'rustfmt'
  2.3 MiB /   2.3 MiB (100 %) 757.0 KiB/s in  3s ETA:  0s
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-std'
 27.6 MiB /  27.6 MiB (100 %)  18.2 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 52.2 MiB /  52.2 MiB (100 %)  20.9 MiB/s in  2s ETA:  0s
info: installing component 'rustfmt'

  stable-aarch64-apple-darwin updated - rustc 1.65.0 (897e37553 2022-11-02) (from rustc 1.61.0 (fe5b13d68 2022-05-18))

info: cleaning up downloads & tmp directories
info: self-update is disabled for this build of rustup
info: any updates to rustup will need to be fetched with your system package manager
$ rustup check
stable-aarch64-apple-darwin - Up to date : 1.65.0 (897e37553 2022-11-02)
rustup - Up to date : 1.25.1

Dernière mise à jour: November 9, 2023