Skip to content

Commit

Permalink
tools/build.rs: Move rav1d-lib specific stuff to its own `build.r…
Browse files Browse the repository at this point in the history
…s` so `rav1d` can cross compile to/from windows.
  • Loading branch information
kkysen committed Jul 17, 2024
1 parent abbc5ae commit fd6d002
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,41 +310,4 @@ fn main() {
{
asm::main();
}

// 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;
use std::env;

let os = env::var("CARGO_CFG_TARGET_OS").expect("missing CARGO_CFG_TARGET_OS");
let target = env::var("TARGET").expect("missing TARGET");
if os == "windows" {
// for sprintf, snprintf, etc.
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}");
}
}
}
3 changes: 3 additions & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ cfg-if = "1.0.0"
libc = "0.2"
rav1d = { path = "../", version = "0.2.0", default-features = false }

[build-dependencies]
cc = "1.0.79"

[features]
default = ["asm", "bitdepth_8", "bitdepth_16"]
asm = ["rav1d/asm"]
Expand Down
38 changes: 38 additions & 0 deletions tools/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
fn main() {
// 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;
use std::env;

let os = env::var("CARGO_CFG_TARGET_OS").expect("missing CARGO_CFG_TARGET_OS");
let target = env::var("TARGET").expect("missing TARGET");
if os == "windows" {
// for sprintf, snprintf, etc.
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}");
}
}
}

0 comments on commit fd6d002

Please sign in to comment.