Skip to content

Commit 00f30ee

Browse files
committed
bench: update the benchmark runner
This updates dependencies and makes sure everything compiles and runs. This also simplifies the build script.
1 parent 2f1e5b0 commit 00f30ee

File tree

7 files changed

+34
-986
lines changed

7 files changed

+34
-986
lines changed

bench/Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ build = "build.rs"
1212
workspace = ".."
1313

1414
[dependencies]
15-
docopt = "0.6"
16-
lazy_static = "0.1"
15+
docopt = "0.8"
16+
lazy_static = "1"
1717
libc = "0.2"
18-
onig = { version = "1.2", optional = true }
18+
onig = { version = "3", optional = true }
1919
libpcre-sys = { version = "0.2", optional = true }
2020
memmap = "0.2"
2121
regex = { version = "0.2.0", path = "..", features = ["simd-accel"] }
22-
regex_macros = { version = "0.2.0", path = "../regex_macros", optional = true }
2322
regex-syntax = { version = "0.4.0", path = "../regex-syntax" }
24-
rustc-serialize = "0.3"
23+
serde = "1"
24+
serde_derive = "1"
2525

2626
[build-dependencies]
27-
gcc = "0.3"
28-
pkg-config = "0.3"
27+
cc = "1"
28+
pkg-config = "0.3.9"
2929

3030
[[bin]]
3131
name = "regex-run-one"
@@ -41,8 +41,7 @@ bench = false
4141
# Doing anything else will probably result in weird "duplicate definition"
4242
# compiler errors.
4343
#
44-
# Tip: use the run-bench script in the root of this repository to run
45-
# benchmarks.
44+
# Tip: use the run script in this directory to run benchmarks.
4645
[features]
4746
re-pcre1 = ["libpcre-sys"]
4847
re-pcre2 = []

bench/build.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,26 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate gcc;
11+
extern crate cc;
1212
extern crate pkg_config;
1313

1414
use std::env;
15-
use std::process;
16-
17-
macro_rules! we {
18-
($($tt:tt)*) => {{
19-
use std::io::Write;
20-
writeln!(&mut ::std::io::stderr(), $($tt),*).unwrap();
21-
}}
22-
}
2315

2416
fn main() {
25-
// We only need to look for PCRE2 and RE2 because we roll the FFI bindings
26-
// for those libraries ourselves from scratch. For PCRE1 and Oniguruma, we
27-
// rely on other crates that do something similar to the dance below for
28-
// us.
29-
30-
let wants_pcre2 = env::var("CARGO_FEATURE_RE_PCRE2").is_ok();
31-
let has_pcre2 = pkg_config::Config::new().find("libpcre2-8").is_ok();
32-
if wants_pcre2 && !has_pcre2 {
33-
we!("pcre2 cannot be found by pkg-config");
34-
process::exit(1);
17+
if env::var("CARGO_FEATURE_RE_PCRE2").is_ok() {
18+
pkg_config::probe_library("libpcre2-8").unwrap();
3519
}
36-
37-
let wants_re2 = env::var("CARGO_FEATURE_RE_RE2").is_ok();
38-
let has_re2 = pkg_config::Config::new().find("re2").is_ok();
39-
if wants_re2 {
40-
if !has_re2 {
41-
we!("re2 cannot be found by pkg-config");
42-
process::exit(1);
43-
}
44-
gcc::Config::new()
20+
if env::var("CARGO_FEATURE_RE_RE2").is_ok() {
21+
// RE2 is a C++ library, so we need to compile our shim layer.
22+
cc::Build::new()
4523
.cpp(true)
46-
.flag("-std=c++11")
4724
.file("src/ffi/re2.cpp")
4825
.compile("libcre2.a");
49-
println!("cargo:rustc-link-lib=re2");
26+
// It's important this comes after compiling the shim, which results
27+
// in the correct order of arguments given to the linker.
28+
pkg_config::probe_library("re2").unwrap();
5029
}
51-
52-
let wants_tcl = env::var("CARGO_FEATURE_RE_TCL").is_ok();
53-
let has_tcl = pkg_config::Config::new().find("tcl").is_ok();
54-
if wants_tcl && !has_tcl {
55-
we!("tcl cannot be found by pkg-config");
56-
process::exit(1);
30+
if env::var("CARGO_FEATURE_RE_TCL").is_ok() {
31+
pkg_config::probe_library("tcl").unwrap();
5732
}
5833
}

bench/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ case $which in
2323
exec cargo bench --bench bench --features re-rust-bytes "$@"
2424
;;
2525
re2)
26-
exec cargo bench --bench bench --features re-re2 "$@"
26+
exec cargo bench --verbose --bench bench --features re-re2 "$@"
2727
;;
2828
pcre1)
2929
exec cargo bench --bench bench --features re-pcre1 "$@"

bench/src/ffi/onig.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ impl Regex {
2222
pub fn is_match(&self, text: &str) -> bool {
2323
// Gah. onig's is_match function is anchored, but find is not.
2424
self.0.search_with_options(
25-
text, 0, text.len(), onig::SEARCH_OPTION_NONE, None).is_some()
25+
text,
26+
0,
27+
text.len(),
28+
onig::SearchOptions::SEARCH_OPTION_NONE,
29+
None,
30+
).is_some()
2631
}
2732

2833
pub fn find_iter<'r, 't>(

bench/src/ffi/re2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include <stdio.h>
33

4-
#include "re2.h"
4+
#include "re2/re2.h"
55

66
using namespace re2;
77

0 commit comments

Comments
 (0)