##// END OF EJS Templates
rust: add option of static linking a local Re2 install...
Raphaël Gomès -
r45207:97c10b15 default
parent child Browse files
Show More
@@ -1,25 +1,61 b''
1 // build.rs
1 // build.rs
2 //
2 //
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net>
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net>
4 //
4 //
5 // This software may be used and distributed according to the terms of the
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
6 // GNU General Public License version 2 or any later version.
7
7
8 #[cfg(feature = "with-re2")]
8 #[cfg(feature = "with-re2")]
9 use cc;
9 use cc;
10
10
11 /// Uses either the system Re2 install as a dynamic library or the provided
12 /// build as a static library
11 #[cfg(feature = "with-re2")]
13 #[cfg(feature = "with-re2")]
12 fn compile_re2() {
14 fn compile_re2() {
13 cc::Build::new()
15 use cc;
16 use std::path::Path;
17 use std::process::exit;
18
19 let msg = r"HG_RE2_PATH must be one of `system|<path to build source clone of Re2>`";
20 let re2 = match std::env::var_os("HG_RE2_PATH") {
21 None => {
22 eprintln!("{}", msg);
23 exit(1)
24 }
25 Some(v) => {
26 if v == "system" {
27 None
28 } else {
29 Some(v)
30 }
31 }
32 };
33
34 let mut options = cc::Build::new();
35 options
14 .cpp(true)
36 .cpp(true)
15 .flag("-std=c++11")
37 .flag("-std=c++11")
16 .file("src/re2/rust_re2.cpp")
38 .file("src/re2/rust_re2.cpp");
17 .compile("librustre.a");
39
40 if let Some(ref source) = re2 {
41 options.include(Path::new(source));
42 };
43
44 options.compile("librustre.a");
18
45
19 println!("cargo:rustc-link-lib=re2");
46 if let Some(ref source) = &re2 {
47 // Link the local source statically
48 println!(
49 "cargo:rustc-link-search=native={}",
50 Path::new(source).join(Path::new("obj")).display()
51 );
52 println!("cargo:rustc-link-lib=static=re2");
53 } else {
54 println!("cargo:rustc-link-lib=re2");
55 }
20 }
56 }
21
57
22 fn main() {
58 fn main() {
23 #[cfg(feature = "with-re2")]
59 #[cfg(feature = "with-re2")]
24 compile_re2();
60 compile_re2();
25 }
61 }
General Comments 0
You need to be logged in to leave comments. Login now