|
1 | 1 | use cargo_metadata::MetadataCommand; |
2 | 2 | use std::env::var; |
| 3 | +use std::fs::{copy, read_dir}; |
3 | 4 | use std::path::PathBuf; |
4 | 5 | use tracing::{info, Level}; |
5 | 6 | use tracing_appender::rolling::{RollingFileAppender, Rotation}; |
@@ -74,7 +75,7 @@ fn main() { |
74 | 75 | .join("registry") |
75 | 76 | .join("src"); |
76 | 77 | let crates_parent_dirs = Vec::from_iter( |
77 | | - std::fs::read_dir(dep_src_dir.clone()) |
| 78 | + read_dir(dep_src_dir.clone()) |
78 | 79 | .expect("Failed to read deps") |
79 | 80 | .flatten(), |
80 | 81 | ); |
@@ -163,12 +164,56 @@ fn main() { |
163 | 164 | { |
164 | 165 | panic!("failed to build dylib {}", e); |
165 | 166 | } |
| 167 | + // correct dylib path |
| 168 | + let hook_deps = out_dir |
| 169 | + .join(target) |
| 170 | + .join(if cfg!(debug_assertions) { |
| 171 | + "debug" |
| 172 | + } else { |
| 173 | + "release" |
| 174 | + }) |
| 175 | + .join("deps"); |
| 176 | + let deps = out_dir |
| 177 | + .parent() |
| 178 | + .expect("can not find deps dir") |
| 179 | + .parent() |
| 180 | + .expect("can not find deps dir") |
| 181 | + .parent() |
| 182 | + .expect("can not find deps dir") |
| 183 | + .join("deps"); |
| 184 | + for entry in read_dir(hook_deps.clone()) |
| 185 | + .expect("can not find deps dir") |
| 186 | + .flatten() |
| 187 | + { |
| 188 | + let file_name = entry.file_name().to_string_lossy().to_string(); |
| 189 | + if !file_name.contains("open_coroutine_hook") { |
| 190 | + continue; |
| 191 | + } |
| 192 | + if cfg!(target_os = "linux") && file_name.ends_with(".so") { |
| 193 | + let from = hook_deps.join(file_name); |
| 194 | + let to = deps.join("libopen_coroutine_hook.so"); |
| 195 | + copy(from.clone(), to.clone()).expect("copy to libopen_coroutine_hook.so failed!"); |
| 196 | + info!("copy {:?} to {:?} success!", from, to); |
| 197 | + } else if cfg!(target_os = "macos") && file_name.ends_with(".dylib") { |
| 198 | + let from = hook_deps.join(file_name); |
| 199 | + let to = deps.join("libopen_coroutine_hook.dylib"); |
| 200 | + copy(from.clone(), to.clone()).expect("copy to libopen_coroutine_hook.dylib failed!"); |
| 201 | + info!("copy {:?} to {:?} success!", from, to); |
| 202 | + } else if cfg!(windows) { |
| 203 | + if file_name.ends_with(".dll") { |
| 204 | + let from = hook_deps.join(file_name); |
| 205 | + let to = deps.join("open_coroutine_hook.dll"); |
| 206 | + copy(from.clone(), to.clone()).expect("copy to open_coroutine_hook.dll failed!"); |
| 207 | + info!("copy {:?} to {:?} success!", from, to); |
| 208 | + } else if file_name.ends_with(".lib") { |
| 209 | + let from = hook_deps.join(file_name); |
| 210 | + let to = deps.join("open_coroutine_hook.lib"); |
| 211 | + copy(from.clone(), to.clone()).expect("copy to open_coroutine_hook.lib failed!"); |
| 212 | + info!("copy {:?} to {:?} success!", from, to); |
| 213 | + } |
| 214 | + } |
| 215 | + } |
166 | 216 | // link dylib |
167 | | - let hook_deps = out_dir.join(target).join(if cfg!(debug_assertions) { |
168 | | - "debug" |
169 | | - } else { |
170 | | - "release" |
171 | | - }); |
172 | | - println!("cargo:rustc-link-search=native={}", hook_deps.display()); |
| 217 | + println!("cargo:rustc-link-search=native={}", deps.display()); |
173 | 218 | println!("cargo:rustc-link-lib=dylib=open_coroutine_hook"); |
174 | 219 | } |
0 commit comments