How to bypass Rust (cargo) error “directory sources are not intended to be edited”
2 min readOct 24, 2022
The package management system GNU Guix (guh-new geeks) can be abused to bypass this Cargo error, which the cargo developers have no interest in fixing.
If you don’t want to follow along and know what you’re doing you can just pull ctrlcctrlv/revendor.guile
.
Step one: find affected packages
Bash STDIN
#!/bin/bash
# This script lists all repositories you changed.
cargo clean
(cargo build 2>&1 | \
grep -Po 'listed checksum of `.*?` has changed' | \
grep -Po '`.*?`' | \
sed 's/`//g') \
| \
parallel "$(cat << 'EOF'
# We want to find the nearest cargo package to the changed file.
(cd $(dirname {}) && while [ ! -f 'Cargo.toml' ]; do
cd ..
done && basename "$(pwd)")
EOF
)" \
| \
# Avoid regenerating same repo twice.
sort -u
# Save me as revendor.sh
STDOUT
epaint
Step two: abuse GNU Guix’s ability to generate Cargo checksums
GNU Guix program
#!/usr/bin/guix repl
!#
(use-modules (guix build cargo-utils))
(define dirs (map (lambda (arg)
(string-append "vendor/" arg))
(cdr (program-arguments))))
(if (not (null? dirs)) (begin (map (lambda (arg)
(generate-all-checksums arg))
dirs)))
; Save me as revendor.scm
; vim: filetype=scheme.guile
Step three: Tie the two together
./revendor.scm $(./revendor.sh)
This shouldn’t even be necessary. But now you know how to do it!
Developers stop treating each other like children challenge (IMPOSSIBLE).