Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ nlprule-build = { version = "=0.6.4", optional = true }
# compress the nlprule artifacts to be under the 10 MB limit
# that cargo enforces
xz2 = "0.1"
cargo_toml = "^0.10.1"

[dependencies]
color-eyre = "0.5"
cargo_toml = "^0.10.1"
console = "0.15"
crossterm = "0.21.0"
crossterm = "0.22.1"
# for the config file
directories = "4.0.1"
docopt = "1"
Expand All @@ -45,7 +46,7 @@ log = "0.4"
num_cpus = "1.13"
proc-macro2 = { version = "1", features = ["span-locations"] }
pulldown-cmark = "0.8.0"
ra_ap_syntax = "0.0.77"
ra_ap_syntax = "0.0.78"
rayon = "1.5"
regex = "1.5"
serde = { version = "1", features = ["derive"] }
Expand Down
54 changes: 46 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,69 @@ use std::io::BufReader;
use std::path::PathBuf;
use xz2::bufread::{XzDecoder, XzEncoder};

fn extract_version<'a>(manifest: &'a cargo_toml::Manifest, pkg_name: &str) -> Option<&'a str> {
let (_, dependency) = manifest
.dependencies
.get_key_value(pkg_name)?;
let version = dependency
.detail()
.map(|x| x.version.as_ref().map(|x| x.as_str())).flatten()?;
let version = match version {
x if x.starts_with("=") => &version[1..],
x if x.starts_with("<=") || x.starts_with(">=") => &version[2..],
x if x.starts_with("*") => panic!("Don't be silly."),
_ => version,
};
Some(version)
}

fn main() -> std::result::Result<(), Box<(dyn std::error::Error + 'static)>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=Cargo.toml");

let out = env::var("OUT_DIR").expect("OUT_DIR exists in env vars. qed");
let out = PathBuf::from(out);

const MISSING: &str = "NOT COMPILED IN";
if !cfg!(feature = "hunspell") {
println!("cargo:rustc-env=CHECKER_NLPRULE_VERSION={}", MISSING);
}
if !cfg!(feature = "nlprules") {
println!("cargo:rustc-env=CHECKER_HUNSPELL_VERSION={}", MISSING);
}

// extract the version from the manifest.
// only accept defined versions, no git dependencies or whatever
let manifest = std::path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST exists in env vars. qed")).join("Cargo.toml");
let manifest = cargo_toml::Manifest::from_path(manifest)?;
#[cfg(feature = "hunspell")]
{
let version = extract_version(&manifest, "hunspell-rs").expect("Hunspell must be present. qed");
println!("cargo:rustc-env=CHECKER_HUNSPELL_VERSION={}", version);
}
#[cfg(feature = "nlprules")]
{
let nlprule_version = extract_version(&manifest, "nlprule").expect("Hunspell must be present. qed");
println!("cargo:rustc-env=CHECKER_NLPRULE_VERSION={}", nlprule_version);

const COMPRESSION_EXTENSION: &str = "xz";
const ARTIFACTS_DIR: &str = "nlprule-data";

println!("cargo:rerun-if-changed=nlprule-data/en_rules.bin.xz");
println!("cargo:rerun-if-changed=nlprule-data/en_tokenizer.bin.xz");
let cwd = env::current_dir().expect("Current dir exists. qed");
let cache_dir = cwd.join(ARTIFACTS_DIR).join(nlprule_version).join("en");
std::fs::create_dir_all(&cache_dir)?;
println!("cargo:rerun-if-changed={}/en_rules.bin.{}", cache_dir.display(), COMPRESSION_EXTENSION);
println!("cargo:rerun-if-changed={}/en_tokenizer.bin.{}", cache_dir.display(), COMPRESSION_EXTENSION);

println!("cargo:rerun-if-changed={}/en_rules.bin", out.display());
println!("cargo:rerun-if-changed={}/en_tokenizer.bin", out.display());

let cwd = env::current_dir().expect("Current dir must exist. qed");

let cache_dir = Some(cwd.join(ARTIFACTS_DIR));

nlprule_build::BinaryBuilder::new(&["en"], &out)
let builder = nlprule_build::BinaryBuilder::new(&["en"], &out);
builder
.version(nlprule_version)
.out_dir(out)
.fallback_to_build_dir(false)
.cache_dir(cache_dir)
.cache_dir(Some(cache_dir))
.transform(
|source, mut sink| {
let mut encoder = XzEncoder::new(BufReader::new(source), 9);
Expand Down
2 changes: 1 addition & 1 deletion src/config/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Usage:
cargo-spellcheck [(-v...|-q)] [--jobs=<jobs>] config (--user|--stdout|--cfg=<cfg>) [--checkers=<checkers>] [--force]
cargo-spellcheck [(-v...|-q)] [--jobs=<jobs>] list-files [--skip-readme] [[--recursive] <paths>... ]
cargo-spellcheck [(-v...|-q)] [--jobs=<jobs>] [check] [--fix] [--cfg=<cfg>] [--code=<code>] [--dev-comments] [--skip-readme] [--checkers=<checkers>] [[--recursive] <paths>... ]
cargo-spellcheck --version
cargo-spellcheck --version [-v...]
cargo-spellcheck --help

Options:
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ fn run() -> Result<ExitCode> {
match args.action() {
Action::Version => {
println!("cargo-spellcheck {}", env!("CARGO_PKG_VERSION"));
if args.flag_verbose > 0 {
println!("hunspell {}", env!("CHECKER_HUNSPELL_VERSION"));
println!("nlprules {}", env!("CHECKER_NLPRULE_VERSION"));
}
return Ok(ExitCode::Success);
}
Action::Help => {
Expand Down