Skip to content

Commit e3dcefd

Browse files
seandewartjdevries
authored andcommitted
build: generate vimfuncs at build time
This has a few advantages: we don't have to include the generated file in the source tree, and using `include!()` avoids rustfmt and other tools checking the file. The location of the generated file can also be customized by setting `OUT_DIR`, but cargo picks an appropriate temporary place in the target/ directory by default. Also set the default workspace members to the crates which have tests so I don't have to forget using `--workspace` all the time.
1 parent 9a530e1 commit e3dcefd

3 files changed

Lines changed: 9 additions & 5083 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ members = [
2424
"crates/vimfuncs",
2525
"crates/format/",
2626
]
27+
default-members = [
28+
"crates/vim9-lexer",
29+
"crates/vim9-parser",
30+
"crates/vim9-gen",
31+
]

crates/vimfuncs/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::Write;
1+
use std::{env, fs::File, io::Write, path::Path};
22

33
use anyhow::Result;
44

@@ -326,7 +326,8 @@ impl FuncParser {
326326
fn main() -> Result<()> {
327327
println!("cargo:rerun-if-changed=data/global_functions.txt");
328328

329-
let mut lib = std::fs::File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/src/lib.rs"))?;
329+
let out_path = Path::new(&env::var_os("OUT_DIR").unwrap()).join("generated_functions.rs");
330+
let mut lib = File::create(&out_path)?;
330331

331332
// Write our struct definitions out here:
332333
writeln!(

0 commit comments

Comments
 (0)