Prescient

This commit is contained in:
Laurenz 2025-07-24 10:45:19 +02:00
parent 8d7898fc6f
commit e42e497ae8
4 changed files with 18 additions and 3 deletions

5
Cargo.lock generated
View File

@ -451,7 +451,7 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]] [[package]]
name = "comemo" name = "comemo"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/typst/comemo?rev=70c0307#70c03075453deda2b2cc592ee8676edfe7962804" source = "git+https://github.com/typst/comemo?rev=499bce5#499bce59ae44af9e61dc106b6b1663a45669b87e"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"comemo-macros", "comemo-macros",
@ -463,7 +463,7 @@ dependencies = [
[[package]] [[package]]
name = "comemo-macros" name = "comemo-macros"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/typst/comemo?rev=70c0307#70c03075453deda2b2cc592ee8676edfe7962804" source = "git+https://github.com/typst/comemo?rev=499bce5#499bce59ae44af9e61dc106b6b1663a45669b87e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2935,6 +2935,7 @@ dependencies = [
"dirs", "dirs",
"ecow", "ecow",
"fs_extra", "fs_extra",
"memmap2",
"notify", "notify",
"open", "open",
"parking_lot", "parking_lot",

View File

@ -165,4 +165,4 @@ uninlined_format_args = "warn"
wildcard_in_or_patterns = "allow" wildcard_in_or_patterns = "allow"
[patch.crates-io] [patch.crates-io]
comemo = { git = "https://github.com/typst/comemo", rev = "70c0307" } comemo = { git = "https://github.com/typst/comemo", rev = "499bce5" }

View File

@ -56,6 +56,7 @@ toml = { workspace = true }
ureq = { workspace = true } ureq = { workspace = true }
xz2 = { workspace = true, optional = true } xz2 = { workspace = true, optional = true }
zip = { workspace = true, optional = true } zip = { workspace = true, optional = true }
memmap2 = "*"
[build-dependencies] [build-dependencies]
chrono = { workspace = true } chrono = { workspace = true }

View File

@ -47,6 +47,13 @@ static ARGS: LazyLock<CliArguments> = LazyLock::new(|| {
/// Entry point. /// Entry point.
fn main() -> ExitCode { fn main() -> ExitCode {
let mut prescient = false;
if let Ok(file) = std::fs::File::open("comemo-sink") {
let mmap = Box::leak(Box::new(unsafe { memmap2::Mmap::map(&file).unwrap() }));
comemo::put_prescience(&*mmap);
prescient = true;
}
// Handle SIGPIPE // Handle SIGPIPE
// https://stackoverflow.com/questions/65755853/simple-word-count-rust-program-outputs-valid-stdout-but-panicks-when-piped-to-he/65760807 // https://stackoverflow.com/questions/65755853/simple-word-count-rust-program-outputs-valid-stdout-but-panicks-when-piped-to-he/65760807
sigpipe::reset(); sigpipe::reset();
@ -58,6 +65,12 @@ fn main() -> ExitCode {
print_error(msg.message()).expect("failed to print error"); print_error(msg.message()).expect("failed to print error");
} }
if !prescient {
let file = std::fs::File::create("comemo-sink").unwrap();
let sink = std::io::BufWriter::new(file);
comemo::write_prescience(sink);
}
EXIT.with(|cell| cell.get()) EXIT.with(|cell| cell.get())
} }