move the creation of the LIBRARIES IndexMap out of the generated file
- only leave the filling of the map in the generated code
This commit is contained in:
@@ -58,28 +58,8 @@ fn main() {
|
|||||||
let mut libraries = File::create(dest_path).unwrap();
|
let mut libraries = File::create(dest_path).unwrap();
|
||||||
let lib_path = Path::new("src").join("lib");
|
let lib_path = Path::new("src").join("lib");
|
||||||
|
|
||||||
writeln!(
|
|
||||||
libraries,
|
|
||||||
"\
|
|
||||||
use indexmap::IndexMap;
|
|
||||||
\
|
|
||||||
"
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let constants = find_prolog_files("", &lib_path);
|
let constants = find_prolog_files("", &lib_path);
|
||||||
|
|
||||||
writeln!(
|
|
||||||
libraries,
|
|
||||||
"\
|
|
||||||
std::thread_local!{{
|
|
||||||
static LIBRARIES: IndexMap<&'static str, &'static str> = {{
|
|
||||||
let mut m = IndexMap::new();
|
|
||||||
\
|
|
||||||
"
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||||
let out_dir_path: &Path = out_dir.as_ref();
|
let out_dir_path: &Path = out_dir.as_ref();
|
||||||
let manifest_dir = &std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
let manifest_dir = &std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
@@ -104,23 +84,12 @@ std::thread_local!{{
|
|||||||
manifest_dir_path.to_path_buf()
|
manifest_dir_path.to_path_buf()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
writeln!(libraries, "{{").unwrap();
|
||||||
for (name, lib_path) in constants {
|
for (name, lib_path) in constants {
|
||||||
let path: PathBuf = prefix.join(lib_path);
|
let path: PathBuf = prefix.join(lib_path);
|
||||||
writeln!(
|
writeln!(libraries, "m.insert(\"{name}\", include_str!({path:?}));").unwrap();
|
||||||
libraries,
|
|
||||||
" m.insert(\"{name}\", include_str!({path:?}));"
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
writeln!(libraries, "}}").unwrap();
|
||||||
writeln!(
|
|
||||||
libraries,
|
|
||||||
"
|
|
||||||
m
|
|
||||||
}};
|
|
||||||
}}"
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let instructions_path = Path::new(&out_dir).join("instructions.rs");
|
let instructions_path = Path::new(&out_dir).join("instructions.rs");
|
||||||
let mut instructions_file = File::create(&instructions_path).unwrap();
|
let mut instructions_file = File::create(&instructions_path).unwrap();
|
||||||
|
|||||||
@@ -119,8 +119,18 @@ fn current_dir() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod libraries {
|
mod libraries {
|
||||||
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
|
std::thread_local! {
|
||||||
|
static LIBRARIES: IndexMap<&'static str, &'static str> = {
|
||||||
|
let mut m = IndexMap::new();
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
||||||
|
|
||||||
|
m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn contains(name: &str) -> bool {
|
pub(crate) fn contains(name: &str) -> bool {
|
||||||
LIBRARIES.with(|libs| libs.contains_key(name))
|
LIBRARIES.with(|libs| libs.contains_key(name))
|
||||||
}
|
}
|
||||||
@@ -128,16 +138,6 @@ mod libraries {
|
|||||||
pub(crate) fn get(name: &str) -> Option<&'static str> {
|
pub(crate) fn get(name: &str) -> Option<&'static str> {
|
||||||
LIBRARIES.with(|libs| libs.get(name).copied())
|
LIBRARIES.with(|libs| libs.get(name).copied())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
std::thread_local! {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
static LIBRARIES2 : IndexMap<&'static str, &'static str> = {
|
|
||||||
let mut m = IndexMap::new();
|
|
||||||
m.insert("test", "test2");
|
|
||||||
m
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
pub static BREAK_FROM_DISPATCH_LOOP_LOC: usize = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user