diff --git a/ylong_ffrt/Cargo.toml b/ylong_ffrt/Cargo.toml index 34458c2556ad93187c9585dbef729dbcadbd41cb..3b851f651e3c5f3057238fbe3d28a70852153215 100644 --- a/ylong_ffrt/Cargo.toml +++ b/ylong_ffrt/Cargo.toml @@ -9,3 +9,6 @@ keywords = ["ylong", "ffrt"] [dependencies] libc = "0.2.134" + +[build-dependencies] +cmake = "0.1" diff --git a/ylong_ffrt/build_ffrt.rs b/ylong_ffrt/build.rs similarity index 39% rename from ylong_ffrt/build_ffrt.rs rename to ylong_ffrt/build.rs index 71ecd3ea3d7d643c8cd2db95eaf84200017f2b8d..74627337c214c655aa9b7090e67f78cea6de88f5 100644 --- a/ylong_ffrt/build_ffrt.rs +++ b/ylong_ffrt/build.rs @@ -13,19 +13,40 @@ //! build.rs file for ylong_ffrt -use std::path::PathBuf; -use std::{env, fs}; +use std::env; +use std::path::Path; + +use cmake::Config; fn main() { - let library_name = "ffrt"; - let root = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); - let library_dir = fs::canonicalize(root.join("lib")).unwrap(); - - println!("cargo:rustc-link-lib={}", library_name); - println!( - "cargo:rustc-link-search=native={}", - env::join_paths([library_dir]).unwrap().to_str().unwrap() - ); - println!("cargo:rustc-link-lib=pthread"); - println!("cargo:rustc-link-lib=dylib=stdc++"); + let mut oh_dir = env::var_os("OH_DIR"); + + let ffrt_dir = env::var_os("FFRT_DIR"); + + let mut home_dir = env::var_os("HOME").unwrap(); + + let ffrt_path = match ffrt_dir.as_ref() { + Some(path) => Path::new(path), + None => match &mut oh_dir { + Some(path) => { + path.push("/foundation/resourceschedule/ffrt"); + Path::new(path) + } + None => { + home_dir.push("/OpenHarmony/foundation/resourceschedule/ffrt"); + Path::new(&home_dir) + } + }, + }; + + let mut dst = Config::new(ffrt_path) + .cflag("-DFFRT_TEST_ENABLE=ON") + .cflag("-DFFRT_ST_ENABLE=ON") + .cflag("-DCMAKE_BUILD_TYPE=RELEASE") + .build_target("ffrt") + .build(); + dst.push("build/src"); + + println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib=dylib=ffrt"); }