-
Notifications
You must be signed in to change notification settings - Fork 353
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
change cargo-miri.rs to fix issue #978 #980
Conversation
Thanks for the PR!
This seems like a work-around instead of fixing the actual issue. Do you have an idea what causes the issue, and why a work-around is better than a fix? I don't think we should add hacks like this without at least trying to properly fix the underlying issue.
Also without being exercised on CI this will inevitably break again.
|
@RalfJung Thank you for your feedback 👍 From my current understanding, the environment variable MIRI_SYSROOT is set inside the setup function (Line 337, cargo-miri.rs). Lines 336 to 342 in de4a846
May I ask why the setup function is called twice inside the build_sysroot function (from the miri bash script) ? It seems to me that calling the setup function once should be enough to set MIRI_SYSROOT.
From my understanding, std::env::set_var("MIRI_SYSROOT", content) is stripping all backslashes from content before storing it to the environment variable "MIRI_SYSROOT". No matter how many numbers of backslashes are in the second argument, it just seems that all the backslashes are simply dropped before storing the string to MIRI_SYSROOT. Currently, I don't have a good idea to fix this other than the proposed work-around in this pull-request. I can try looking into it with more time to come up with a better solution. |
Is it possible that this is windows specific? (sorry I don't have a Windows machine to try :P). If you run the following code, does it strip the fn main() {
std::env::set_var("TEST_VAR", "C:\\A\\B\\C");
println!("{:?}", std::env::var("TEST_VAR"));
} On linux the string is unchanged. |
That is definitely not desired behavior. Can you reproduce this in a stand-alone program? If yes, please report a bug for rustc. It seems surprising that such a critical bug would go unnoticed for so long though.
There are comments there explaining this. Basically, the first time runs the setup with output so the user sees what happens; the second time runs setup again which should be a NOP, but this time we capture the output and use it to determine the sysroot location. Indeed the following build_sysroot() {
eval $(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env "$@")
} But now the user would not see any build log from the libstd build, and if there are errors during that build they are silently discarded. That's not great behavior. But maybe that build_sysroot() {
# Build once, for the user to see.
cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup "$@"
# Call again, to just set env var.
eval "$(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env "$@")"
} |
@christianpoveda , @RalfJung The below screenshot shows a minimal reproduction of what was happening to me.
I committed another fix to change line 339(cargo-miri.rs) to not use I've tested that the fixed version works as expected both on Windows10 and Ubuntu(Windows Subsystem for Linux) |
It turns out that there is nothing wrong with the current implementation of |
Hmm... that's suspicious. I think that calling
So even if the path is not a valid unicode string it should be able to print it, idk why is it messing a perfectly valid unicode path in windows (on linux: https://play.integer32.com/?version=stable&mode=debug&edition=2018&gist=33c62dac4f10f4f524e9ce11ed343acf) Edit: Is it possible that for some reason, when doing |
I'm sorry if my explanation up there was unclear.. I checked the rustplayground link you shared, and I see that Path.display() outputs a string with a valid Windows path with backslashes. The real problem is that, the What our Rust code needs to print out to the console in this particular case is C:\\Foo\\Bar\\Baz. |
The confusion comes from the fact that |
Uhh ok i got it now. So is it there any way to not escape those |
@christianpoveda |
Maybe use |
After playing with bash for a while and smashing my head against the keyboard... What happens if instead of doing println!("MIRI_SYSROOT={:?}", &sysroot); you do println!("MIRI_SYSROOT=\"{}\"", sysroot.display()); I think this is just the shell messing up the escaping because the string is not quoted. Like in bash: PD: I feel like a conspiracy theory guy with this escaping stuff, sorry for my sloppy comments :P |
That's odd, in my bash it works. Do you remember when stuff was platform independent :P (me neither). What about @bjorn3's idea? |
@bjorn3 's idea also seems to be a valid way to solve the problem, and is a very similar approach to my initial commit for this issue. |
Ah yes that makes a lot of sense. Bash interprets this as shell so it applies one level of escaping. |
src/bin/cargo-miri.rs
Outdated
std::env::set_var("MIRI_SYSROOT", &sysroot); // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags | ||
if print_env { | ||
println!("MIRI_SYSROOT={}", sysroot.display()); | ||
println!("MIRI_SYSROOT={:?}", &sysroot); // for Windows users, prints path with backslashes escaped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not just for Windows users. It just as much affects Linux users with '
, "
or \
in the path (all of which are valid filename characters on Linux).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Do you think I should add a macro for conditional compilation for Windows users??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, what I am saying is the bug you are fixing also affects other platforms. With conditional compilation you'd only fix it on Windows, why do you want that? :D
That'll go horribly wrong if there are However, this made me realize that The strongest escape in shell is
Yeah this looks like a bad joke, I know... it's, in this order:
Does this make sense? |
Thanks for the PR! @bors r+ |
📌 Commit 65fd006 has been approved by |
change cargo-miri.rs to fix issue #978 In Windows 10, there was an issue with building MIRI locally and getting it running, due to unpredictable backslash escaping issues in paths. I added a code snippet that would only be compiled in Windows OS, which replaces all backslashes in paths to slashes. This fix should only affect Windows users. Building and testing MIRI locally now works fine after the fix. ![miri_result_after_fix0](https://user-images.githubusercontent.com/10286488/66260998-344abc80-e794-11e9-9d7c-b4ef098443de.PNG) Fixes #978
☀️ Test successful - checks-travis, status-appveyor |
explain our shell encoding Follow-up to #980
explain our shell encoding Follow-up to #980
In Windows 10, there was an issue with building MIRI locally and getting it running,
due to unpredictable backslash escaping issues in paths.
I added a code snippet that would only be compiled in Windows OS, which replaces all backslashes in paths to slashes.
This fix should only affect Windows users.
Building and testing MIRI locally now works fine after the fix.
Fixes #978