-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build.rs
: Fix windows cross compilation (#1323)
@thedataking, I only noticed after you merged #1295 a few things. This should let us cross-compile from windows, cross-compile to `*-windows-gnu` (I think; the linker wasn't installed so I couldn't test all the way), and print a clear error when trying to cross-compile to `*-windows-msvc`. It also lets us do full cross-compilation on `rav1d`, as the `snprintf` stuff for windows is only for `rav1d-cli`. * Fixes #1365.
- Loading branch information
Showing
4 changed files
with
61 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::env; | ||
|
||
fn main() { | ||
let os = env::var("CARGO_CFG_TARGET_OS").unwrap(); | ||
let env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); | ||
|
||
let os = os.as_str(); | ||
let env = env.as_str(); | ||
|
||
match (os, env) { | ||
("windows", "msvc") => { | ||
if !cfg!(all(target_os = "windows", target_env = "msvc")) { | ||
panic!("Cannot cross compile to *-windows-msvc"); | ||
} | ||
} | ||
#[allow(clippy::needless_return)] | ||
_ => return, | ||
} | ||
|
||
// NOTE: we rely on libraries that are only distributed for Windows so | ||
// targeting Windows/MSVC is not supported when cross compiling. | ||
#[cfg(all(target_os = "windows", target_env = "msvc"))] | ||
{ | ||
use cc::windows_registry; | ||
|
||
// for sprintf, snprintf, etc. | ||
let target = env::var("TARGET").unwrap(); | ||
println!("cargo:rustc-link-lib=static=oldnames"); | ||
let tool = windows_registry::find_tool(&target, "cl.exe") | ||
.expect("couldn't find cl.exe; are the Visual Studio C++ tools installed?"); | ||
let lib_paths = &tool | ||
.env() | ||
.iter() | ||
.find(|(key, _val)| key == "LIB") | ||
.expect("LIB path not found") | ||
.1; | ||
for path in lib_paths.to_str().unwrap().split(';') { | ||
if path != "" { | ||
println!("cargo:rustc-link-search={path}"); | ||
} | ||
} | ||
|
||
let getopt = "getopt"; | ||
cc::Build::new() | ||
.files([&"../tools/compat/getopt.c"]) | ||
.include("../include/compat") | ||
.debug(cfg!(debug_assertions)) | ||
.compile(&getopt); | ||
// cc automatically outputs the following line | ||
// println!("cargo:rustc-link-lib=static={getopt}"); | ||
} | ||
} |