diff --git a/.github/workflows/cross_platform.yml b/.github/workflows/cross_platform.yml new file mode 100644 index 00000000..3125393d --- /dev/null +++ b/.github/workflows/cross_platform.yml @@ -0,0 +1,79 @@ +{ + "name": "Cross platform tests", + "on": { + "push": { + "branches": [ + "trunk", + "v*.x", + "ci/*" + ] + }, + "pull_request": { + "branches": [ + "trunk", + "v*.x" + ] + } + }, + "jobs": { + "check": { + "name": "Test", + "runs-on": "ubuntu-latest", + "strategy": { + "fail-fast": false, + "matrix": { + "platform": [ + "aarch64-unknown-linux-gnu", + "arm-unknown-linux-gnueabi", + "arm-unknown-linux-gnueabihf", + # "armv5te-unknown-linux-gnueabi", + "armv7-unknown-linux-gnueabihf", + "i586-unknown-linux-gnu", + # "i686-pc-windows-gnu", + "i686-unknown-linux-gnu", + # "mips-unknown-linux-gnu", + "mips64-unknown-linux-gnuabi64", + "mips64el-unknown-linux-gnuabi64", + # "mipsel-unknown-linux-gnu", + # "powerpc-unknown-linux-gnu", + # "powerpc64-unknown-linux-gnu", + # "powerpc64le-unknown-linux-gnu", + "riscv64gc-unknown-linux-gnu", + # "sparc64-unknown-linux-gnu", + "x86_64-pc-windows-gnu", + "x86_64-unknown-linux-gnu" + ] + } + }, + "steps": [ + { + "uses": "actions/checkout@v2", + "name": "Checkout" + }, + { + "uses": "actions-rs/toolchain@v1", + "with": { + "profile": "minimal", + "toolchain": "stable", + "override": true + }, + "name": "Install Rust stable" + }, + { + "uses": "actions-rs/install@v0.1", + "with": { + "crate": "cross" + }, + "name": "Install cargo cross" + }, + { + "run": "cross test --target ${{ matrix.platform }}", + "name": "Run tests", + "env": { + "RUSTFLAGS": "-D warnings" + } + } + ] + } + } +} diff --git a/src/enc/impls.rs b/src/enc/impls.rs index 0269a1b6..0f061acd 100644 --- a/src/enc/impls.rs +++ b/src/enc/impls.rs @@ -134,8 +134,8 @@ impl Encode for usize { crate::varint::varint_encode_usize(encoder.writer(), E::C::ENDIAN, *self) } IntEncoding::Fixed => match E::C::ENDIAN { - Endian::Big => encoder.writer().write(&self.to_be_bytes()), - Endian::Little => encoder.writer().write(&self.to_le_bytes()), + Endian::Big => encoder.writer().write(&(*self as u64).to_be_bytes()), + Endian::Little => encoder.writer().write(&(*self as u64).to_le_bytes()), }, } } @@ -246,8 +246,8 @@ impl Encode for isize { crate::varint::varint_encode_isize(encoder.writer(), E::C::ENDIAN, *self) } IntEncoding::Fixed => match E::C::ENDIAN { - Endian::Big => encoder.writer().write(&self.to_be_bytes()), - Endian::Little => encoder.writer().write(&self.to_le_bytes()), + Endian::Big => encoder.writer().write(&(*self as i64).to_be_bytes()), + Endian::Little => encoder.writer().write(&(*self as i64).to_le_bytes()), }, } } diff --git a/tests/alloc.rs b/tests/alloc.rs index 84bffe09..3173ed74 100644 --- a/tests/alloc.rs +++ b/tests/alloc.rs @@ -115,7 +115,13 @@ fn test_container_limits() { bincode::config::standard().with_limit::(), ); - assert_eq!(result.unwrap_err(), DecodeError::LimitExceeded); + let name = core::any::type_name::(); + match result { + Ok(_) => panic!("Decoding {} should fail, it instead succeeded", name), + Err(DecodeError::OutsideUsizeRange(_)) if cfg!(target_pointer_width = "32") => {}, + Err(DecodeError::LimitExceeded) => {}, + Err(e) => panic!("Expected OutsideUsizeRange (on 32 bit platforms) or LimitExceeded whilst decoding {}, got {:?}", name, e), + } } for slice in test_cases {