mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Faster compile times and test execution ⚡
- Optimize only dependencies, not the main crate - Don't generate debug info - Don't generate PDFs for all tets by default
This commit is contained in:
parent
1584b09708
commit
3c74e4566a
22
Cargo.toml
22
Cargo.toml
@ -4,13 +4,21 @@ version = "0.1.0"
|
|||||||
authors = ["The Typst Project Developers"]
|
authors = ["The Typst Project Developers"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["fs"]
|
||||||
|
cli = ["fs", "anyhow"]
|
||||||
|
fs = ["fontdock/fs"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["bench"]
|
members = ["bench"]
|
||||||
|
|
||||||
[features]
|
[profile.dev]
|
||||||
default = ["cli", "fs"]
|
# Faster compilation
|
||||||
cli = ["fs", "anyhow"]
|
debug = 0
|
||||||
fs = ["fontdock/fs"]
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
# Faster test execution
|
||||||
|
opt-level = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fontdock = { path = "../fontdock", default-features = false }
|
fontdock = { path = "../fontdock", default-features = false }
|
||||||
@ -26,12 +34,6 @@ serde = { version = "1", features = ["derive"], optional = true }
|
|||||||
tiny-skia = "0.2"
|
tiny-skia = "0.2"
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
opt-level = 2
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "typst"
|
name = "typst"
|
||||||
required-features = ["cli"]
|
required-features = ["cli"]
|
||||||
|
@ -37,7 +37,7 @@ const FONT_DIR: &str = "../fonts";
|
|||||||
fn main() {
|
fn main() {
|
||||||
env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap();
|
env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap();
|
||||||
|
|
||||||
let filter = TestFilter::new(env::args().skip(1));
|
let args = Args::new(env::args().skip(1));
|
||||||
let mut filtered = Vec::new();
|
let mut filtered = Vec::new();
|
||||||
|
|
||||||
for entry in WalkDir::new(".").into_iter() {
|
for entry in WalkDir::new(".").into_iter() {
|
||||||
@ -51,7 +51,7 @@ fn main() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter.matches(&src_path.to_string_lossy()) {
|
if args.matches(&src_path.to_string_lossy()) {
|
||||||
filtered.push(src_path);
|
filtered.push(src_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,11 +73,19 @@ fn main() {
|
|||||||
|
|
||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
for src_path in filtered {
|
for src_path in filtered {
|
||||||
let trailer = src_path.strip_prefix(TYP_DIR).unwrap();
|
let path = src_path.strip_prefix(TYP_DIR).unwrap();
|
||||||
let png_path = Path::new(PNG_DIR).join(trailer).with_extension("png");
|
let png_path = Path::new(PNG_DIR).join(path).with_extension("png");
|
||||||
let pdf_path = Path::new(PDF_DIR).join(trailer).with_extension("pdf");
|
let ref_path = Path::new(REF_DIR).join(path).with_extension("png");
|
||||||
let ref_path = Path::new(REF_DIR).join(trailer).with_extension("png");
|
let pdf_path =
|
||||||
ok &= test(&src_path, &png_path, &pdf_path, &ref_path, &mut env);
|
args.pdf.then(|| Path::new(PDF_DIR).join(path).with_extension("pdf"));
|
||||||
|
|
||||||
|
ok &= test(
|
||||||
|
&mut env,
|
||||||
|
&src_path,
|
||||||
|
&png_path,
|
||||||
|
&ref_path,
|
||||||
|
pdf_path.as_deref(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -85,25 +93,28 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestFilter {
|
struct Args {
|
||||||
filter: Vec<String>,
|
filter: Vec<String>,
|
||||||
|
pdf: bool,
|
||||||
perfect: bool,
|
perfect: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestFilter {
|
impl Args {
|
||||||
fn new(args: impl Iterator<Item = String>) -> Self {
|
fn new(args: impl Iterator<Item = String>) -> Self {
|
||||||
let mut filter = Vec::new();
|
let mut filter = Vec::new();
|
||||||
let mut perfect = false;
|
let mut perfect = false;
|
||||||
|
let mut pdf = false;
|
||||||
|
|
||||||
for arg in args {
|
for arg in args {
|
||||||
match arg.as_str() {
|
match arg.as_str() {
|
||||||
"--nocapture" => {}
|
"--nocapture" => {}
|
||||||
|
"--pdf" => pdf = true,
|
||||||
"=" => perfect = true,
|
"=" => perfect = true,
|
||||||
_ => filter.push(arg),
|
_ => filter.push(arg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { filter, perfect }
|
Self { filter, pdf, perfect }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn matches(&self, name: &str) -> bool {
|
fn matches(&self, name: &str) -> bool {
|
||||||
@ -116,11 +127,11 @@ impl TestFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test(
|
fn test(
|
||||||
|
env: &mut Env,
|
||||||
src_path: &Path,
|
src_path: &Path,
|
||||||
png_path: &Path,
|
png_path: &Path,
|
||||||
pdf_path: &Path,
|
|
||||||
ref_path: &Path,
|
ref_path: &Path,
|
||||||
env: &mut Env,
|
pdf_path: Option<&Path>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
||||||
println!("Testing {}", name.display());
|
println!("Testing {}", name.display());
|
||||||
@ -149,7 +160,7 @@ fn test(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let (part_ok, compare_here, part_frames) =
|
let (part_ok, compare_here, part_frames) =
|
||||||
test_part(part, i, compare_ref, lines, env);
|
test_part(env, part, i, compare_ref, lines);
|
||||||
ok &= part_ok;
|
ok &= part_ok;
|
||||||
compare_ever |= compare_here;
|
compare_ever |= compare_here;
|
||||||
frames.extend(part_frames);
|
frames.extend(part_frames);
|
||||||
@ -159,9 +170,11 @@ fn test(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if compare_ever {
|
if compare_ever {
|
||||||
let pdf_data = pdf::export(&env, &frames);
|
if let Some(pdf_path) = pdf_path {
|
||||||
fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
|
let pdf_data = pdf::export(&env, &frames);
|
||||||
fs::write(pdf_path, pdf_data).unwrap();
|
fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
|
||||||
|
fs::write(pdf_path, pdf_data).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let canvas = draw(&env, &frames, 2.0);
|
let canvas = draw(&env, &frames, 2.0);
|
||||||
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
||||||
@ -186,11 +199,11 @@ fn test(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_part(
|
fn test_part(
|
||||||
|
env: &mut Env,
|
||||||
src: &str,
|
src: &str,
|
||||||
i: usize,
|
i: usize,
|
||||||
compare_ref: bool,
|
compare_ref: bool,
|
||||||
lines: u32,
|
lines: u32,
|
||||||
env: &mut Env,
|
|
||||||
) -> (bool, bool, Vec<Frame>) {
|
) -> (bool, bool, Vec<Frame>) {
|
||||||
let map = LineMap::new(src);
|
let map = LineMap::new(src);
|
||||||
let (local_compare_ref, ref_diags) = parse_metadata(src, &map);
|
let (local_compare_ref, ref_diags) = parse_metadata(src, &map);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user