Skip to content

Commit 8eb4631

Browse files
committed
wip
1 parent 4522ad0 commit 8eb4631

File tree

15 files changed

+66
-123
lines changed

15 files changed

+66
-123
lines changed

.github/workflows/pkg-pr-new.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
on:
22
pull_request:
3+
push:
4+
branches:
5+
- main
36

47
jobs:
58
publish:
@@ -15,5 +18,5 @@ jobs:
1518
run: pnpm build
1619
working-directory: ./typescript
1720
- name: Publish preview packages
18-
run: pnpm dlx pkg-pr-new publish 'compiler' 'vbare' --packageManager pnpm
21+
run: pnpm dlx pkg-pr-new publish 'vbare-compiler' 'vbare' --packageManager pnpm
1922
working-directory: ./typescript

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["bare-gen", "compiler", "vbare"]
2+
members = ["bare-gen", "vbare-compiler", "vbare"]
33
resolver = "2"
44

55
[workspace.package]

rust/compiler/src/lib.rs

Lines changed: 0 additions & 118 deletions
This file was deleted.

rust/compiler/Cargo.toml renamed to rust/vbare-compiler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "compiler"
2+
name = "vbare-compiler"
33
version.workspace = true
44
edition.workspace = true
55

rust/vbare-compiler/src/lib.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::{fs, path::Path};
2+
use indoc::formatdoc;
3+
4+
/// Process BARE schema files and generate Rust code.
5+
///
6+
/// This function is designed to be called from a build.rs script.
7+
/// It automatically uses the OUT_DIR environment variable and sets up
8+
/// cargo:rerun-if-changed for the schema directory.
9+
pub fn process_schemas(schema_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
10+
let out_dir = std::env::var("OUT_DIR")?;
11+
let out_path = Path::new(&out_dir);
12+
13+
println!("cargo:rerun-if-changed={}", schema_dir.display());
14+
15+
let mut all_names = Vec::new();
16+
17+
for entry in fs::read_dir(schema_dir)?.flatten() {
18+
let path = entry.path();
19+
20+
if path.is_dir() {
21+
continue;
22+
}
23+
24+
let bare_name = path
25+
.file_name()
26+
.ok_or("No file name")?
27+
.to_str()
28+
.ok_or("Invalid UTF-8 in file name")?
29+
.rsplit_once('.')
30+
.ok_or("No file extension")?
31+
.0;
32+
33+
let tokens = bare_gen::bare_schema(&path);
34+
let ast = syn::parse2(tokens)?;
35+
let content = prettyplease::unparse(&ast);
36+
37+
fs::write(out_path.join(format!("{bare_name}_generated.rs")), content)?;
38+
39+
all_names.push(bare_name.to_string());
40+
}
41+
42+
let mut mod_content = String::new();
43+
mod_content.push_str("// Auto-generated module file for schemas\n\n");
44+
45+
for name in all_names {
46+
mod_content.push_str(&formatdoc!(
47+
r#"
48+
pub mod {name} {{
49+
include!(concat!(env!("OUT_DIR"), "/{name}_generated.rs"));
50+
}}
51+
"#,
52+
));
53+
}
54+
55+
fs::write(out_path.join("combined_imports.rs"), mod_content)?;
56+
57+
Ok(())
58+
}

typescript/pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
packages:
2-
- 'compiler'
2+
- 'vbare-compiler'
33
- 'vbare'
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)