如何在 Rust 货物构建脚本上调用批处理构建器脚本?
rust-onig项目需要编译oniguruma C 项目。这源于问题错误:无法为尝试在 Windows 上构建的“onig_sys v61.1.0”运行自定义构建命令oniguruma
。后来注意到在 Visual Studio 2015 中的 windows 上,我们需要调用make_win32.bat
, 而不是cmake
构建oniguruma
C 项目。
但是我不知道如何让cargo
构建器调用make_win32.bat
构建脚本。基于build-script ,我编辑了尝试使用的默认构建器build.rscmake
,而不是make_win32.bat
:
extern crate pkg_config;
extern crate cmake;
// use std::env;
// fn compile_with_cmake() {
// use cmake::Config;
// let static_link = env::var("CARGO_FEATURE_STATIC_ONIG").is_ok();
// // Builds the project in the directory located in `oniguruma`, installing it
// // into $OUT_DIR
// let mut c = Config::new("oniguruma");
// let dst = if static_link {
// c.define("BUILD_SHARED_LIBS", "OFF")
// } else {
// c.define("CMAKE_MACOSX_RPATH", "NO")
// }
// .build();
// let link_type = if static_link {
// "static"
// } else {
// "dylib"
// };
// println!("cargo:rustc-link-search=native={}",
// dst.join("build").display());
// println!("cargo:rustc-link-lib={}=onig", link_type);
// }
pub fn main() {
println!("Opening MAIN!!!!!!!!\n\n\n\n");
use std::process::Command;
let status = Command::new("D:\\User\\Downloads\\rust-onig\\onig_sys\\oniguruma\\make_win32.bat").status().unwrap_or_else(|e|
{
panic!("failed to execute process: {}", e)
});
println!("process exited with: {}", status);
println!("process exited with: {}", status);
println!("process exited with: {}", status);
println!("process exited with: {}", status);
println!("process exited with: {}", status);
// if let Ok(_) = pkg_config::find_library("oniguruma") {
// return;
// }
// compile_with_cmake();
}
但是我的构建器脚本没有被调用,因为该消息process exited with
从未显示:
D:\Downloads\rust-onig>cargo build
Compiling onig_sys v61.1.0 (file:///D:/User/Downloads/rust-onig/onig_sys)
Compiling onig v1.2.0 (file:///D:/User/Downloads/rust-onig)
warning: unused import: `c_ulong`, #[warn(unused_imports)] on by default
--> src\names.rs:6:27
|
6 | use libc::{c_int, c_uint, c_ulong, c_void, c_uchar};
| ^^^^^^^
Finished dev [unoptimized + debuginfo] target(s) in 11.31 secs
D:\Downloads\rust-onig>
显示什么,我们什么时候尝试使用cmake
构建器可以在问题上查看这源于问题错误:未能为`onig_sys v61.1.0`运行自定义构建命令
存在的问题cmake
是生成了几个Visual Studio
项目,这些项目完全不知道如何构建oniguruma
。能够有效构建它的唯一解决方案是make_win32.bat
已经包含在oniguruma
. 此外,我们需要使用 themake_win32.bat
而不是 let cmake
generation Visual Studio
。