Skip to content

Commit

Permalink
g2
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Feb 6, 2025
1 parent 666e616 commit 37ed1ef
Show file tree
Hide file tree
Showing 30 changed files with 1,928 additions and 1,866 deletions.
832 changes: 454 additions & 378 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ vergen-gitcl = { version = "1.0.1" }
# tinymist's world implementation
typst-shim = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03" }
tinymist-analysis = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03" }
tinymist-project = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03" }
tinymist-std = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03", default-features = false }
tinymist-task = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03", default-features = false }
tinymist-world = { git = "https://github.com/Myriad-Dreamin/tinymist.git", rev = "665b27a6291d02375bd58664edcd7db0f44bfe03", default-features = false }

# project core
Expand Down Expand Up @@ -234,6 +236,10 @@ undocumented_unsafe_blocks = "warn"

[patch.crates-io]

reflexo = { path = "crates/reflexo/" }
reflexo-typst = { path = "crates/reflexo-typst/" }
reflexo-vec2svg = { path = "crates/conversion/vec2svg/" }

# typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
# typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
# typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "typst.ts-v0.10.0" }
Expand All @@ -244,9 +250,13 @@ typst = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0
typst-syntax = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-ide = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-svg = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-render = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-pdf = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-eval = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-html = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "8cccef9", features = [
"fonts",
] }

