Skip to content

Commit 15ff701

Browse files
author
Martin Nordholts
committed
Adapt to flate2 changing default backend to Rust two years ago
When the `-rs` versions of dump creation and loading were introduced in syntect, `flate2` defaulted to a C implementation and made the Rust backend optional. Since two years, the Rust backend has been the default backend. See rust-lang/flate2-rs@c479d064e2. So we can stop using the `-rs` versions since enabling them makes no difference. Note that there is no mechanism yet that we can use to mark features as deprecated. See rust-lang/cargo#7130
1 parent ec87599 commit 15ff701

File tree

7 files changed

+42
-45
lines changed

7 files changed

+42
-45
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ jobs:
7676
- name: Run Xi tests
7777
run: |
7878
# Test the build configuration that Xi uses
79-
cargo test --lib --no-default-features --features "assets dump-load-rs"
79+
cargo test --lib --no-default-features --features "assets dump-load"

Cargo.toml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lazy_static = "1.0"
2727
bitflags = "1.0.4"
2828
plist = "1"
2929
bincode = { version = "1.0", optional = true }
30-
flate2 = { version = "1.0", optional = true, default-features = false }
30+
flate2 = { version = "1.0", optional = true }
3131
fnv = { version = "1.0", optional = true }
3232
serde = "1.0"
3333
serde_derive = "1.0"
@@ -47,27 +47,24 @@ pretty_assertions = "0.6"
4747
# will fail, choose one of each. If you are using both creation and loading,
4848
# your binary will be smaller if you choose the same one for each.
4949

50-
# Pure Rust dump loading, slower than regular `dump-load`
51-
dump-load-rs = ["flate2/rust_backend", "bincode"]
52-
# Dump loading using flate2, which depends on the miniz C library.
53-
dump-load = ["flate2/default", "bincode"]
54-
# Dump creation using flate2, which depends on the miniz C library.
55-
dump-create = ["flate2/default", "bincode"]
56-
# Pure Rust dump creation, worse compressor so produces larger dumps than dump-create
57-
dump-create-rs = ["flate2/rust_backend", "bincode"]
50+
# Legacy alias for `dump-load`
51+
dump-load-rs = ["dump-load"]
52+
# Dump loading using flate2
53+
dump-load = ["flate2", "bincode"]
54+
# Dump creation using flate2
55+
dump-create = ["flate2", "bincode"]
56+
# Legacy alias for `dump-create`
57+
dump-create-rs = ["dump-create"]
5858

5959
regex-fancy = ["fancy-regex"]
6060
regex-onig = ["onig"]
6161

62-
# If you enable "parsing", you must also enable either "dump-load" or
63-
# "dump-load-rs", and "dump-create" or "dump-create-rs". Otherwise the code that
64-
# enables lazy-loading of syntaxes will not compile.
65-
parsing = ["regex-syntax", "fnv"]
62+
parsing = ["regex-syntax", "fnv", "dump-create", "dump-load"]
6663

6764
# Support for .tmPreferenes metadata files (indentation, comment syntax, etc)
6865
metadata = ["parsing"]
6966
# The `assets` feature enables inclusion of the default theme and syntax packages.
70-
# For `assets` to do anything, it requires one of `dump-load-rs` or `dump-load` to be set.
67+
# For `assets` to do anything, it requires `dump-load` to be set.
7168
assets = []
7269
html = ["parsing"]
7370
# Support for parsing .sublime-syntax files

src/dumps.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,43 @@
1313
//! [`ThemeSet`]: ../highlighting/struct.ThemeSet.html
1414
//! [`dump_to_file`]: fn.dump_to_file.html
1515
use bincode::Result;
16-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
16+
#[cfg(feature = "dump-load")]
1717
use bincode::deserialize_from;
18-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
18+
#[cfg(feature = "dump-create")]
1919
use bincode::serialize_into;
2020
use std::fs::File;
21-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
21+
#[cfg(feature = "dump-load")]
2222
use std::io::{BufRead};
23-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
23+
#[cfg(feature = "dump-create")]
2424
use std::io::{BufWriter, Write};
25-
#[cfg(all(feature = "parsing", feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
25+
#[cfg(all(feature = "parsing", feature = "assets", feature = "dump-load"))]
2626
use crate::parsing::SyntaxSet;
27-
#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
27+
#[cfg(all(feature = "assets", feature = "dump-load"))]
2828
use crate::highlighting::ThemeSet;
2929
use std::path::Path;
3030
#[cfg(feature = "dump-create")]
3131
use flate2::write::ZlibEncoder;
32-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
32+
#[cfg(feature = "dump-load")]
3333
use flate2::bufread::ZlibDecoder;
34-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
34+
#[cfg(feature = "dump-create")]
3535
use flate2::Compression;
36-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
36+
#[cfg(feature = "dump-create")]
3737
use serde::Serialize;
38-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
38+
#[cfg(feature = "dump-load")]
3939
use serde::de::DeserializeOwned;
4040

