From fd6d0026a2596067bc279547a31c005d18c4b149 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 17 Jul 2024 03:59:40 -0700 Subject: [PATCH] `tools/build.rs`: Move `rav1d-lib` specific stuff to its own `build.rs` so `rav1d` can cross compile to/from windows. --- Cargo.lock | 1 + build.rs | 37 ------------------------------------- tools/Cargo.toml | 3 +++ tools/build.rs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 tools/build.rs diff --git a/Cargo.lock b/Cargo.lock index cd9ceec7a..a375d5ae8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,6 +190,7 @@ dependencies = [ name = "rav1d_cli" version = "0.2.0" dependencies = [ + "cc", "cfg-if", "libc", "rav1d", diff --git a/build.rs b/build.rs index 473e203da..951753735 100644 --- a/build.rs +++ b/build.rs @@ -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}"); - } - } } diff --git a/tools/Cargo.toml b/tools/Cargo.toml index e98c19ac9..79e60cc77 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -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"] diff --git a/tools/build.rs b/tools/build.rs new file mode 100644 index 000000000..7746efacc --- /dev/null +++ b/tools/build.rs @@ -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}"); + } + } +}