summaryrefslogtreecommitdiff
blob: 638d033b50a59bc52bac54affa72b466d1d290ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From d2b14f02fbf6b8420abb4c77870d64df596fc0e9 Mon Sep 17 00:00:00 2001
From: Alessandro Ghedini <alessandro@ghedini.me>
Date: Tue, 1 Feb 2022 11:36:54 +0000
Subject: [PATCH] build: fix pkg-config output path

When building the tarball from crates.io rather than from the git
repository, the target directory for the pkg-config file doesn't exist.

Note that when explicitly passing the --target option to cargo, this
changes the output directory from "target/<profile>/quiche.pc" (e.g.
"target/debug/quiche.pc") to "target/<target>/<profile>/quiche.pc" (e.g.
"target/x86_64-unknown-linux-gnu/debug).

Fixes #1142.
---
 quiche/src/build.rs | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/build.rs b/src/build.rs
index ce299cd49..d1ef4f4ee 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -173,11 +173,10 @@ fn get_boringssl_cmake_config() -> cmake::Config {
 fn write_pkg_config() {
     use std::io::prelude::*;
 
-    let profile = std::env::var("PROFILE").unwrap();
     let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
-    let target_dir = format!("{}/../target/{}", manifest_dir, profile);
+    let target_dir = target_dir_path();
 
-    let out_path = std::path::Path::new(&target_dir).join("quiche.pc");
+    let out_path = target_dir.as_path().join("quiche.pc");
     let mut out_file = std::fs::File::create(&out_path).unwrap();
 
     let include_dir = format!("{}/include", manifest_dir);
@@ -196,12 +195,27 @@ Version: {}
 Libs: -Wl,-rpath,${{libdir}} -L${{libdir}} -lquiche
 Cflags: -I${{includedir}}
 ",
-        include_dir, target_dir, version
+        include_dir,
+        target_dir.to_str().unwrap(),
+        version
     );
 
     out_file.write_all(output.as_bytes()).unwrap();
 }
 
+fn target_dir_path() -> std::path::PathBuf {
+    let out_dir = std::env::var("OUT_DIR").unwrap();
+    let out_dir = std::path::Path::new(&out_dir);
+
+    for p in out_dir.ancestors() {
+        if p.ends_with("build") {
+            return p.parent().unwrap().to_path_buf();
+        }
+    }
+
+    unreachable!();
+}
+
 fn main() {
     if cfg!(feature = "boringssl-vendored") && !cfg!(feature = "boring-sys") {
         let bssl_dir = std::env::var("QUICHE_BSSL_PATH").unwrap_or_else(|_| {