From f8baec92723fb6f9c98192fef14fde4578fdc124 Mon Sep 17 00:00:00 2001 From: fqwert Date: Thu, 11 Jan 2024 15:34:52 +0800 Subject: [PATCH] build.rs for ffrt Change-Id: I2d30bce9ba743b4f7650c422e8c805dee5d800e0 --- ylong_ffrt/Cargo.toml | 3 ++ ylong_ffrt/{build_ffrt.rs => build.rs} | 47 +++++++++++++++++++------- 2 files changed, 37 insertions(+), 13 deletions(-) rename ylong_ffrt/{build_ffrt.rs => build.rs} (39%) diff --git a/ylong_ffrt/Cargo.toml b/ylong_ffrt/Cargo.toml index 34458c2..3b851f6 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 71ecd3e..7462733 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"); } -- Gitee