From 319479e2c74a0b05f83d4c49bdb5d15982909888 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama <45118249+mtshiba@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:18:59 +0900 Subject: [PATCH] Add build.rs to set ANTE_STDLIB_DIR (#116) * Add build.rs Since ANTE_STDLIB_DIR was not set, The compiler crashed when compiling a file other than the project root. So I created a build script that creates the standard library directory and sets ANTE_STDLIB_DIR. * Update mod.rs * Update build.rs * Update build.rs --- Cargo.toml | 1 + build.rs | 9 +++++++++ src/util/mod.rs | 9 +-------- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index b1a406da..5a66f934 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "ante" version = "0.1.1" authors = ["Jake Fecher "] edition = "2018" +build = "build.rs" [lib] name = "ante" diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..47392ad6 --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +use std::env; + +fn main() -> std::io::Result<()> { + if option_env!("ANTE_STDLIB_DIR").is_none() { + let cur_dir = env::current_dir()?; + println!("cargo:rustc-env=ANTE_STDLIB_DIR={}/stdlib", cur_dir.to_str().unwrap()); + } + Ok(()) +} diff --git a/src/util/mod.rs b/src/util/mod.rs index b33825e1..d59e2d2e 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -73,14 +73,7 @@ pub fn binary_name(module_name: &str) -> String { pub fn stdlib_dir() -> PathBuf { match option_env!("ANTE_STDLIB_DIR") { Some(env) => std::fs::canonicalize(env).unwrap(), - None => { - let mut path = PathBuf::from(file!()); - path.pop(); - path.pop(); - path.pop(); - path.push("stdlib"); - path.canonicalize().unwrap() - } + None => panic!("ANTE_STDLIB_DIR is not set"), } }