diff options
| author | LuuuXXX <luuux98@163.com> | 2025-02-27 11:43:03 +0800 |
|---|---|---|
| committer | LuuuXXX <luuux98@163.com> | 2025-02-27 11:43:03 +0800 |
| commit | dae664d09a0f4c72702d96877aeace83cc100f41 (patch) | |
| tree | 34a53a9c0a20b31cf4f2c7b73fd849f6d28f1647 | |
| parent | 444ce09d53eb7bf966f155a322407924fc6ce8cd (diff) | |
| download | rust-dae664d09a0f4c72702d96877aeace83cc100f41.tar.gz rust-dae664d09a0f4c72702d96877aeace83cc100f41.zip | |
Cofigurate out ohos target to avoid compilation crashes
| -rw-r--r-- | src/tools/rust-analyzer/crates/profile/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/profile/src/stop_watch.rs | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/profile/Cargo.toml b/src/tools/rust-analyzer/crates/profile/Cargo.toml index 3179c810f69..65eec868af3 100644 --- a/src/tools/rust-analyzer/crates/profile/Cargo.toml +++ b/src/tools/rust-analyzer/crates/profile/Cargo.toml @@ -17,7 +17,7 @@ cfg-if = "1.0.0" libc.workspace = true jemalloc-ctl = { version = "0.5.0", package = "tikv-jemalloc-ctl", optional = true } -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(all(target_os = "linux", not(target_env = "ohos")))'.dependencies] perf-event = "=0.4.7" [target.'cfg(windows)'.dependencies] diff --git a/src/tools/rust-analyzer/crates/profile/src/stop_watch.rs b/src/tools/rust-analyzer/crates/profile/src/stop_watch.rs index 0a803959eed..9f3e636ef81 100644 --- a/src/tools/rust-analyzer/crates/profile/src/stop_watch.rs +++ b/src/tools/rust-analyzer/crates/profile/src/stop_watch.rs @@ -11,7 +11,7 @@ use crate::MemoryUsage; pub struct StopWatch { time: Instant, - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "ohos")))] counter: Option<perf_event::Counter>, memory: MemoryUsage, } @@ -24,7 +24,7 @@ pub struct StopWatchSpan { impl StopWatch { pub fn start() -> StopWatch { - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "ohos")))] let counter = { // When debugging rust-analyzer using rr, the perf-related syscalls cause it to abort. // We allow disabling perf by setting the env var `RA_DISABLE_PERF`. @@ -51,7 +51,7 @@ impl StopWatch { let time = Instant::now(); StopWatch { time, - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "ohos")))] counter, memory, } @@ -60,10 +60,12 @@ impl StopWatch { pub fn elapsed(&mut self) -> StopWatchSpan { let time = self.time.elapsed(); - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", not(target_env = "ohos")))] let instructions = self.counter.as_mut().and_then(|it| { it.read().map_err(|err| eprintln!("Failed to read perf counter: {err}")).ok() }); + #[cfg(all(target_os = "linux", target_env = "ohos"))] + let instructions = None; #[cfg(not(target_os = "linux"))] let instructions = None; |
