-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add manual generation of abi, runtime-capi
When using build.rs files several files get regenerated every build which causes rebuilds even when nothing really changed. This commit changes this behavior to make the user manually run a command when the files should be regenerated.
- Loading branch information
1 parent
23a4efc
commit 63a49e4
Showing
13 changed files
with
105 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[alias] | ||
# Automatically generates the ast and syntax kinds files | ||
gen-syntax = "run --package tools --bin tools -- gen-syntax" | ||
gen-syntax = "run --package tools --bin tools -- gen-syntax" | ||
gen-runtime-capi = "run --package tools --bin tools -- gen-runtime-capi" | ||
gen-abi = "run --package tools --bin tools -- gen-abi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Submodule ffi
updated
5 files
+ − | bin/linux64/libmun_runtime.so | |
+ − | bin/osx64/libmun_runtime.dylib | |
+ − | bin/win64/mun_runtime.dll | |
+ − | bin/win64/mun_runtime.dll.lib | |
+16 −1 | include/mun/runtime_capi.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ teraron = "0.0.1" | |
clap = "2.32.0" | ||
failure = "0.1.4" | ||
ron = "0.4.2" | ||
cbindgen = "0.9.1" | ||
bindgen = "0.51" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::{project_root, update, Result}; | ||
use teraron::Mode; | ||
|
||
pub const RUNTIME_CAPI_DIR: &str = "crates/mun_runtime_capi"; | ||
|
||
/// Generates the FFI bindings for the Mun runtime | ||
pub fn generate(mode: Mode) -> Result<()> { | ||
let crate_dir = project_root().join(RUNTIME_CAPI_DIR); | ||
let file_path = crate_dir.join("ffi/include/mun/runtime_capi.h"); | ||
|
||
let mut file_contents = Vec::<u8>::new(); | ||
cbindgen::generate(crate_dir)?.write(&mut file_contents); | ||
|
||
let file_contents = String::from_utf8(file_contents)?.replace("\r\n", "\n"); | ||
update(&file_path, &file_contents, mode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::{project_root, reformat, update, Result}; | ||
use std::fs; | ||
use std::path::Path; | ||
use teraron::Mode; | ||
|
||
pub const GRAMMAR: &str = "crates/mun_syntax/src/grammar.ron"; | ||
pub const SYNTAX_KINDS: &str = "crates/mun_syntax/src/syntax_kind/generated.rs.tera"; | ||
pub const AST: &str = "crates/mun_syntax/src/ast/generated.rs.tera"; | ||
|
||
/// Generates the generated.rs for AST and syntax nodes. | ||
pub fn generate(mode: Mode) -> Result<()> { | ||
let grammar = project_root().join(GRAMMAR); | ||
let syntax_kinds = project_root().join(SYNTAX_KINDS); | ||
let ast = project_root().join(AST); | ||
generate_from_template(&syntax_kinds, &grammar, mode)?; | ||
generate_from_template(&ast, &grammar, mode)?; | ||
Ok(()) | ||
} | ||
|
||
/// Generate file contents from a template | ||
fn generate_from_template(template: &Path, src: &Path, mode: Mode) -> Result<()> { | ||
let file_name = template.file_stem().unwrap().to_str().unwrap(); | ||
let tgt = template.with_file_name(file_name); | ||
let template = fs::read_to_string(template)?; | ||
let src: ron::Value = { | ||
let text = fs::read_to_string(src)?; | ||
ron::de::from_str(&text)? | ||
}; | ||
let content = teraron::render(&template, src)?; | ||
let content = reformat(content)?; | ||
update(&tgt, &content, mode) | ||
} |