Skip to content

Commit 7a2a748

Browse files
danakjchromeos-ci-prod
authored andcommitted
Remove access to unstable features in Rust
Using unstable features creates risk for our ability to roll the compiler, and are not supported at all in other toolchains like Cronet. Build scripts sometimes compile rust code as a way to query the compiler, as is seen with the anyhow crate. It compiles code to test for the presence of an unstable feature. We need to tell the build script the rustflags to use when compiling, or it will not know about the `-Zallow-features=` flag, and will incorrectly try to enable the unstable feature. We can do this through the `CARGO_ENCODED_RUSTFLAGS` environment variable. To get this variable to the build script we write `{{rustflags}}` to a file. This avoids the need to try differentiate rust flags from python flags in the command line for run_build_script.py. The stdlib gets to use unstable features still, by design, as its part of the toolchain itself, but the rest of our code should not. The mojo experimental code has an exception to this, but it's not blocking code. If it becomes a problem, we can disable it from the build. R=aeubanks@google.com, lukasza@chromium.org Change-Id: I34fd5d36cccc6327f68821f5cfb8db2773544110 Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5967012 Commit-Queue: danakj <danakj@chromium.org> Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org> Reviewed-by: Arthur Eubanks <aeubanks@google.com> Cr-Commit-Position: refs/heads/main@{#1375330} CrOS-Libchrome-Original-Commit: 6fdddfa2d8492bc0f1bb9055b41f1bae387cb862
1 parent cc08f5f commit 7a2a748

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

mojo/public/rust/system/data_pipe.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ impl<T> Consumer<T> {
290290
)
291291
});
292292
unsafe { buf.set_len((num_bytes / elem_size) as usize) }
293-
if r != MojoResult::Okay { Err(r) } else { Ok(buf) }
293+
if r != MojoResult::Okay {
294+
Err(r)
295+
} else {
296+
Ok(buf)
297+
}
294298
}
295299

296300
/// Begin two-phase read. Returns a ReadDataBuffer to perform read and

mojo/public/rust/system/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// found in the LICENSE file.
44

55
#![feature(maybe_uninit_slice)]
6-
// Require unsafe blocks for unsafe operations even in an unsafe fn.
7-
#![deny(unsafe_op_in_unsafe_fn)]
86

97
mod handle;
108
mod mojo_types;

mojo/public/rust/system/shared_buffer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ impl SharedBuffer {
176176
info.inner_mut_ptr(),
177177
)
178178
});
179-
if r != MojoResult::Okay { Err(r) } else { Ok(info.size) }
179+
if r != MojoResult::Okay {
180+
Err(r)
181+
} else {
182+
Ok(info.size)
183+
}
180184
}
181185
}
182186

0 commit comments

Comments
 (0)