Skip to content

Commit

Permalink
allow wasm32 compilation of librustc_data_structures/profiling.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart committed Apr 21, 2020
1 parent 20fc02f commit df3776b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/librustc_data_structures/profiling.rs
Expand Up @@ -99,10 +99,12 @@ use parking_lot::RwLock;

/// MmapSerializatioSink is faster on macOS and Linux
/// but FileSerializationSink is faster on Windows
#[cfg(not(windows))]
#[cfg(all(not(windows),not(target_arch="wasm32")))]
type SerializationSink = measureme::MmapSerializationSink;
#[cfg(windows)]
#[cfg(all(windows,not(target_arch="wasm32")))]
type SerializationSink = measureme::FileSerializationSink;
#[cfg(target_arch="wasm32")]
type SerializationSink = measureme::ByteVecSink;

type Profiler = measureme::Profiler<SerializationSink>;

Expand Down Expand Up @@ -602,7 +604,7 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
}

// Memory reporting
#[cfg(unix)]
#[cfg(all(unix,not(target_arch="wasm32")))]
fn get_resident() -> Option<usize> {
let field = 1;
let contents = fs::read("/proc/self/statm").ok()?;
Expand All @@ -612,7 +614,7 @@ fn get_resident() -> Option<usize> {
Some(npages * 4096)
}

#[cfg(windows)]
#[cfg(all(windows,not(target_arch="wasm32")))]
fn get_resident() -> Option<usize> {
use std::mem::{self, MaybeUninit};
use winapi::shared::minwindef::DWORD;
Expand All @@ -630,3 +632,8 @@ fn get_resident() -> Option<usize> {
}
}
}

#[cfg(target_arch="wasm32")]
fn get_resident() -> Option<usize> {
None
}

0 comments on commit df3776b

Please sign in to comment.