Skip to content

Commit a424a81

Browse files
committed
Auto merge of rust-lang#104456 - RalfJung:miri, r=RalfJung
update Miri Not a huge sync, but there was a conflict and [josh](https://github.com/josh-project/josh/) seems to prefer those to be merged back ASAP.
2 parents c1d6ff4 + ed72e77 commit a424a81

19 files changed

+305
-335
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ jobs:
6767
shell: bash
6868
run: |
6969
if [[ ${{ github.event_name }} == 'schedule' ]]; then
70-
./miri toolchain HEAD --host ${{ matrix.host_target }}
71-
else
72-
./miri toolchain "" --host ${{ matrix.host_target }}
70+
echo "Building against latest rustc git version"
71+
git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
7372
fi
73+
./miri toolchain --host ${{ matrix.host_target }}
7474
7575
- name: Show Rust version
7676
run: |

CONTRIBUTING.md

+9-24
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ is set the `MIRI_LIB_SRC` environment variable to the `library` folder of a
150150
`rust-lang/rust` repository checkout. Note that changing files in that directory
151151
does not automatically trigger a re-build of the standard library; you have to
152152
clear the Miri build cache manually (on Linux, `rm -rf ~/.cache/miri`;
153-
and on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`).
153+
on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`;
154+
and on macOS, `rm -rf ~/Library/Caches/org.rust-lang.miri`).
154155

155156
### Benchmarking
156157

@@ -208,23 +209,6 @@ We described above the simplest way to get a working build environment for Miri,
208209
which is to use the version of rustc indicated by `rustc-version`. But
209210
sometimes, that is not enough.
210211

211-
### Updating `rustc-version`
212-
213-
The `rustc-version` file is regularly updated to keep Miri close to the latest
214-
version of rustc. Usually, new contributors do not have to worry about this. But
215-
sometimes a newer rustc is needed for a patch, and sometimes Miri needs fixing
216-
for changes in rustc. In both cases, `rustc-version` needs updating.
217-
218-
To update the `rustc-version` file and install the latest rustc, you can run:
219-
```
220-
./miri toolchain HEAD
221-
```
222-
223-
Now edit Miri until `./miri test` passes, and submit a PR. Generally, it is
224-
preferred to separate updating `rustc-version` and doing what it takes to get
225-
Miri working again, from implementing new features that rely on the updated
226-
rustc. This avoids blocking all Miri development on landing a big PR.
227-
228212
### Building Miri with a locally built rustc
229213

230214
[building Miri with a locally built rustc]: #building-miri-with-a-locally-built-rustc
@@ -282,13 +266,13 @@ With this, you should now have a working development setup! See
282266
## Advanced topic: Syncing with the rustc repo
283267

284268
We use the [`josh` proxy](https://github.com/josh-project/josh) to transmit
285-
changes between the rustc and Miri repositories. For now, a fork of josh needs to be built
286-
from source. This downloads and runs josh:
269+
changes between the rustc and Miri repositories. For now, the latest git version
270+
of josh needs to be built from source. This downloads and runs josh:
287271

288272
```sh
289-
git clone https://github.com/RalfJung/josh
273+
git clone https://github.com/josh-project/josh
290274
cd josh
291-
cargo run --release -p josh-proxy -- --local=$(pwd)/local --remote=https://github.com --no-background
275+
cargo run --release -p josh-proxy -- --local=local --remote=https://github.com --no-background
292276
```
293277

294278
### Importing changes from the rustc repo
@@ -298,9 +282,10 @@ We assume we start on an up-to-date master branch in the Miri repo.
298282

299283
```sh
300284
# Fetch and merge rustc side of the history. Takes ca 5 min the first time.
285+
# This will also update the 'rustc-version' file.
301286
./miri rustc-pull
302-
# Update toolchain reference and apply formatting.
303-
./miri toolchain HEAD && ./miri fmt
287+
# Update local toolchain and apply formatting.
288+
./miri toolchain && ./miri fmt
304289
git commit -am "rustup"
305290
```
306291

Cargo.lock

+55-61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ libloading = "0.7"
4040

4141
[dev-dependencies]
4242
colored = "2"
43-
ui_test = "0.3.1"
43+
ui_test = "0.4"
4444
rustc_version = "0.4"
4545
# Features chosen to match those required by env_logger, to avoid rebuilds
4646
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ Moreover, Miri recognizes some environment variables:
432432
must point to the `library` subdirectory of a `rust-lang/rust` repository
433433
checkout. Note that changing files in that directory does not automatically
434434
trigger a re-build of the standard library; you have to clear the Miri build
435-
cache manually (on Linux, `rm -rf ~/.cache/miri`).
435+
cache manually (on Linux, `rm -rf ~/.cache/miri`;
436+
on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`;
437+
and on macOS, `rm -rf ~/Library/Caches/org.rust-lang.miri`).
436438
* `MIRI_SYSROOT` (recognized by `cargo miri` and the Miri driver) indicates the sysroot to use. When
437439
using `cargo miri`, this skips the automatic setup -- only set this if you do not want to use the
438440
automatically created sysroot. For directly invoking the Miri driver, this variable (or a
@@ -568,6 +570,15 @@ extern "Rust" {
568570
/// program) the contents of a section of program memory, as bytes. Bytes
569571
/// written using this function will emerge from the interpreter's stderr.
570572
fn miri_write_to_stderr(bytes: &[u8]);
573+
574+
/// Miri-provided extern function to allocate memory from the interpreter.
575+
///
576+
/// This is useful when no fundamental way of allocating memory is
577+
/// available, e.g. when using `no_std` + `alloc`.
578+
fn miri_alloc(size: usize, align: usize) -> *mut u8;
579+
580+
/// Miri-provided extern function to deallocate memory.
581+
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
571582
}
572583
```
573584

cargo-miri/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-miri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "4"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.15.0"
21-
rustc-build-sysroot = "0.3.3"
21+
rustc-build-sysroot = "0.4"
2222

2323
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
2424
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

cargo-miri/src/setup.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ffi::OsStr;
55
use std::path::PathBuf;
66
use std::process::{self, Command};
77

8-
use rustc_build_sysroot::{BuildMode, Sysroot, SysrootConfig};
8+
use rustc_build_sysroot::{BuildMode, SysrootBuilder, SysrootConfig};
99
use rustc_version::VersionMeta;
1010

1111
use crate::util::*;
@@ -70,9 +70,11 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
7070
let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
7171
SysrootConfig::NoStd
7272
} else {
73-
SysrootConfig::WithStd { std_features: &["panic_unwind", "backtrace"] }
73+
SysrootConfig::WithStd {
74+
std_features: ["panic_unwind", "backtrace"].into_iter().map(Into::into).collect(),
75+
}
7476
};
75-
let cargo_cmd = || {
77+
let cargo_cmd = {
7678
let mut command = cargo();
7779
// Use Miri as rustc to build a libstd compatible with us (and use the right flags).
7880
// However, when we are running in bootstrap, we cannot just overwrite `RUSTC`,
@@ -106,13 +108,14 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
106108
command.stdout(process::Stdio::null());
107109
command.stderr(process::Stdio::null());
108110
}
109-
// Disable debug assertions in the standard library -- Miri is already slow enough.
110-
// But keep the overflow checks, they are cheap. This completely overwrites flags
111-
// the user might have set, which is consistent with normal `cargo build` that does
112-
// not apply `RUSTFLAGS` to the sysroot either.
113-
let rustflags = vec!["-Cdebug-assertions=off".into(), "-Coverflow-checks=on".into()];
114-
(command, rustflags)
111+
112+
command
115113
};
114+
// Disable debug assertions in the standard library -- Miri is already slow enough.
115+
// But keep the overflow checks, they are cheap. This completely overwrites flags
116+
// the user might have set, which is consistent with normal `cargo build` that does
117+
// not apply `RUSTFLAGS` to the sysroot either.
118+
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
116119
// Make sure all target-level Miri invocations know their sysroot.
117120
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
118121

@@ -124,8 +127,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
124127
// We want to be quiet, but still let the user know that something is happening.
125128
eprint!("Preparing a sysroot for Miri (target: {target})... ");
126129
}
127-
Sysroot::new(&sysroot_dir, target)
128-
.build_from_source(&rust_src, BuildMode::Check, sysroot_config, rustc_version, cargo_cmd)
130+
SysrootBuilder::new(&sysroot_dir, target)
131+
.build_mode(BuildMode::Check)
132+
.rustc_version(rustc_version.clone())
133+
.sysroot_config(sysroot_config)
134+
.rustflags(rustflags)
135+
.cargo(cargo_cmd)
136+
.build_from_source(&rust_src)
129137
.unwrap_or_else(|_| {
130138
if only_setup {
131139
show_error!("failed to build sysroot, see error details above")

0 commit comments

Comments
 (0)