1use std::fmt;
6
7use comemo::{Track, Tracked};
8use typst::ecow::EcoString;
9use typst_kit::datetime::Time;
10use typst_kit::fonts::FontStore;
11
12use crate::foundation::{FilesystemDependency, FontConfig, Project};
13
14mod content;
15mod downloader;
16mod files;
17mod output;
18mod pipeline;
19mod postprocess;
20mod transform;
21mod world;
22
23use self::files::ProjectFiles;
24
25pub use pipeline::BuildOutcome;
26
27pub struct BuildSession {
32 project: Project,
33 font_config: Option<FontConfig>,
34 fonts: FontStore,
35 files: ProjectFiles,
36 now: Time,
37 dev: bool,
38}
39
40impl BuildSession {
41 pub fn new(project: Project, dev: bool) -> Self {
45 let files = ProjectFiles::new(&project);
46 Self {
47 project,
48 font_config: None,
49 fonts: FontStore::new(),
50 files,
51 now: Time::system(),
52 dev,
53 }
54 }
55
56 pub fn project(&self) -> &Project {
58 &self.project
59 }
60
61 pub fn dependencies(&mut self) -> Vec<FilesystemDependency> {
63 self.files.dependencies()
64 }
65
66 fn reset(&mut self) {
67 self.files.reset();
68 self.now.reset();
69 }
70
71 fn project_files(&self) -> Tracked<'_, ProjectFiles> {
72 self.files.track()
73 }
74}
75
76#[derive(Clone, Debug, Eq, Hash, PartialEq)]
78pub struct BuildWarning(EcoString);
79
80impl BuildWarning {
81 fn new(message: impl Into<EcoString>) -> Self {
82 Self(message.into())
83 }
84
85 pub fn as_str(&self) -> &str {
87 self.0.as_str()
88 }
89}
90
91impl fmt::Display for BuildWarning {
92 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
93 formatter.write_str(&self.0)
94 }
95}
96
97impl AsRef<str> for BuildWarning {
98 fn as_ref(&self) -> &str {
99 self.as_str()
100 }
101}