-
Notifications
You must be signed in to change notification settings - Fork 38
Workarounds in build.rs for Windows compilation #270
Conversation
bors try |
artifact-app/build.rs
Outdated
.unwrap(); | ||
&BOOK.as_path() | ||
.to_str() | ||
.expect("Invalid book dir")[shortened.start() .. shortened.end()] |
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.
I'm still unsure how this equates to what you want. Does this really work for all of these case?
C:/foo
C:/foo/bar
//?/C:foo/bar/baz
I think you are trying to remove the leading //?/
, but wouldn't you want to slice from book[shortened.start() .. ]
?
The fact that windows doesn't accept it's own absolute paths is very concerning, and suggests to me that path_abs
(a crate I maintain in ergo
) should handle this case. Maybe PathInfo::to_non_absolute()
or some such method.
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.
See regex tests here for demonstration: https://regex101.com/r/pOevIF/1
The slice could be changed to [shortened.start .. ]
, which is more concise and essentially the same since the end of the matched text will always be the end of the string, .+
matching any number of any character - it's a matter of style so it's up to you.
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.
On the topic of the windows API - everything in the windows API is concerning. I think the issue here, however, is likely in std::process::Command. I need to put more time into investigating this, but if the issue is in the standard library here it makes more sense for that to be fixed rather than having to handle strange platform edge cases in your own library.
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.
somehow I missed the .
. Makes sense now. Either is fine.
@@ -23,10 +23,12 @@ lazy_static! { | |||
fn check_deps() { | |||
println!("Checking dependencies"); | |||
|
|||
let path_finding_cmd = if cfg!(windows) {"where"} else {"which"}; |
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.
I think I previously had this, and it didn't work in travis. I think travis runs it in a shell-like env in windows.
I'm wondering.... I've heard that windows now supports bash? Does it make sense to build this in windows bash? What version of windows are you building on?
Maybe we could do not just cfg!(windows)
but also key on the version of windows. Thoughts?
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.
There are a few options for "bash" in windows. One is Windows Linux Subsystem, which does give you essentially a true bash shell in windows. This isn't built in though, and requires the system hypervisor. This means that Docker, VirtualBox / other VM environments, and WLS all block each other from running. You can't usually rely on this feature unfortunately - I wish that you could. The other option is the MinGW / Git shell, which is just a program along with a bunch of implementations of common shell utilities. Git shell you can pretty much count on being installed on any windows computer which is git cloning any git repository, it's part of the standard windows git installation. It is used so that git hooks, etc., can run cross-platform. Perhaps this is where Travis runs? It may be possible to enforce running which
inside of the git shell on windows to accomplish cross-platform support here.
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.
fun, I didn't realize all of that.
I think it would be good if windows developers could run -- and it also ran in travis. I'm not sure why bors is having issues and travis isn't running. I have to investigate...
PR updated with code nice-ification |
tryTimed out |
never mind, it looks like travis windows nearly passed -- a couple of "serve" tests failed, which I'm not terribly concerned with -- especially if there is a windows user capable of PR's. Would you mind taking a look at the failures and seeing if you can replicate+fix -- or at least see if they might be related to this PR? I wouldn't be surprised if they aren't related. |
Cargo.lock
Outdated
@@ -1,3 +1,5 @@ | |||
# This file is automatically @generated by Cargo. |
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.
lol
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.
I included it reflexively because of this without really inspecting the contents of the change. Yeah, not really needed.
artifact-app/build.rs
Outdated
|
||
let mdbook_dir = if cfg!(windows) { | ||
|
||
let regex = Regex::new("[a-zA-Z].+").unwrap(); |
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.
nit: I think i would like this slightly better if it were r"[a-zA-Z]+:.*"
because at least I know I'm looking at a windows drive (C:/
). However, it's up to you.
artifact-app/build.rs
Outdated
|
||
let regex = Regex::new("[a-zA-Z].+").unwrap(); | ||
let dir_as_str = BOOK.as_path().to_str().expect("Invalid book dir"); | ||
let shortened = regex.find(dir_as_str).unwrap(); |
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.
just return regex.find(dir_as_str).unwrap().as_str()
instead of taking the slice.
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.
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.
oh, that's a really neat feature.
artifact-app/build.rs
Outdated
&dir_as_str[shortened.start() .. shortened.end()] | ||
} else { | ||
|
||
BOOK.as_path().to_str().expect("Invalid book dir") |
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.
move dir_as_str
up to remove this duplicate as well.
Alright, cleaned things up a little more. I've ran the failed Travis test cases on my local machine and was able to handle them without issue - I can take a deeper look and maybe uncover a little more this evening. |
Update on the extended length paths issue. I ran the following code expecting
So I need to go back and do more digging. It is possible that my workaround regex stuff isn't needed, and there is a simpler solution here. I will look into it this evening. |
Thanks for all of this. I strongly support getting this running on windows, but just a heads up that I'm doing a rewrite in python for easier inclusion in build systems (and cross-platform support). See #271 |
where
on windows rather thanwhich
std::process::Command.current_dir
not accepting them