1 Star 0 Fork 28

hw-wLiu/hdc_rust

forked from leiguangyu/hdc_rust 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
build.rs 2.93 KB
一键复制 编辑 原始数据 按行查看 历史
liupeng298 提交于 2023-11-21 02:29 . !103 tmode port/ bugs
extern crate cc;
use std::env;
use std::path::Path;
const INCLUDE_PATH: &str = "include";
const MEMCPY_PATH: &str = "src/memcpy_s.c";
const MEMSET_PATH: &str = "src/memset_s.c";
const LZ4_CPATH: &str = "lz4.c";
const BCF_PATH: &str = "third_party/bounds_checking_function";
const LZ4_PATH: &str = "third_party/lz4/lib/";
fn main() {
let oh_path = env::var_os("OH_DIR");
let bcf_path = match env::var_os("BCF_DIR") {
Some(path) => path,
None => {
if let Some(path) = oh_path.clone() {
Path::new(&path).join(BCF_PATH).as_os_str().to_owned()
} else {
panic!("neither [BCF_DIR=/path/to/bounds_checking_function] nor [OH_DIR] is not found in env");
}
}
};
let lz4_src = if let Some(path) = oh_path.clone() {
Path::new(&path).join(LZ4_PATH).as_os_str().to_owned()
} else {
panic!("[OH_DIR] is not found in env");
};
let bcf_header = Path::new(&bcf_path).join(INCLUDE_PATH);
let memcpy_src = Path::new(&bcf_path).join(MEMCPY_PATH);
let memset_src = Path::new(&bcf_path).join(MEMSET_PATH);
let lz4_src_cpp = Path::new(&lz4_src).join(LZ4_CPATH).clone();
let cpp_files = vec![
memcpy_src.to_str().unwrap(),
memset_src.to_str().unwrap(),
lz4_src_cpp.to_str().unwrap(),
"src/cffi/serial_struct.cpp",
"src/cffi/uart.cpp",
"src/cffi/uart_wrapper.cpp",
"src/cffi/usb_util.cpp",
"src/cffi/oh_usb.cpp",
"src/cffi/usb_wrapper.cpp",
"src/cffi/mount.cpp",
"src/cffi/mount_wrapper.cpp",
"src/cffi/transfer.cpp",
];
let mut build = cc::Build::new();
build
.include(bcf_header)
.include("/usr/include/")
.include("/usr/lib/gcc/x86_64-linux-gnu/9/include/")
.include(lz4_src)
.files(cpp_files)
.cpp(true)
.flag("--std=c++17");
if cfg!(target_os = "macos") {
build.flag("-D HOST_MAC");
} else if cfg!(target_os = "linux") {
build.flag("-D HOST_LINUX");
}
build.compile("serial_struct");
if cfg!(target_os = "windows") {
const MINGW_PATH: &str =
"prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32";
const WINDEP_SRC: &str = "src/cffi/win_dep.cpp";
let mingw_path = match env::var_os("MINGW_DIR") {
Some(path) => path,
None => {
if let Some(path) = oh_path {
Path::new(&path).join(MINGW_PATH).as_os_str().to_owned()
} else {
panic!("neither [MINGW_DIR=/path/to/x86_64-w64-mingw32] nor [OH_DIR] is not found in env");
}
}
};
let include_dep = Path::new(&mingw_path).join(INCLUDE_PATH);
cc::Build::new()
.include(include_dep)
.file(WINDEP_SRC)
.cpp(true)
.flag("--std=c++17")
.compile("win_dep");
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Rust
1
https://gitee.com/windeliu/hdc_rust.git
git@gitee.com:windeliu/hdc_rust.git
windeliu
hdc_rust
hdc_rust
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385