-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests with re2 and compiler feature detection.
- Loading branch information
1 parent
f35af56
commit 1702cfd
Showing
11 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "re2"] | ||
path = re2 | ||
url = https://github.com/google/re2/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <re2/re2.h> | ||
|
||
extern "C" { | ||
bool is_match(const char* pattern, const char* string) { | ||
re2::StringPiece regex(pattern); | ||
re2::StringPiece input(string); | ||
return re2::RE2::FullMatch(input, regex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
#[cfg(feature = "re2")] | ||
use rust_cmake_hello_world::hello_is_match; | ||
use rust_cmake_hello_world::multiply_add; | ||
|
||
pub fn main() { | ||
println!("multiply_add(2, 3, 4)={:?}", multiply_add(2, 3, 4)); | ||
#[cfg(feature = "re2")] | ||
{ | ||
let pattern = "Hello.*"; | ||
let input = "Hello World"; | ||
let matches = match hello_is_match(pattern, input) { | ||
true => "matches", | ||
false => "does not match", | ||
}; | ||
println!("{pattern:?} {matches} the input {input:?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
use cmake; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=src/build.rs"); | ||
|
||
build_sum(); | ||
build_re2(); | ||
} | ||
|
||
fn build_sum() { | ||
let dst = cmake::build("libsum"); | ||
println!("cargo:rustc-link-search=native={}/lib", dst.display()); | ||
println!("cargo:rustc-link-lib=static=sum"); | ||
} | ||
|
||
fn build_re2() { | ||
if cfg!(feature = "re2") { | ||
let dst = cmake::build("re2"); | ||
|
||
cc::Build::new() | ||
.cpp(true) | ||
.file("match.cc") | ||
.include(dst.join("include")) | ||
.compile("libmatch.a"); | ||
|
||
println!("cargo:rerun-if-changed=match.cc"); | ||
println!("cargo:rustc-link-search=native={}/build", dst.display()); | ||
println!("cargo:rustc-link-lib=static=re2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![cfg(feature = "re2")] | ||
|
||
use std::ffi::CString; | ||
use std::os::raw::c_char; | ||
|
||
pub fn hello_is_match(pattern: &str, input: &str) -> bool { | ||
let pattern = CString::new(pattern).unwrap(); | ||
let input = CString::new(input).unwrap(); | ||
unsafe { is_match(pattern.as_ptr(), input.as_ptr()) } | ||
} | ||
|
||
extern "C" { | ||
fn is_match(pattern: *const c_char, string: *const c_char) -> bool; | ||
} |