From d35e40185a8972cf7ce2b3cebdea8b1369d3789a Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 13 May 2024 16:09:58 +0200 Subject: [PATCH] fix(rust): fetch `CARGO_MANIFEST_DIR` at runtime in build script The `CARGO_MANIFEST_DIR` environment variable should be accessed by `build.rs` at run time rather than compile time. This was for example causing issues when importing `tree-sitter` via [`rules_rust`](https://github.com/bazelbuild/rules_rust) in bazel, where compilation and running happen in separate environments. --- lib/binding_rust/build.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 19cb0f6e..ce4198bc 100644 --- a/lib/binding_rust/build.rs +++ b/lib/binding_rust/build.rs @@ -1,7 +1,4 @@ -use std::{ - env, fs, - path::{Path, PathBuf}, -}; +use std::{env, fs, path::PathBuf}; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); @@ -26,7 +23,7 @@ fn main() { .include(env::var("DEP_WASMTIME_C_API_WASM_INCLUDE").unwrap()); } - let manifest_path = Path::new(env!("CARGO_MANIFEST_DIR")); + let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let include_path = manifest_path.join("include"); let src_path = manifest_path.join("src"); let wasm_path = src_path.join("wasm");