Use `cargo sweep` to clean Rust target directories after an upgrade

finchie
Mar 18, 2025, 5:40 AM
XDXDY3CX5KPQWKSFJS7ER5DYTWZFJRXGUWRBITFEYTV565K4IEKQC

Dependencies

  • [2] F2XQXDES Replace `cargo-watch` with `bacon`
  • [3] FU7S4JHV Add script to ensure Rust nightly version stays in sync
  • [4] MAVDUPWD Improve REPL prompt
  • [5] FPOXMH3V Add more agressive garbage collection settings
  • [6] HINOSPQO Add simple nushell update script
  • [*] BAT5B53O Refuse to rebuild until repository has no unrecorded changes
  • [*] 5FI47NSA Migrate to home-manager
  • [*] 226QFOML Replace `cargo-asm` with `cargo-show-asm`

Change contents

  • replacement in src/update.nu at line 7
    [4.28][3.0:42]()
    use rust_version.nu enforce-rust-version;
    [4.28]
    [4.186]
    use rust_version.nu get-rust-version;
  • edit in src/update.nu at line 37
    [8.298]
    [4.874]
    # Before updating, get the current Rust version to see if we need to clean the target directories
    let old_rust_version = get-rust-version;
  • edit in src/update.nu at line 50
    [4.944]
    [4.0]
    # Make sure that Rust is roughly up-to-date (less than a week old)
    # rust-overlay's selectLatestNightlyWith silently keeps older versions if components/targets are no longer valid
    # This code should catch if that happens
    let new_rust_version = get-rust-version;
    assert greater $new_rust_version ((date now) - 7day) $"This version of Rust was built (ansi red_bold)($new_rust_version | date humanize)(ansi reset)!
    Check that all specified targets and extensions are valid.
    (ansi yellow_bold)HINT(ansi reset): replace `selectLatestNightlyWith` with `nightly.latest.default.override` to debug.";
  • replacement in src/update.nu at line 61
    [3.294][3.294:352]()
    # Make sure that Rust is up-to-date
    enforce-rust-version;
    [3.294]
    [4.80]
    # Since the Rust version has changed anyways, clean all Rust target directories
    if $old_rust_version != $new_rust_version {
    print $"Removing old Rust target directories: ($new_rust_version - $old_rust_version) newer";
    # `cargo-sweep` seems to require the `time` parameter, so just set it to 0
    cargo sweep --time 0 --recursive ~/Projects/Rust
    }
  • replacement in src/rust_version.nu at line 1
    [3.393][3.394:553](),[3.553][3.553:554](),[3.554][3.554:570]()
    # Prevent rustc from getting too out-of-date;
    # rust-overlay's selectLatestNightlyWith silently keeps older versions if components/targets are no longer valid
    use std assert;
    [3.393]
    [3.570]
    # Get the release date of the current Rust version
  • replacement in src/rust_version.nu at line 3
    [3.571][3.571:608]()
    export def enforce-rust-version [] {
    [3.571]
    [3.608]
    export def get-rust-version [] {
  • replacement in src/rust_version.nu at line 10
    [3.846][3.846:913](),[3.913][3.913:1312]()
    let version_date = $version_info.date | first | into datetime;
    # Return an error if the version is more than one week old
    assert greater $version_date ((date now) - 7day) $"This version of Rust was built (ansi red_bold)($version_date | date humanize)(ansi reset)!
    Check that all specified targets and extensions are valid.
    (ansi yellow_bold)HINT(ansi reset): replace `selectLatestNightlyWith` with `nightly.latest.default.override` to debug.";
    }
    [3.846]
    $version_info.date | first | into datetime
    }
  • edit in home.nix at line 89
    [10.19]
    [2.0]
    cargo-sweep