Skip to content

Commit

Permalink
Add WASM support
Browse files Browse the repository at this point in the history
  • Loading branch information
dgopsq committed Aug 11, 2022
1 parent a9d97a1 commit 645cb7e
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 16 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ num_cpus = "1.8.0"
regex = "1.3.5"
serde_json = "1.0.23"
termcolor = "1.1.0"
instant = { version = "0.1.12", features = [ "wasm-bindgen" ] }

[dependencies.clap]
version = "2.33.0"
Expand Down
5 changes: 5 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,8 @@ pub fn is_tty_stdout() -> bool {
pub fn is_tty_stderr() -> bool {
atty::is(atty::Stream::Stderr)
}

#[cfg(not(any(unix, windows)))]
fn imp() -> bool {
false
}
2 changes: 1 addition & 1 deletion crates/core/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use instant::SystemTime;
use std::cmp;
use std::env;
use std::ffi::{OsStr, OsString};
Expand All @@ -6,7 +7,6 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process;
use std::sync::Arc;
use std::time::SystemTime;

use clap;
use grep::cli;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use instant::*;
use std::error;
use std::io::{self, Write};
use std::process;
use std::sync::Mutex;
use std::time::Instant;

use ignore::WalkState;

Expand Down
2 changes: 1 addition & 1 deletion crates/core/search.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use instant::Duration;
use std::fs::File;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::time::Duration;

use grep::cli;
use grep::matcher::Matcher;
Expand Down
1 change: 1 addition & 0 deletions crates/ignore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ regex = "1.1"
same-file = "1.0.4"
thread_local = "1"
walkdir = "2.2.7"
instant = { version = "0.1.12", features = [ "wasm-bindgen" ] }

[target.'cfg(windows)'.dependencies.winapi-util]
version = "0.1.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/ignore/src/walk.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use instant::Duration;
use std::cmp;
use std::ffi::OsStr;
use std::fmt;
Expand All @@ -7,7 +8,6 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use std::vec;

use same_file::Handle;
Expand Down
1 change: 1 addition & 0 deletions crates/printer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ grep-searcher = { version = "0.1.8", path = "../searcher" }
termcolor = "1.0.4"
serde = { version = "1.0.77", optional = true, features = ["derive"] }
serde_json = { version = "1.0.27", optional = true }
instant = { version = "0.1.12", features = [ "wasm-bindgen" ] }

[dev-dependencies]
grep-regex = { version = "0.1.9", path = "../regex" }
2 changes: 1 addition & 1 deletion crates/printer/src/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use instant::*;
use std::io::{self, Write};
use std::path::Path;
use std::time::Instant;

use grep_matcher::{Match, Matcher};
use grep_searcher::{
Expand Down
6 changes: 3 additions & 3 deletions crates/printer/src/standard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use instant::Instant;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::io::{self, Write};
use std::path::Path;
use std::sync::Arc;
use std::time::Instant;

use bstr::ByteSlice;
use grep_matcher::{Match, Matcher};
Expand Down Expand Up @@ -1702,7 +1702,7 @@ and exhibited clearly, with a label attached.\

#[test]
fn reports_stats() {
use std::time::Duration;
use instant::Duration;

let matcher = RegexMatcher::new("Sherlock|opposed").unwrap();
let mut printer =
Expand All @@ -1729,7 +1729,7 @@ and exhibited clearly, with a label attached.\

#[test]
fn reports_stats_multiple() {
use std::time::Duration;
use instant::Duration;

let matcher = RegexMatcher::new("Sherlock|opposed").unwrap();
let mut printer =
Expand Down
2 changes: 1 addition & 1 deletion crates/printer/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use instant::Duration;
use std::ops::{Add, AddAssign};
use std::time::Duration;

use crate::util::NiceDuration;

Expand Down
2 changes: 1 addition & 1 deletion crates/printer/src/summary.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use instant::Instant;
use std::cell::RefCell;
use std::io::{self, Write};
use std::path::Path;
use std::sync::Arc;
use std::time::Instant;

use grep_matcher::Matcher;
use grep_searcher::{Searcher, Sink, SinkError, SinkFinish, SinkMatch};
Expand Down
4 changes: 2 additions & 2 deletions crates/printer/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use instant::*;
use std::borrow::Cow;
use std::fmt;
use std::io;
use std::path::Path;
use std::time;

use bstr::{ByteSlice, ByteVec};
use grep_matcher::{Captures, LineTerminator, Match, Matcher};
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a> PrinterPath<'a> {
/// with the Deserialize impl for std::time::Duration, since this type only
/// adds new fields.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NiceDuration(pub time::Duration);
pub struct NiceDuration(pub Duration);

impl fmt::Display for NiceDuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
4 changes: 1 addition & 3 deletions tests/json.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time;

use serde_derive::Deserialize;
use serde_json as json;

Expand Down Expand Up @@ -130,7 +128,7 @@ struct Stats {
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
struct Duration {
#[serde(flatten)]
duration: time::Duration,
duration: instant::Duration,
human: String,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use instant::Duration;
use std::env;
use std::error;
use std::ffi::OsStr;
Expand All @@ -7,7 +8,6 @@ use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;

static TEST_DIR: &'static str = "ripgrep-tests";
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
Expand Down

0 comments on commit 645cb7e

Please sign in to comment.