diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce6932b..daf9223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + toolchain: [stable, nightly] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -76,7 +77,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.toolchain }} - name: Test std uses: actions-rs/cargo@v1 with: @@ -87,6 +88,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] + toolchain: [stable, nightly] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -97,7 +99,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.toolchain }} - name: Test sim uses: actions-rs/cargo@v1 env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f79f3b..fb0c8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.9] - 2022-10-28 + +### Fixed + +- madsim: Fix internal structure change of nightly `std::time::{SystemTime, Interval}`. + ## [0.2.8] - 2022-09-26 ### Added diff --git a/madsim/Cargo.toml b/madsim/Cargo.toml index 08e491b..c12479e 100644 --- a/madsim/Cargo.toml +++ b/madsim/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "madsim" -version = "0.2.8" +version = "0.2.9" edition = "2021" authors = ["Runji Wang "] description = "Deterministic Simulator for distributed systems." diff --git a/madsim/src/sim/time/system_time.rs b/madsim/src/sim/time/system_time.rs index ea62427..4dd4e4e 100644 --- a/madsim/src/sim/time/system_time.rs +++ b/madsim/src/sim/time/system_time.rs @@ -1,3 +1,5 @@ +use std::time::SystemTime; + /// Override the libc `gettimeofday` function. For `SystemTime` on macOS. #[no_mangle] #[inline(never)] @@ -12,7 +14,7 @@ unsafe extern "C" fn gettimeofday(tp: *mut libc::timeval, tz: *mut libc::c_void) // inside a madsim context, use the simulated time. let dur = time .now_time() - .duration_since(std::time::SystemTime::UNIX_EPOCH) + .duration_since(SystemTime::UNIX_EPOCH) .unwrap(); tp.write(libc::timeval { tv_sec: dur.as_secs() as _, @@ -50,7 +52,7 @@ unsafe extern "C" fn clock_gettime( libc::CLOCK_REALTIME | libc::CLOCK_REALTIME_COARSE => { let dur = time .now_time() - .duration_since(std::time::SystemTime::UNIX_EPOCH) + .duration_since(SystemTime::UNIX_EPOCH) .unwrap(); tp.write(libc::timespec { tv_sec: dur.as_secs() as _, @@ -59,7 +61,13 @@ unsafe extern "C" fn clock_gettime( } // used by Instant libc::CLOCK_MONOTONIC | libc::CLOCK_MONOTONIC_RAW | libc::CLOCK_MONOTONIC_COARSE => { - tp.write(std::mem::transmute(time.now_instant())); + let dur = std::mem::transmute::<_, SystemTime>(time.now_instant()) + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + tp.write(libc::timespec { + tv_sec: dur.as_secs() as _, + tv_nsec: dur.subsec_nanos() as _, + }); } _ => panic!("unsupported clockid: {}", clockid), }