Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonas-schievink
Last active August 2, 2019 11:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonas-schievink/18cf82523262b8ca62f94d54bef6f905 to your computer and use it in GitHub Desktop.
Save jonas-schievink/18cf82523262b8ca62f94d54bef6f905 to your computer and use it in GitHub Desktop.
Compare metadata produced by successive invocations of rustc
#!/bin/bash
set -e
if [ -z "$RUSTC" ]; then
RUSTC=rustc
fi
crate="$1"
if [ -z "$crate" ]; then
echo "usage: metadiff.sh <crate-name>"
echo
echo "Compiles the given crate (.rs file) twice, comparing the produced metadata."
exit 1
fi
function compile {
output="$1"
echo "Compiling $crate to $output ..."
$RUSTC --crate-type=rlib "$crate" -o "$output"
}
function extract {
rlib="$1"
output="$2"
echo "Extracting metadata from $rlib to $output ..."
ar p "$rlib" rust.metadata.bin > "$output"
}
$RUSTC -V
compile "first.rlib" &
compile "second.rlib" &
wait %% %-
extract "first.rlib" "metadata.0"
extract "second.rlib" "metadata.1"
echo "Diffing metadata files ..."
diffoscope --html-dir diffoscope metadata.0 metadata.1 \
--max-diff-block-lines 5000 \
--max-diff-input-lines 10000000 \
--max-report-size 204800000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment