don't genrate code in src/
[Outputs of Build Script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script) states that only files in $OUT_DIR may be modified
This commit is contained in:
6
build.rs
6
build.rs
@@ -56,7 +56,7 @@ fn main() {
|
|||||||
find_prolog_files(&mut libraries, "", &lib_path);
|
find_prolog_files(&mut libraries, "", &lib_path);
|
||||||
libraries.write_all(b"\n m\n };\n}\n").unwrap();
|
libraries.write_all(b"\n m\n };\n}\n").unwrap();
|
||||||
|
|
||||||
let instructions_path = Path::new("src/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();
|
||||||
|
|
||||||
let quoted_output = generate_instructions_rs();
|
let quoted_output = generate_instructions_rs();
|
||||||
@@ -70,10 +70,10 @@ fn main() {
|
|||||||
.spawn().unwrap()
|
.spawn().unwrap()
|
||||||
.wait().unwrap();
|
.wait().unwrap();
|
||||||
|
|
||||||
let static_atoms_path = Path::new("src/static_atoms.rs");
|
let static_atoms_path = Path::new(&out_dir).join("static_atoms.rs");
|
||||||
let mut static_atoms_file = File::create(&static_atoms_path).unwrap();
|
let mut static_atoms_file = File::create(&static_atoms_path).unwrap();
|
||||||
|
|
||||||
let quoted_output = index_static_strings();
|
let quoted_output = index_static_strings(&instructions_path);
|
||||||
|
|
||||||
static_atoms_file
|
static_atoms_file
|
||||||
.write_all(quoted_output.to_string().as_bytes())
|
.write_all(quoted_output.to_string().as_bytes())
|
||||||
|
|||||||
@@ -3037,11 +3037,13 @@ pub fn generate_instructions_rs() -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! instr {
|
macro_rules! _instr {
|
||||||
#(
|
#(
|
||||||
#instr_macro_arms
|
#instr_macro_arms
|
||||||
);*
|
);*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use _instr as instr; // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ impl<'ast> Visit<'ast> for StaticStrVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index_static_strings() -> TokenStream {
|
pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStream {
|
||||||
use quote::*;
|
use quote::*;
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -103,20 +103,14 @@ pub fn index_static_strings() -> TokenStream {
|
|||||||
|
|
||||||
let mut visitor = StaticStrVisitor::new();
|
let mut visitor = StaticStrVisitor::new();
|
||||||
|
|
||||||
for entry in WalkDir::new("src/").into_iter().filter_entry(filter_rust_files) {
|
fn process_filepath(path: &std::path::Path) -> std::result::Result<syn::File, ()> {
|
||||||
let entry = entry.unwrap();
|
|
||||||
|
|
||||||
if entry.path().is_dir() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file = match File::open(entry.path()) {
|
|
||||||
Ok(file) => file,
|
|
||||||
Err(_) => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut src = String::new();
|
let mut src = String::new();
|
||||||
|
|
||||||
|
let mut file = match File::open(path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(_) => return Err(()),
|
||||||
|
};
|
||||||
|
|
||||||
match file.read_to_string(&mut src) {
|
match file.read_to_string(&mut src) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -127,14 +121,36 @@ pub fn index_static_strings() -> TokenStream {
|
|||||||
let syntax = match syn::parse_file(&src) {
|
let syntax = match syn::parse_file(&src) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!("parse error: {} in file {:?}", e, entry.path());
|
panic!("parse error: {} in file {:?}", e, path);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Ok(syntax)
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in WalkDir::new("src/")
|
||||||
|
.into_iter()
|
||||||
|
.filter_entry(filter_rust_files)
|
||||||
|
{
|
||||||
|
let entry = entry.unwrap();
|
||||||
|
|
||||||
|
if entry.path().is_dir() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let syntax = match process_filepath(entry.path()) {
|
||||||
|
Ok(syntax) => syntax,
|
||||||
|
Err(_) => continue,
|
||||||
|
};
|
||||||
|
|
||||||
visitor.visit_file(&syntax);
|
visitor.visit_file(&syntax);
|
||||||
}
|
}
|
||||||
|
|
||||||
let indices = (0 .. visitor.static_strs.len()).map(|i| i << 3);
|
match process_filepath(instruction_rs_path) {
|
||||||
|
Ok(syntax) => visitor.visit_file(&syntax),
|
||||||
|
Err(_) => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let indices = (0..visitor.static_strs.len()).map(|i| i << 3);
|
||||||
let indices_iter = indices.clone();
|
let indices_iter = indices.clone();
|
||||||
|
|
||||||
let static_strs_len = visitor.static_strs.len();
|
let static_strs_len = visitor.static_strs.len();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub struct Atom {
|
|||||||
|
|
||||||
const_assert!(mem::size_of::<Atom>() == 8);
|
const_assert!(mem::size_of::<Atom>() == 8);
|
||||||
|
|
||||||
include!("./static_atoms.rs");
|
include!(concat!(env!("OUT_DIR"), "/static_atoms.rs"));
|
||||||
|
|
||||||
impl<'a> From<&'a Atom> for Atom {
|
impl<'a> From<&'a Atom> for Atom {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ mod heap_iter;
|
|||||||
pub mod heap_print;
|
pub mod heap_print;
|
||||||
mod indexing;
|
mod indexing;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod instructions;
|
pub mod instructions {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/instructions.rs"));
|
||||||
|
}
|
||||||
mod iterators;
|
mod iterators;
|
||||||
pub mod machine;
|
pub mod machine;
|
||||||
mod raw_block;
|
mod raw_block;
|
||||||
@@ -29,3 +31,5 @@ pub mod read;
|
|||||||
mod targets;
|
mod targets;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod write;
|
pub mod write;
|
||||||
|
|
||||||
|
use instructions::instr;
|
||||||
|
|||||||
Reference in New Issue
Block a user