|
1 | 1 | use cargo_metadata::MetadataCommand; |
2 | 2 | use std::env::var; |
3 | | -use std::fs::{copy, read_dir}; |
4 | 3 | use std::path::PathBuf; |
5 | 4 | use tracing::{info, Level}; |
6 | 5 | use tracing_appender::rolling::{RollingFileAppender, Rotation}; |
@@ -75,7 +74,7 @@ fn main() { |
75 | 74 | .join("registry") |
76 | 75 | .join("src"); |
77 | 76 | let crates_parent_dirs = Vec::from_iter( |
78 | | - read_dir(dep_src_dir.clone()) |
| 77 | + std::fs::read_dir(dep_src_dir.clone()) |
79 | 78 | .expect("Failed to read deps") |
80 | 79 | .flatten(), |
81 | 80 | ); |
@@ -164,55 +163,12 @@ fn main() { |
164 | 163 | { |
165 | 164 | panic!("failed to build dylib {}", e); |
166 | 165 | } |
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 | | - } |
216 | 166 | // 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 | 173 | println!("cargo:rustc-link-lib=dylib=open_coroutine_hook"); |
218 | 174 | } |
0 commit comments