Skip to content

Commit 0c2c93e

Browse files
committed
Auto merge of rust-lang#3240 - Jefffrey:tempfile, r=RalfJung
Support for tempfile crate on UNIX hosts Reviving old PR: rust-lang/miri#2720 Attempted to apply the changes as suggested by rust-lang/miri#2720 (comment) To fix tempfile to work for UNIX targets only and fall back to previous behaviour of only supporting default mode for Windows targets
2 parents 4658d38 + cf2ef7d commit 0c2c93e

File tree

4 files changed

+181
-16
lines changed

4 files changed

+181
-16
lines changed

src/tools/miri/src/shims/unix/fs.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
559559
);
560560
};
561561

562-
if mode != 0o666 {
563-
throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
562+
#[cfg(unix)]
563+
{
564+
// Support all modes on UNIX host
565+
use std::os::unix::fs::OpenOptionsExt;
566+
options.mode(mode);
567+
}
568+
#[cfg(not(unix))]
569+
{
570+
// Only support default mode for non-UNIX (i.e. Windows) host
571+
if mode != 0o666 {
572+
throw_unsup_format!(
573+
"non-default mode 0o{:o} is not supported on non-Unix hosts",
574+
mode
575+
);
576+
}
564577
}
565578

566579
mirror |= o_creat;

src/tools/miri/test_dependencies/Cargo.lock

+144-14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ version = "1.3.2"
4444
source = "registry+https://github.com/rust-lang/crates.io-index"
4545
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
4646

47+
[[package]]
48+
name = "bitflags"
49+
version = "2.4.1"
50+
source = "registry+https://github.com/rust-lang/crates.io-index"
51+
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
52+
4753
[[package]]
4854
name = "bumpalo"
4955
version = "3.14.0"
@@ -71,6 +77,22 @@ version = "1.0.0"
7177
source = "registry+https://github.com/rust-lang/crates.io-index"
7278
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
7379

80+
[[package]]
81+
name = "errno"
82+
version = "0.3.8"
83+
source = "registry+https://github.com/rust-lang/crates.io-index"
84+
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
85+
dependencies = [
86+
"libc",
87+
"windows-sys 0.52.0",
88+
]
89+
90+
[[package]]
91+
name = "fastrand"
92+
version = "2.0.1"
93+
source = "registry+https://github.com/rust-lang/crates.io-index"
94+
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
95+
7496
[[package]]
7597
name = "getrandom"
7698
version = "0.1.16"
@@ -122,6 +144,12 @@ version = "0.2.148"
122144
source = "registry+https://github.com/rust-lang/crates.io-index"
123145
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
124146

147+
[[package]]
148+
name = "linux-raw-sys"
149+
version = "0.4.12"
150+
source = "registry+https://github.com/rust-lang/crates.io-index"
151+
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
152+
125153
[[package]]
126154
name = "lock_api"
127155
version = "0.4.10"
@@ -161,7 +189,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
161189
dependencies = [
162190
"libc",
163191
"wasi 0.11.0+wasi-snapshot-preview1",
164-
"windows-sys",
192+
"windows-sys 0.48.0",
165193
]
166194

167195
[[package]]
@@ -174,6 +202,7 @@ dependencies = [
174202
"num_cpus",
175203
"page_size",
176204
"rand",
205+
"tempfile",
177206
"tokio",
178207
]
179208

@@ -230,9 +259,9 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
230259
dependencies = [
231260
"cfg-if",
232261
"libc",
233-
"redox_syscall",
262+
"redox_syscall 0.3.5",
234263
"smallvec",
235-
"windows-targets",
264+
"windows-targets 0.48.5",
236265
]
237266

238267
[[package]]
@@ -301,7 +330,16 @@ version = "0.3.5"
301330
source = "registry+https://github.com/rust-lang/crates.io-index"
302331
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
303332
dependencies = [
304-
"bitflags",
333+
"bitflags 1.3.2",
334+
]
335+
336+
[[package]]
337+
name = "redox_syscall"
338+
version = "0.4.1"
339+
source = "registry+https://github.com/rust-lang/crates.io-index"
340+
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
341+
dependencies = [
342+
"bitflags 1.3.2",
305343
]
306344

307345
[[package]]
@@ -310,6 +348,19 @@ version = "0.1.23"
310348
source = "registry+https://github.com/rust-lang/crates.io-index"
311349
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
312350

351+
[[package]]
352+
name = "rustix"
353+
version = "0.38.21"
354+
source = "registry+https://github.com/rust-lang/crates.io-index"
355+
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
356+
dependencies = [
357+
"bitflags 2.4.1",
358+
"errno",
359+
"libc",
360+
"linux-raw-sys",
361+
"windows-sys 0.48.0",
362+
]
363+
313364
[[package]]
314365
name = "scopeguard"
315366
version = "1.2.0"
@@ -338,7 +389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
338389
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
339390
dependencies = [
340391
"libc",
341-
"windows-sys",
392+
"windows-sys 0.48.0",
342393
]
343394

344395
[[package]]
@@ -352,6 +403,19 @@ dependencies = [
352403
"unicode-ident",
353404
]
354405

406+
[[package]]
407+
name = "tempfile"
408+
version = "3.8.1"
409+
source = "registry+https://github.com/rust-lang/crates.io-index"
410+
checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
411+
dependencies = [
412+
"cfg-if",
413+
"fastrand",
414+
"redox_syscall 0.4.1",
415+
"rustix",
416+
"windows-sys 0.48.0",
417+
]
418+
355419
[[package]]
356420
name = "tokio"
357421
version = "1.32.0"
@@ -368,7 +432,7 @@ dependencies = [
368432
"signal-hook-registry",
369433
"socket2",
370434
"tokio-macros",
371-
"windows-sys",
435+
"windows-sys 0.48.0",
372436
]
373437

374438
[[package]]
@@ -482,7 +546,16 @@ version = "0.48.0"
482546
source = "registry+https://github.com/rust-lang/crates.io-index"
483547
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
484548
dependencies = [
485-
"windows-targets",
549+
"windows-targets 0.48.5",
550+
]
551+
552+
[[package]]
553+
name = "windows-sys"
554+
version = "0.52.0"
555+
source = "registry+https://github.com/rust-lang/crates.io-index"
556+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
557+
dependencies = [
558+
"windows-targets 0.52.0",
486559
]
487560

488561
[[package]]
@@ -491,13 +564,28 @@ version = "0.48.5"
491564
source = "registry+https://github.com/rust-lang/crates.io-index"
492565
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
493566
dependencies = [
494-
"windows_aarch64_gnullvm",
495-
"windows_aarch64_msvc",
496-
"windows_i686_gnu",
497-
"windows_i686_msvc",
498-
"windows_x86_64_gnu",
499-
"windows_x86_64_gnullvm",
500-
"windows_x86_64_msvc",
567+
"windows_aarch64_gnullvm 0.48.5",
568+
"windows_aarch64_msvc 0.48.5",
569+
"windows_i686_gnu 0.48.5",
570+
"windows_i686_msvc 0.48.5",
571+
"windows_x86_64_gnu 0.48.5",
572+
"windows_x86_64_gnullvm 0.48.5",
573+
"windows_x86_64_msvc 0.48.5",
574+
]
575+
576+
[[package]]
577+
name = "windows-targets"
578+
version = "0.52.0"
579+
source = "registry+https://github.com/rust-lang/crates.io-index"
580+
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
581+
dependencies = [
582+
"windows_aarch64_gnullvm 0.52.0",
583+
"windows_aarch64_msvc 0.52.0",
584+
"windows_i686_gnu 0.52.0",
585+
"windows_i686_msvc 0.52.0",
586+
"windows_x86_64_gnu 0.52.0",
587+
"windows_x86_64_gnullvm 0.52.0",
588+
"windows_x86_64_msvc 0.52.0",
501589
]
502590

503591
[[package]]
@@ -506,38 +594,80 @@ version = "0.48.5"
506594
source = "registry+https://github.com/rust-lang/crates.io-index"
507595
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
508596

597+
[[package]]
598+
name = "windows_aarch64_gnullvm"
599+
version = "0.52.0"
600+
source = "registry+https://github.com/rust-lang/crates.io-index"
601+
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
602+
509603
[[package]]
510604
name = "windows_aarch64_msvc"
511605
version = "0.48.5"
512606
source = "registry+https://github.com/rust-lang/crates.io-index"
513607
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
514608

609+
[[package]]
610+
name = "windows_aarch64_msvc"
611+
version = "0.52.0"
612+
source = "registry+https://github.com/rust-lang/crates.io-index"
613+
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
614+
515615
[[package]]
516616
name = "windows_i686_gnu"
517617
version = "0.48.5"
518618
source = "registry+https://github.com/rust-lang/crates.io-index"
519619
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
520620

621+
[[package]]
622+
name = "windows_i686_gnu"
623+
version = "0.52.0"
624+
source = "registry+https://github.com/rust-lang/crates.io-index"
625+
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
626+
521627
[[package]]
522628
name = "windows_i686_msvc"
523629
version = "0.48.5"
524630
source = "registry+https://github.com/rust-lang/crates.io-index"
525631
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
526632

633+
[[package]]
634+
name = "windows_i686_msvc"
635+
version = "0.52.0"
636+
source = "registry+https://github.com/rust-lang/crates.io-index"
637+
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
638+
527639
[[package]]
528640
name = "windows_x86_64_gnu"
529641
version = "0.48.5"
530642
source = "registry+https://github.com/rust-lang/crates.io-index"
531643
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
532644

645+
[[package]]
646+
name = "windows_x86_64_gnu"
647+
version = "0.52.0"
648+
source = "registry+https://github.com/rust-lang/crates.io-index"
649+
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
650+
533651
[[package]]
534652
name = "windows_x86_64_gnullvm"
535653
version = "0.48.5"
536654
source = "registry+https://github.com/rust-lang/crates.io-index"
537655
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
538656

657+
[[package]]
658+
name = "windows_x86_64_gnullvm"
659+
version = "0.52.0"
660+
source = "registry+https://github.com/rust-lang/crates.io-index"
661+
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
662+
539663
[[package]]
540664
name = "windows_x86_64_msvc"
541665
version = "0.48.5"
542666
source = "registry+https://github.com/rust-lang/crates.io-index"
543667
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
668+
669+
[[package]]
670+
name = "windows_x86_64_msvc"
671+
version = "0.52.0"
672+
source = "registry+https://github.com/rust-lang/crates.io-index"
673+
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"

src/tools/miri/test_dependencies/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = "2021"
1111
# all dependencies (and their transitive ones) listed here can be used in `tests/`.
1212
libc = "0.2"
1313
num_cpus = "1.10.1"
14+
tempfile = "3"
1415

1516
getrandom_01 = { package = "getrandom", version = "0.1" }
1617
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ignore-target-windows: File handling is not implemented yet
2+
//@ignore-host-windows: Only supported for UNIX hosts
3+
//@compile-flags: -Zmiri-disable-isolation
4+
5+
#[path = "../utils/mod.rs"]
6+
mod utils;
7+
8+
/// Test that the [`tempfile`] crate is compatible with miri for UNIX hosts and targets
9+
fn main() {
10+
test_tempfile();
11+
test_tempfile_in();
12+
}
13+
14+
fn test_tempfile() {
15+
tempfile::tempfile().unwrap();
16+
}
17+
18+
fn test_tempfile_in() {
19+
let dir_path = utils::tmp();
20+
tempfile::tempfile_in(dir_path).unwrap();
21+
}

0 commit comments

Comments
 (0)