-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for the tempfile
crate
#2720
Conversation
I see the windows CI is failing, but there is a |
21661cb
to
566c541
Compare
Yes, miri supports cross interpretation. For testing you can use the |
I think I may still might be doing something the wrong way. If I look at the logs of the previous failed Windows run, I see two mentions of targets:
I tried running both targets on my Ubuntu machine like this: $ MIRI_TEST_TARGET="i686-uwp-windows-msvc" ./miri test tests/pass-dep/shims/libc-fs.rs
$ MIRI_TEST_TARGET="x86_64-unknown-linux-gnu" ./miri test tests/pass-dep/shims/libc-fs.rs and for good measure also all the other targets that mention Windows: $ rustc --print target-list | grep windows
aarch64-pc-windows-gnullvm
aarch64-pc-windows-msvc
aarch64-uwp-windows-msvc
i586-pc-windows-msvc
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-uwp-windows-gnu
i686-uwp-windows-msvc
thumbv7a-pc-windows-msvc
thumbv7a-uwp-windows-msvc
x86_64-pc-windows-gnu
x86_64-pc-windows-gnullvm
x86_64-pc-windows-msvc
x86_64-uwp-windows-gnu
x86_64-uwp-windows-msvc
$ rustc --print target-list | grep windows | xargs -I {} env MIRI_TEST_TARGET="{}" ./miri test tests/pass-dep/shims/libc-fs.rs But the test passes on all Windows targets on my machine, with the exception of targets The next Windows CI also finished just now and has a slightly different error now: The first time around, the error was:
And the second time the error is:
The difference is that in the first time, the test said (now no longer visible due to my earlier force push): /// Test that the [`tempfile`] crate is compatible with miri.
fn test_tempfile() {
tempfile::tempfile().unwrap();
} Which I changed to: /// Test that the [`tempfile`] crate is compatible with miri.
fn test_tempfile() {
let dir_path = tmp();
tempfile::tempfile_in(dir_path).unwrap();
} One other idea I could try is to add Also the Mac OS build had a network blip just now and failed early. I tried force pushing it again, but that doesn't seem to trigger a restart of the CI without changes ( Thanks! |
ah, the problem is a windows host interpreting a linux target. Oof. Maybe this is due to backslashes in names or sth? Not sure how to debug this. |
I would imagine it is because the call to These sort of issues are going to keep coming up, as I mentioned in https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Filesystem.20abstraction. I'd love to get some time to tackle it but currently I do not :-( |
Thanks for that pointer @LegNeato . Going through the zulip topic that you linked, it sounds like it would be a proper effort add path translation from a unix target family to a windows Host. On the bright side, we now have an actual example of this being a problem on Windows running a linux target :P (cc #1537) Considering that this can not be properly fixed without access to a Windows environment and a significant time investment, I believe that leaves me with two possible alternatives: Alternative 1Adjust the test case for Alternative 2We do not commit at this point in time to adding @oli-obk What do you think is the best course of action? Or maybe you know of a third viable alternative? Thanks! |
The PR seems to effectively just ignore most of the mode. Is that really a good idea?
|
Regarding the path problem: we already do path separator adjustment if host!=target, which so far was enough. It would be good to figure out what exactly happens here to understand why this is no longer enough. It is not too surprising that naive separator substitution is insufficient but it would still be good to learn why exactly it fails now.
I don't have a Windows machine either, but you can still add a bunch of debug printing and then see what happens on CI.
|
My first guess would be that the |
FWIW I think this would also not have been a problem if tempfile just called if !path.is_absolute() {
let cur_dir = env::current_dir()?;
tmp = cur_dir.join(path);
path = &tmp;
} |
Thanks for all that input @RalfJung ! My next steps for this PR will be:
|
Yeah that is the most pressing point. On a unix host we could directly use |
From what I've been able to research so far, it appears to be the case that the Windows file creation API has no concept of group permissions. Even if we find a work-around by calling the group permissions APIs ourselves after creating the file first, there is a discrepancy between the permission models of Windows and Unix: Unix distinguishes between the owner, a single additional group and everyone else; while Windows has a more complicated model that allows multiple users and multiple groups, and there is not a clear-cut way to map the only Linux owner/group to a Windows equivalent ("Everybody" is a group in Windows, though, so that part is at least somewhat straight-forward - assuming there is a Windows API that we can call to set the permissions for "Everyone", I was unable to find which API we need for that so far). |
566c541
to
372521f
Compare
The CI passes with the fixes from #2725 applied 🎉 The remaining open question is how to support Unix file modes on a Windows host, before this can be merged. Some thoughts about the file mode flag translation:
|
Setting it later won't be entirely correct though, someone could access the file between it being created and the permissions being adjusted. I guess the alternative would be to just not support this on a Windows host. So far we have kept our set of supported operations host-independent but as we move beyond what the Rust stdlib can provide, that might not always be feasible. |
That is a good point. In that case, does it makes sense to support all file modes on Unix platforms (including execute permissions) or still just a subset of the file modes which lets miri stay forward compatible for when the std lib does add support for this in the future? So far I was only able to deduce that modes To clarify what you mean by "not support this on a Windows host", should we either: 1) halt the interpreter by showing an unsupported error or 2) silently default to the default permissions when executing a Unix target on a Windows host? Thanks! |
In this version we would
|
@rustbot author |
☔ The latest upstream changes (presumably #2748) made this pull request unmergeable. Please resolve the merge conflicts. |
@Pointerbender I am closing this PR due to inactivity. Feel free to reopen or open a new PR if you want to get back to this! |
Hey I was wondering on the status of this. Would it be possible for me to help push this along, as the PR has been inactive for a while now? |
Support for tempfile crate on UNIX hosts Reviving old PR: #2720 Attempted to apply the changes as suggested by #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
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
tempfile
as a dependency intest_dependencies/Cargo.toml
tempfile::tempfile()
.