Skip to content

Commit

Permalink
Define the math block renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Jun 18, 2024
1 parent 4666014 commit 7bf59e6
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 318 deletions.
22 changes: 8 additions & 14 deletions projects/notedown-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,24 @@ use std::{fs::File, io::Write, path::Path};
use wit_bindgen_core::Files;
use wit_parser::Resolve;

fn generate_rust(rust_project: &Path) {
pub fn generate_rust(rust_project: &Path) -> anyhow::Result<()> {
let config = wit_bindgen_rust::Opts { rustfmt: false, generate_unused_types: true, ..wit_bindgen_rust::Opts::default() };
let mut generator = config.build();
let mut resolve = Resolve::default();
let (pkg, _) = resolve.push_dir(&rust_project.join("wit")).unwrap();
let world = resolve.select_world(pkg, None).unwrap();
let (pkg, _) = resolve.push_dir(&rust_project.join("wit"))?;
let world = resolve.select_world(pkg, None)?;
let mut files = Files::default();
generator.generate(&resolve, world, &mut files).unwrap();
generator.generate(&resolve, world, &mut files)?;

let wit = rust_project.join("src").join("exports");
// 检查目录是否存在并生成
if !wit.exists() {
std::fs::create_dir_all(&wit).unwrap();
std::fs::create_dir_all(&wit)?;
}

for (file, text) in files.iter() {
let mut file = File::create(wit.join(file)).unwrap();
file.write_all(text).unwrap();
let mut file = File::create(wit.join(file))?;
file.write_all(text)?;
}
}

#[test]
fn export() {
let here = Path::new(env!("CARGO_MANIFEST_DIR"));
let proj = here.join("..").join("notedown-wasi");
let out = generate_rust(&proj);
Ok(())
}
14 changes: 10 additions & 4 deletions projects/notedown-bindgen/tests/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#![allow(dead_code)]
#![allow(non_camel_case_types)]

use std::{fs::File, io::Write, path::Path};
use wit_bindgen_core::Files;
use wit_bindgen_rust::Opts;
use wit_parser::Resolve;
use bindgen::generate_rust;
use std::path::Path;

#[test]
fn ready() {
println!("it, works!")
}

#[test]
fn export() {
let here = Path::new(env!("CARGO_MANIFEST_DIR"));
let _ = generate_rust(&here.join("..").join("notedown-wasi"));
let _ = generate_rust(Path::new(r#"C:\Users\Dell\CLionProjects\dejavu-engine\projects\dejavu-wasi"#));
let _ = generate_rust(Path::new(r#"C:\Users\Dell\CLionProjects\notedown-rs\projects\notedown-json"#));
}
143 changes: 0 additions & 143 deletions projects/notedown-bindgen/wit/world.wit

This file was deleted.

8 changes: 7 additions & 1 deletion projects/notedown-wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ edition = "2021"

[lib]
name = "wasi_notedown"
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]

[dependencies]
url = "2.5.0"
wit-bindgen = "0.24.0"
toml = { version = "0.8.12", optional = true }
serde_json = { version = "1.0.115", optional = true }
cargo-component-bindings = "0.6.0"

[features]
default = []

[package.metadata.component]
package = "notedown:core"

[package.metadata.component.dependencies]
5 changes: 1 addition & 4 deletions projects/notedown-wasi/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{
exports::notedown::core::{
syntax_tree::NotedownRoot,
types::{GuestUrl, NotedownError, SyntaxError, TextRange},
},
exports::notedown::core::types::{GuestUrl, NotedownError, SyntaxError, TextRange},
NotedownHost,
};
use std::str::FromStr;
Expand Down
Loading

0 comments on commit 7bf59e6

Please sign in to comment.