Rust bindings: Use CARGO_MANIFEST_DIR in build.rs

When a rust crate uses the boringssl rust bindings like:

```Cargo.toml
[dependencies]
bssl-sys = { path = "./third_party/boringssl/build/rust" }
```

The working directory of `build.rs` is set to the the crate's
working directory so "." and ".." aren't relative to the bindings'
directory. Use CARGO_MANIFEST_DIR to specify link search paths.

Change-Id: Ieb49f4ab479f47390388dc5ace70561f593dc238
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51645
Reviewed-by: David Drysdale <drysdale@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
fips-20220613
Kenichi Ishibashi 3 years ago committed by Boringssl LUCI CQ
parent ab69425a98
commit e5abf588c0
  1. 1
      .gitignore
  2. 19
      rust/build.rs

1
.gitignore vendored

@ -7,6 +7,7 @@ ssl/test/runner/runner
*.swo
doc/*.html
doc/doc.css
rust/Cargo.lock
rust/target
util/bot/android_ndk

@ -13,14 +13,27 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
use std::env;
use std::path::Path;
fn main() {
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let crate_path = Path::new(&dir);
let parent_path = crate_path.parent().unwrap();
// Statically link libraries.
println!("cargo:rustc-link-search=native=../crypto");
println!(
"cargo:rustc-link-search=native={}",
parent_path.join("crypto").display()
);
println!("cargo:rustc-link-lib=static=crypto");
println!("cargo:rustc-link-search=native=../ssl");
println!(
"cargo:rustc-link-search=native={}",
parent_path.join("ssl").display()
);
println!("cargo:rustc-link-lib=static=ssl");
println!("cargo:rustc-link-search=native=.");
println!("cargo:rustc-link-search=native={}", crate_path.display());
println!("cargo:rustc-link-lib=static=rust_wrapper");
}

Loading…
Cancel
Save