Use custom syntect packs to reduce binary size

- Custom syntax set containing only C/C++
- Custom themeset containing only Solarized (Dark)
- Disable default syntect features
This commit is contained in:
Luke Street 2023-11-18 16:12:03 -05:00
parent d7a3fd53c7
commit 363fa2ac72
6 changed files with 19 additions and 104 deletions

99
Cargo.lock generated
View File

@ -343,15 +343,6 @@ dependencies = [
"xxhash-rust",
]
[[package]]
name = "deranged"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
dependencies = [
"powerfmt",
]
[[package]]
name = "digest"
version = "0.10.7"
@ -567,21 +558,6 @@ version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "line-wrap"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9"
dependencies = [
"safemem",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
@ -778,26 +754,6 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "plist"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef"
dependencies = [
"base64",
"indexmap",
"line-wrap",
"quick-xml",
"serde",
"time",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppc750cl"
version = "0.2.0"
@ -837,15 +793,6 @@ dependencies = [
"unicase",
]
[[package]]
name = "quick-xml"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
dependencies = [
"memchr",
]
[[package]]
name = "quote"
version = "1.0.33"
@ -965,12 +912,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "safemem"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
[[package]]
name = "same-file"
version = "1.0.6"
@ -1127,13 +1068,11 @@ dependencies = [
"fnv",
"once_cell",
"onig",
"plist",
"regex-syntax 0.7.5",
"serde",
"serde_json",
"thiserror",
"walkdir",
"yaml-rust",
]
[[package]]
@ -1175,35 +1114,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
dependencies = [
"deranged",
"itoa",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
dependencies = [
"time-core",
]
[[package]]
name = "toml_datetime"
version = "0.6.5"
@ -1512,15 +1422,6 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9828b178da53440fa9c766a3d2f73f7cf5d0ac1fe3980c1e5018d899fd19e07b"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]]
name = "zerocopy"
version = "0.7.26"

View File

@ -63,7 +63,7 @@ serde_yaml = "0.9.27"
sha-1 = "0.10.1"
smallvec = "1.11.2"
supports-color = "2.1.0"
syntect = "5.1.0"
syntect = { version = "5.1.0", features = ["parsing", "regex-onig", "dump-load"], default-features = false }
tracing = "0.1.40"
tracing-attributes = "0.1.27"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

11
assets/syntax/README Normal file
View File

@ -0,0 +1,11 @@
syntect packs generated from:
https://github.com/braver/Solarized/blob/87e01090cf5fb821a234265b3138426ae84900e7/Solarized%20(dark).tmTheme
https://github.com/sublimehq/Packages/tree/fa6b8629c95041bf262d4c1dab95c456a0530122/C%2B%2B
// let mut theme_set = ThemeSet::load_from_folder("../Solarized")?;
// syntect::dumps::dump_to_file(&theme_set, "assets/syntax/default.themedump")?;
//
// let mut builder = SyntaxSetBuilder::new();
// builder.add_from_folder("../sublimehq-Packages/C++", true)?;
// let syntax_set = builder.build();
// syntect::dumps::dump_to_file(&syntax_set, "assets/syntax/default_newlines.packdump")?;

Binary file not shown.

Binary file not shown.

View File

@ -57,11 +57,14 @@ pub fn run(args: Args) -> Result<()> {
}
fn dump(args: DumpArgs) -> Result<()> {
let theme_set = ThemeSet::load_defaults();
// Load syntect
let theme_set: ThemeSet =
syntect::dumps::from_binary(include_bytes!("../../assets/syntax/default.themedump"));
let syntax_set: SyntaxSet = syntect::dumps::from_binary(include_bytes!(
"../../assets/syntax/default_newlines.packdump"
));
let theme = theme_set.themes.get("Solarized (dark)").context("Failed to load theme")?;
let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax =
syntax_set.find_syntax_by_extension("cpp").context("Failed to find syntax")?.clone();
let syntax = syntax_set.find_syntax_by_name("C++").context("Failed to find syntax")?.clone();
let file = map_file(&args.in_file)?;
let buf = file.as_slice();