4141
/// Dumps an object to the given writer in a compressed binary format
4242
///
4343
/// The writer is encoded with the `bincode` crate and compressed with `flate2`.
44-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
44+
#[cfg(feature = "dump-create")]
4545
pub fn dump_to_writer<T: Serialize, W: Write>(to_dump: &T, output: W) -> Result<()> {
4646
serialize_to_writer_impl(to_dump, output, true)
4747
}
4848

4949
/// Dumps an object to a binary array in the same format as [`dump_to_writer`]
5050
///
5151
/// [`dump_to_writer`]: fn.dump_to_writer.html
52-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
52+
#[cfg(feature = "dump-create")]
5353
pub fn dump_binary<T: Serialize>(o: &T) -> Vec<u8> {
5454
let mut v = Vec::new();
5555
dump_to_writer(o, &mut v).unwrap();
@@ -62,28 +62,28 @@ pub fn dump_binary<T: Serialize>(o: &T) -> Vec<u8> {
6262
/// the `bincode` crate and then compressed with the `flate2` crate.
6363
///
6464
/// [`dump_to_writer`]: fn.dump_to_writer.html
65-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
65+
#[cfg(feature = "dump-create")]
6666
pub fn dump_to_file<T: Serialize, P: AsRef<Path>>(o: &T, path: P) -> Result<()> {
6767
let out = BufWriter::new(File::create(path)?);
6868
dump_to_writer(o, out)
6969
}
7070

7171
/// A helper function for decoding and decompressing data from a reader
72-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
72+
#[cfg(feature = "dump-load")]
7373
pub fn from_reader<T: DeserializeOwned, R: BufRead>(input: R) -> Result<T> {
7474
deserialize_from_reader_impl(input, true)
7575
}
7676

7777
/// Returns a fully loaded object from a binary dump.
7878
///
7979
/// This function panics if the dump is invalid.
80-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
80+
#[cfg(feature = "dump-load")]
8181
pub fn from_binary<T: DeserializeOwned>(v: &[u8]) -> T {
8282
from_reader(v).unwrap()
8383
}
8484

8585
/// Returns a fully loaded object from a binary dump file.
86-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
86+
#[cfg(feature = "dump-load")]
8787
pub fn from_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T> {
8888
let contents = std::fs::read(path)?;
8989
from_reader(&contents[..])
@@ -93,15 +93,15 @@ pub fn from_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T>
9393
/// itself shall not be compressed, because the data for its lazy-loaded
9494
/// syntaxes are already compressed. Compressing another time just results in
9595
/// bad performance.
96-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
96+
#[cfg(feature = "dump-create")]
9797
pub fn dump_to_uncompressed_file<T: Serialize, P: AsRef<Path>>(o: &T, path: P) -> Result<()> {
9898
let out = BufWriter::new(File::create(path)?);
9999
serialize_to_writer_impl(o, out, false)
100100
}
101101

102102
/// To be used when deserializing a [`SyntaxSet`] that was previously written to
103103
/// file using [dump_to_uncompressed_file].
104-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
104+
#[cfg(feature = "dump-load")]
105105
pub fn from_uncompressed_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T> {
106106
let contents = std::fs::read(path)?;
107107
deserialize_from_reader_impl(&contents[..], false)
@@ -110,13 +110,13 @@ pub fn from_uncompressed_dump_file<T: DeserializeOwned, P: AsRef<Path>>(path: P)
110110
/// To be used when deserializing a [`SyntaxSet`] from raw data, for example
111111
/// data that has been embedded in your own binary with the [`include_bytes!`]
112112
/// macro.
113-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
113+
#[cfg(feature = "dump-load")]
114114
pub fn from_uncompressed_data<T: DeserializeOwned>(v: &[u8]) -> Result<T> {
115115
deserialize_from_reader_impl(v, false)
116116
}
117117

118118
/// Private low level helper function used to implement the public API.
119-
#[cfg(any(feature = "dump-create", feature = "dump-create-rs"))]
119+
#[cfg(feature = "dump-create")]
120120
fn serialize_to_writer_impl<T: Serialize, W: Write>(to_dump: &T, output: W, use_compression: bool) -> Result<()> {
121121
if use_compression {
122122
let mut encoder = ZlibEncoder::new(output, Compression::best());
@@ -127,7 +127,7 @@ fn serialize_to_writer_impl<T: Serialize, W: Write>(to_dump: &T, output: W, use_
127127
}
128128

129129
/// Private low level helper function used to implement the public API.
130-
#[cfg(any(feature = "dump-load", feature = "dump-load-rs"))]
130+
#[cfg(feature = "dump-load")]
131131
fn deserialize_from_reader_impl<T: DeserializeOwned, R: BufRead>(input: R, use_compression: bool) -> Result<T> {
132132
if use_compression {
133133
let mut decoder = ZlibDecoder::new(input);
@@ -137,7 +137,7 @@ fn deserialize_from_reader_impl<T: DeserializeOwned, R: BufRead>(input: R, use_c
137137
}
138138
}
139139

140-
#[cfg(all(feature = "parsing", feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
140+
#[cfg(all(feature = "parsing", feature = "assets", feature = "dump-load"))]
141141
impl SyntaxSet {
142142
/// Instantiates a new syntax set from a binary dump of Sublime Text's default open source
143143
/// syntax definitions.
@@ -195,7 +195,7 @@ impl SyntaxSet {
195195
}
196196
}
197197

198-
#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
198+
#[cfg(all(feature = "assets", feature = "dump-load"))]
199199
impl ThemeSet {
200200
/// Loads the set of default themes
201201
/// Currently includes (these are the keys for the map):
@@ -210,7 +210,7 @@ impl ThemeSet {
210210

211211
#[cfg(test)]
212212
mod tests {
213-
#[cfg(all(feature = "yaml-load", any(feature = "dump-create", feature = "dump-create-rs"), any(feature = "dump-load", feature = "dump-load-rs")))]
213+
#[cfg(all(feature = "yaml-load", feature = "dump-create", feature = "dump-load"))]
214214
#[test]
215215
fn can_dump_and_load() {
216216
use super::*;
@@ -225,7 +225,7 @@ mod tests {
225225
assert_eq!(ss.syntaxes().len(), ss2.syntaxes().len());
226226
}
227227

228-
#[cfg(all(feature = "yaml-load", any(feature = "dump-create", feature = "dump-create-rs"), any(feature = "dump-load", feature = "dump-load-rs")))]
228+
#[cfg(all(feature = "yaml-load", feature = "dump-create", feature = "dump-load"))]
229229
#[test]
230230
fn dump_is_deterministic() {
231231
use super::*;
@@ -246,7 +246,7 @@ mod tests {
246246
assert_eq!(bin1, bin2);
247247
}
248248

249-
#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
249+
#[cfg(all(feature = "assets", feature = "dump-load"))]
250250
#[test]
251251
fn has_default_themes() {
252252
use crate::highlighting::ThemeSet;

src/easy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a> Iterator for ScopeRegionIterator<'a> {
251251
}
252252
}
253253

254-
#[cfg(all(feature = "assets", any(feature = "dump-load", feature = "dump-load-rs")))]
254+
#[cfg(all(feature = "assets", feature = "dump-load"))]
255255
#[cfg(test)]
256256
mod tests {
257257
use super::*;

src/highlighting/highlighter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a> Highlighter<'a> {
370370
}
371371
}
372372

373-
#[cfg(all(feature = "assets", feature = "parsing", any(feature = "dump-load", feature = "dump-load-rs")))]
373+
#[cfg(all(feature = "assets", feature = "parsing", feature = "dump-load"))]
374374
#[cfg(test)]
375375
mod tests {
376376
use super::*;

src/html.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub fn start_highlighted_html_snippet(t: &Theme) -> (String, Color) {
518518

519519
#[cfg(all(
520520
feature = "assets",
521-
any(feature = "dump-load", feature = "dump-load-rs")
521+
feature = "dump-load"
522522
))]
523523
#[cfg(test)]
524524
mod tests {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern crate serde_derive;
2929
#[macro_use]
3030
extern crate pretty_assertions;
3131

32-
#[cfg(any(feature = "dump-load-rs", feature = "dump-load", feature = "dump-create", feature = "dump-create-rs"))]
32+
#[cfg(any(feature = "dump-load", feature = "dump-create"))]
3333
pub mod dumps;
3434
#[cfg(feature = "parsing")]
3535
pub mod easy;

0 commit comments

Comments
 (0)