unit-tests: Fix `cargo test` on 32-bit platforms
Fixes https://bz.mercurial-scm.org/show_bug.cgi?id=6506
This makes `IndexEntryBuilder::build`, which is only used in unit tests, use
`u32` or `u64` instead of platform-dependent `usize` when packing binary data
to be used at test input.
To run Rust unit tests in 32-bit mode in a x86-64 environment, use:
rustup target add i686-unknown-linux-gnu # Once
(cd rust && cargo test --target i686-unknown-linux-gnu)
Differential Revision: https://phab.mercurial-scm.org/D10351
--- a/rust/hg-core/src/revlog/index.rs Fri Apr 09 08:46:40 2021 -0700
+++ b/rust/hg-core/src/revlog/index.rs Fri Apr 09 12:02:51 2021 +0200
@@ -300,12 +300,12 @@
// Remaining offset bytes.
bytes.extend(&[0u8; 2]);
} else {
- // Offset is only 6 bytes will usize is 8.
- bytes.extend(&self.offset.to_be_bytes()[2..]);
+ // Offset stored on 48 bits (6 bytes)
+ bytes.extend(&(self.offset as u64).to_be_bytes()[2..]);
}
bytes.extend(&[0u8; 2]); // Revision flags.
- bytes.extend(&self.compressed_len.to_be_bytes()[4..]);
- bytes.extend(&self.uncompressed_len.to_be_bytes()[4..]);
+ bytes.extend(&(self.compressed_len as u32).to_be_bytes());
+ bytes.extend(&(self.uncompressed_len as u32).to_be_bytes());
bytes.extend(&self.base_revision.to_be_bytes());
bytes
}