Skip to content

Commit 230ce20

Browse files
authored
Merge pull request rust-lang#19239 from LuuuXXX/add-support-for-ohos
Cofigurate out ohos target to avoid compilation crashes
2 parents 444ce09 + dae664d commit 230ce20

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/tools/rust-analyzer/crates/profile/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = "1.0.0"
1717
libc.workspace = true
1818
jemalloc-ctl = { version = "0.5.0", package = "tikv-jemalloc-ctl", optional = true }
1919

20-
[target.'cfg(target_os = "linux")'.dependencies]
20+
[target.'cfg(all(target_os = "linux", not(target_env = "ohos")))'.dependencies]
2121
perf-event = "=0.4.7"
2222

2323
[target.'cfg(windows)'.dependencies]

src/tools/rust-analyzer/crates/profile/src/stop_watch.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::MemoryUsage;
1111

1212
pub struct StopWatch {
1313
time: Instant,
14-
#[cfg(target_os = "linux")]
14+
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
1515
counter: Option<perf_event::Counter>,
1616
memory: MemoryUsage,
1717
}
@@ -24,7 +24,7 @@ pub struct StopWatchSpan {
2424

2525
impl StopWatch {
2626
pub fn start() -> StopWatch {
27-
#[cfg(target_os = "linux")]
27+
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
2828
let counter = {
2929
// When debugging rust-analyzer using rr, the perf-related syscalls cause it to abort.
3030
// We allow disabling perf by setting the env var `RA_DISABLE_PERF`.
@@ -51,7 +51,7 @@ impl StopWatch {
5151
let time = Instant::now();
5252
StopWatch {
5353
time,
54-
#[cfg(target_os = "linux")]
54+
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
5555
counter,
5656
memory,
5757
}
@@ -60,10 +60,12 @@ impl StopWatch {
6060
pub fn elapsed(&mut self) -> StopWatchSpan {
6161
let time = self.time.elapsed();
6262

63-
#[cfg(target_os = "linux")]
63+
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
6464
let instructions = self.counter.as_mut().and_then(|it| {
6565
it.read().map_err(|err| eprintln!("Failed to read perf counter: {err}")).ok()
6666
});
67+
#[cfg(all(target_os = "linux", target_env = "ohos"))]
68+
let instructions = None;
6769
#[cfg(not(target_os = "linux"))]
6870
let instructions = None;
6971

0 commit comments

Comments
 (0)