From 9c2c4d5d19b7b1b6b2502d747bc28c71764d66f3 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Tue, 11 Nov 2025 12:52:40 -0800 Subject: [PATCH] Resolve CARGO_MANIFEST_DIR at runtime Fix issue when used outside this repo. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6961a58..af8a768 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "include-file" -version = "0.3.0" +version = "0.4.0" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index e87aa96..67b8c9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "include-file" -version = "0.3.0" +version = "0.4.0" description = "Include sections of files into Rust source code" readme = "README.md" authors = ["Heath Stewart (https://github.com/heaths)"] diff --git a/src/lib.rs b/src/lib.rs index cf4625e..d623189 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ mod textile; use proc_macro2::{Span, TokenStream}; use std::{ - fmt, fs, + env, fmt, fs, io::{self, BufRead}, path::PathBuf, }; @@ -237,8 +237,8 @@ where } fn open(path: &str) -> io::Result { - let manifest_dir: PathBuf = option_env!("CARGO_MANIFEST_DIR") - .ok_or_else(|| io::Error::other("no manifest directory"))? + let manifest_dir: PathBuf = env::var("CARGO_MANIFEST_DIR") + .map_err(|_| io::Error::other("no manifest directory"))? .into(); let path = manifest_dir.join(path); fs::File::open(path)