#!/usr/bin/env bash # CI check: clawhdf5-format has no truncating `u64 as usize` cast on a 32-bit # target. HDF5 addresses and lengths are 64-bit; on wasm32 (or any 32-bit # target) such a cast silently wraps an address past 4 GiB onto another part # of the file. File values go through `addr::to_usize` (a clean error) and # in-memory counts through `addr::saturating_usize`. # # Lints wasm32-unknown-unknown with clippy's cast_possible_truncation and # fails on any u64 -> usize finding (other truncations are not checked here). # # Usage: # ./scripts/check-32bit-casts.sh # # Prerequisites: # rustup target add wasm32-unknown-unknown set -euo pipefail TARGET="wasm32-unknown-unknown" echo "==> Checking for truncating u64 -> usize casts in clawhdf5-format ($TARGET)" out=$(cargo clippy -p clawhdf5-format --target "$TARGET" \ --features plugin-filters --message-format short \ -- -A clippy::all -W clippy::cast_possible_truncation 2>&1) || { echo "$out" echo "==> clippy failed" >&2 exit 1 } found=$(grep -F 'casting `u64` to `usize`' <<<"$out" || true) if [ -n "$found" ]; then echo "$found" echo "==> use addr::to_usize (file values) or addr::saturating_usize (in-memory counts)" >&2 exit 1 fi echo "==> no truncating u64 -> usize casts"