# comemo = { path = "../comemo" }
# typst = { path = "../typst/crates/typst" }
Expand All @@ -257,8 +267,10 @@ typst-html = { git = "https://github.com/ParaN3xus/typst", tag = "tinymist-night

# fontdb = { path = "../fontdb" }

# [patch."https://github.com/Myriad-Dreamin/tinymist.git"]
# typst-shim = { path = "../tinymist/crates/typst-shim" }
# tinymist-analysis = { path = "../tinymist/crates/tinymist-analysis" }
# tinymist-std = { path = "../tinymist/crates/tinymist-std" }
# tinymist-world = { path = "../tinymist/crates/tinymist-world" }
[patch."https://github.com/Myriad-Dreamin/tinymist.git"]
typst-shim = { path = "../tinymist/crates/typst-shim" }
tinymist-analysis = { path = "../tinymist/crates/tinymist-analysis" }
tinymist-project = { path = "../tinymist/crates/tinymist-project" }
tinymist-std = { path = "../tinymist/crates/tinymist-std" }
tinymist-task = { path = "../tinymist/crates/tinymist-task" }
tinymist-world = { path = "../tinymist/crates/tinymist-world" }
80 changes: 17 additions & 63 deletions cli/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use std::sync::Arc;
use reflexo_typst::config::entry::{EntryOpts, MEMORY_MAIN_ENTRY};
use reflexo_typst::config::CompileOpts;
use reflexo_typst::features::{FeatureSet, DIAG_FMT_FEATURE};
use reflexo_typst::TypstDocument;
use reflexo_typst::{exporter_builtins::GroupExporter, path::PathClean};
use reflexo_typst::path::PathClean;
use reflexo_typst::{
CompilationHandle, CompileActor, CompileDriver, CompileExporter, CompileServerOpts,
CompileStarter, CompiledArtifact, CompilerFeat, ConsoleDiagReporter, DynExporter,
DynamicLayoutCompiler, EntryManager, EntryReader, GenericExporter, PureCompiler, ShadowApi,
SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld,
CompilationHandle, CompileActor, CompileDriver, CompileServerOpts, CompilerFeat,
DynComputation, DynamicLayoutCompiler, EntryManager, EntryReader, PureCompiler, ShadowApi,
SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld, WorldComputeGraph,
};
use reflexo_typst::{DynSystemComputation, TypstDocument};
use tokio::sync::mpsc;
use typst::diag::{FileError, FileResult};
use typst::foundations::{Bytes, Dict, IntoValue};
Expand All @@ -24,7 +23,7 @@ use crate::{
CompileArgs, CompileOnceArgs,
};

pub fn create_driver(args: CompileOnceArgs) -> CompileDriver<PureCompiler<TypstSystemWorld>> {
pub fn create_driver(args: CompileOnceArgs) -> CompileDriver {
let workspace_dir = Path::new(args.workspace.as_str()).clean();
let entry = args.entry;
let entry_file_path = Path::new(entry.as_str()).clean();
Expand Down Expand Up @@ -112,52 +111,20 @@ pub fn create_driver(args: CompileOnceArgs) -> CompileDriver<PureCompiler<TypstS
verse.with_entry_file(entry_file_path)
};

CompileDriver::new(std::marker::PhantomData, verse)
CompileDriver::new(Arc::new(|_| Ok(())), verse)
}

pub fn compile_export(args: CompileArgs, exporter: GroupExporter<TypstDocument>) -> ! {
pub fn compile_export(args: CompileArgs, exporter: DynSystemComputation) -> ! {
let (intr_tx, intr_rx) = mpsc::unbounded_channel();

// todo: make dynamic layout exporter
let output_dir = {
let dir = args.compile.output_dir();
if args.compile.is_stdin() {
dir.join("main")
} else {
dir.join(
args.compile
.main_id()
.vpath()
.as_rooted_path()
.file_name()
.expect("entry_file has no file name"),
)
}
};

let driver = create_driver(args.compile);

let feature_set =
FeatureSet::default().configure(&DIAG_FMT_FEATURE, args.diagnostic_format.into());

let verse = driver.universe;
// todo: when there is only dynamic export, it is not need to compile first.

let mut exporters: Vec<DynExporter<CompiledArtifact<SystemCompilerFeat>>> = vec![];

if !exporter.is_empty() {
let driver = CompileExporter::new(std::marker::PhantomData).with_exporter(exporter);
exporters.push(Box::new(CompileStarter::new(driver)));
}

if args.dynamic_layout {
let driver = DynamicLayoutCompiler::new(std::marker::PhantomData, output_dir);
exporters.push(Box::new(CompileStarter::new(driver)));
}

let handle = Arc::new(CompileHandler {
exporter: GroupExporter::new(exporters),
});
let handle = Arc::new(CompileHandler { exporter });

let actor = CompileActor::new_with(
verse,
Expand All @@ -172,7 +139,7 @@ pub fn compile_export(args: CompileArgs, exporter: GroupExporter<TypstDocument>)
.with_watch(args.watch);

utils::async_continue(async move {
utils::logical_exit(actor.run().await);
utils::logical_exit(actor.run().await.unwrap_or_exit());
})
}

Expand All @@ -190,31 +157,18 @@ fn read_from_stdin() -> FileResult<Vec<u8>> {
}

pub struct CompileHandler<F: CompilerFeat> {
exporter: GroupExporter<CompiledArtifact<F>>,
exporter: DynComputation<F>,
}

impl<F: CompilerFeat + 'static> CompilationHandle<F> for CompileHandler<F> {
fn status(&self, _revision: usize, _rep: reflexo_typst::CompileReport) {}

fn notify_compile(
&self,
compiled: &reflexo_typst::CompiledArtifact<F>,
rep: reflexo_typst::CompileReport,
) {
use reflexo_typst::Exporter;
if let reflexo_typst::CompileReport::CompileSuccess(t, ..) = rep {
let curr = reflexo_typst::time::now();
let errs = self
.exporter
.export(compiled.world.as_ref(), Arc::new(compiled.clone()));
if let Err(errs) = errs {
let elapsed = curr.elapsed().unwrap_or_default();
let rep = reflexo_typst::CompileReport::ExportError(t, errs, elapsed);
let _ = ConsoleDiagReporter::default().export(
compiled.world.as_ref(),
Arc::new((compiled.env.features.clone(), rep.clone())),
);
}
fn notify_compile(&self, g: &Arc<WorldComputeGraph<F>>) {
let res = (self.exporter)(g);
if let Err(err) = res {
eprintln!("export failed: {err}");
}

todo!()
}
}
Loading

0 comments on commit 37ed1ef

Please sign in to comment.