Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix link error on os with systemd #629

Merged
merged 3 commits into from
Aug 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions grpc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,38 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
}
}

figure_systemd_path(&build_dir);

cc.include("grpc/include");
}

fn figure_systemd_path(build_dir: &str) {
let path = format!("{build_dir}/CMakeCache.txt");
let f = BufReader::new(std::fs::File::open(&path).unwrap());
let mut libdir: Option<String> = None;
let mut libname: Option<String> = None;
for l in f.lines() {
let l = l.unwrap();
if let Some(s) = trim_start(&l, "SYSTEMD_LIBDIR:INTERNAL=").filter(|s| !s.is_empty()) {
libdir = Some(s.to_owned());
if libname.is_some() {
break;
}
} else if let Some(s) =
trim_start(&l, "SYSTEMD_LIBRARIES:INTERNAL=").filter(|s| !s.is_empty())
{
libname = Some(s.to_owned());
if libdir.is_some() {
break;
}
}
}
if let (Some(libdir), Some(libname)) = (libdir, libname) {
println!("cargo:rustc-link-search=native={}", libdir);
println!("cargo:rustc-link-lib={}", libname);
}
}

fn figure_ssl_path(build_dir: &str) {
let path = format!("{build_dir}/CMakeCache.txt");
let f = BufReader::new(std::fs::File::open(&path).unwrap());
Expand Down
Loading