Skip to content

Commit cc5d2ab

Browse files
authored
fix link error on os with systemd (#629)
Signed-off-by: fortime <[email protected]>
1 parent 2821787 commit cc5d2ab

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

grpc-sys/build.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,38 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
293293
}
294294
}
295295

296+
figure_systemd_path(&build_dir);
297+
296298
cc.include("grpc/include");
297299
}
298300

301+
fn figure_systemd_path(build_dir: &str) {
302+
let path = format!("{build_dir}/CMakeCache.txt");
303+
let f = BufReader::new(std::fs::File::open(&path).unwrap());
304+
let mut libdir: Option<String> = None;
305+
let mut libname: Option<String> = None;
306+
for l in f.lines() {
307+
let l = l.unwrap();
308+
if let Some(s) = trim_start(&l, "SYSTEMD_LIBDIR:INTERNAL=").filter(|s| !s.is_empty()) {
309+
libdir = Some(s.to_owned());
310+
if libname.is_some() {
311+
break;
312+
}
313+
} else if let Some(s) =
314+
trim_start(&l, "SYSTEMD_LIBRARIES:INTERNAL=").filter(|s| !s.is_empty())
315+
{
316+
libname = Some(s.to_owned());
317+
if libdir.is_some() {
318+
break;
319+
}
320+
}
321+
}
322+
if let (Some(libdir), Some(libname)) = (libdir, libname) {
323+
println!("cargo:rustc-link-search=native={}", libdir);
324+
println!("cargo:rustc-link-lib={}", libname);
325+
}
326+
}
327+
299328
fn figure_ssl_path(build_dir: &str) {
300329
let path = format!("{build_dir}/CMakeCache.txt");
301330
let f = BufReader::new(std::fs::File::open(&path).unwrap());

0 commit comments

Comments
 (0)