measureme: add update script

This commit is contained in:
t4ccer
2025-06-25 14:15:18 +02:00
parent 4206c4cb56
commit 012200a357
2 changed files with 33 additions and 0 deletions
+2
View File
@@ -21,6 +21,8 @@ rustPlatform.buildRustPackage rec {
ln -s ${./Cargo.lock} Cargo.lock
'';
passthru.updateScript = ./update.sh;
meta = with lib; {
description = "Support crate for rustc's self-profiling feature";
homepage = "https://github.com/rust-lang/measureme";
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nix jq gnused curl nix-prefetch-git cargo
set -eu -o pipefail
package_dir="$(dirname "${BASH_SOURCE[0]}")"
echo "Fetching latest version"
version=$(curl -sfL ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/rust-lang/measureme/releases/latest | jq -r '.tag_name')
echo "Latest version is $version"
if [[ "$UPDATE_NIX_OLD_VERSION" == "$version" ]]; then
echo "Already up to date!"
exit 0
fi
echo "Fetching source hash"
hash="$(nix-prefetch-git https://github.com/rust-lang/measureme.git --quiet --rev "refs/tags/$version" | jq -r '.hash')"
tmp=$(mktemp -d)
trap "rm -rf $tmp" EXIT
git clone --depth 1 --branch "$version" https://github.com/rust-lang/measureme.git "$tmp"
pushd "$tmp"
echo "Generating Cargo.lock"
cargo update
cp "Cargo.lock" "$package_dir/Cargo.lock"
popd
sed -i "s#hash = \".*\";#hash = \"$hash\";#g" "$package_dir/package.nix"
sed -i "s#version = \".*\";#version = \"$version\";#g" "$package_dir/package.nix"