-
Notifications
You must be signed in to change notification settings - Fork 38
Workarounds in build.rs for Windows compilation #270
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,12 @@ lazy_static! { | |
fn check_deps() { | ||
println!("Checking dependencies"); | ||
|
||
let path_finding_cmd = if cfg!(windows) {"where"} else {"which"}; | ||
|
||
let mut missing = Vec::new(); | ||
|
||
let check_cmd = |m: &mut Vec<_>, cmd: &'static str| { | ||
let is_ok = Command::new("which") | ||
let is_ok = Command::new(path_finding_cmd) | ||
.args(&[cmd]) | ||
.output() | ||
.expect("which/where doesn't exist") | ||
|
@@ -53,8 +55,22 @@ fn check_deps() { | |
|
||
fn build_mdbook() { | ||
println!("Building the book"); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think i would like this slightly better if it were |
||
let shortened = regex.find(BOOK.as_path().to_str().expect("Invalid book dir")) | ||
visceralfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.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 commentThe 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?
I think you are trying to remove the leading The fact that windows doesn't accept it's own absolute paths is very concerning, and suggests to me that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See regex tests here for demonstration: https://regex101.com/r/pOevIF/1 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. somehow I missed the |
||
} else { | ||
|
||
BOOK.as_path().to_str().expect("Invalid book dir") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move |
||
}; | ||
|
||
let _status = Command::new("mdbook") | ||
.current_dir(BOOK.as_path()) | ||
.current_dir(mdbook_dir) | ||
.args(&["build"]) | ||
.status() | ||
.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.
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...