Skip to content

Commit

Permalink
Add build.rs to set ANTE_STDLIB_DIR (#116)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mtshiba authored Jun 30, 2022
1 parent d76e09b commit 319479e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ante"
version = "0.1.1"
authors = ["Jake Fecher <[email protected]>"]
edition = "2018"
build = "build.rs"

[lib]
name = "ante"
Expand Down
9 changes: 9 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
9 changes: 1 addition & 8 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand Down

0 comments on commit 319479e

Please sign in to comment.