1
1
use bindgen:: { Builder , RustTarget } ;
2
2
use std:: {
3
- env, fs ,
3
+ env,
4
4
io:: { Read , Write } ,
5
5
path:: { Path , PathBuf } ,
6
6
process:: Stdio ,
@@ -11,69 +11,51 @@ fn main() {
11
11
let dst = cmake:: Config :: new ( Path :: new ( "couchbase-lite-core" ) )
12
12
. define ( "DISABLE_LTO_BUILD" , "True" )
13
13
. define ( "SANITIZE_FOR_DEBUG_ENABLED" , "False" )
14
- . build_target ( "LiteCore" )
14
+ . define ( "ENABLE_TESTING" , "False" )
15
+ . define ( "LITECORE_BUILD_TESTS" , "False" )
16
+ . build_target ( "all" )
15
17
. build ( )
16
18
. join ( "build" ) ;
17
19
18
- let out_dir = getenv_unwrap ( "OUT_DIR" ) ;
19
- let out_dir = Path :: new ( & out_dir) ;
20
-
21
- let lib_name = if cfg ! ( target_os = "windows" ) {
22
- "LiteCore.dll"
23
- } else if cfg ! ( target_os = "macos" ) || cfg ! ( target_os = "ios" ) {
24
- "libLiteCore.dylib"
25
- } else {
26
- "libLiteCore.so"
27
- } ;
28
- // so it is possible to use from project that uses Rust library,
29
- // but not on Rust language
30
- let target_dir = target_directory ( out_dir) ;
20
+ println ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ;
21
+ println ! (
22
+ "cargo:rustc-link-search=native={}" ,
23
+ dst. join( "vendor" ) . join( "fleece" ) . display( )
24
+ ) ;
25
+ println ! (
26
+ "cargo:rustc-link-search=native={}" ,
27
+ dst. join( "Networking" ) . join( "BLIP" ) . display( )
28
+ ) ;
29
+ println ! (
30
+ "cargo:rustc-link-search=native={}" ,
31
+ dst. join( "vendor" ) . join( "sqlite3-unicodesn" ) . display( )
32
+ ) ;
33
+ println ! (
34
+ "cargo:rustc-link-search=native={}" ,
35
+ dst. join( "vendor" )
36
+ . join( "mbedtls" )
37
+ . join( "crypto" )
38
+ . join( "library" )
39
+ . display( )
40
+ ) ;
41
+ println ! ( "cargo:rustc-link-lib=static=FleeceStatic" ) ;
42
+ println ! ( "cargo:rustc-link-lib=static=LiteCoreStatic" ) ;
43
+ println ! ( "cargo:rustc-link-lib=static=SQLite3_UnicodeSN" ) ;
44
+ println ! ( "cargo:rustc-link-lib=static=BLIPStatic" ) ;
45
+ println ! ( "cargo:rustc-link-lib=static=Support" ) ;
46
+ println ! ( "cargo:rustc-link-lib=static=mbedcrypto" ) ;
31
47
32
- if cfg ! ( target_os = "windows" ) {
33
- let msvc_cmake_profile = match & getenv_unwrap ( "PROFILE" ) [ ..] {
34
- "debug" => "Debug" ,
35
- "release" | "bench" => "Release" ,
36
- unknown => {
37
- eprintln ! (
38
- "Warning: unknown Rust profile={}; defaulting to a release build." ,
39
- unknown
40
- ) ;
41
- "Release"
42
- }
43
- } ;
44
- let dst = dst. join ( msvc_cmake_profile) ;
45
- if let Err ( err) = fs:: copy ( dst. join ( lib_name) , target_dir. join ( lib_name) ) {
46
- panic ! (
47
- "copy {} from '{}' to '{}' faied: {}" ,
48
- lib_name,
49
- dst. display( ) ,
50
- target_dir. display( ) ,
51
- err
52
- ) ;
53
- }
54
- let lib_lib_name = "LiteCore.lib" ;
55
- if let Err ( err) = fs:: copy ( dst. join ( lib_lib_name) , target_dir. join ( lib_lib_name) ) {
56
- panic ! (
57
- "copy {} from '{}' to '{}' faied: {}" ,
58
- lib_lib_name,
59
- dst. display( ) ,
60
- target_dir. display( ) ,
61
- err
62
- ) ;
63
- }
64
- } else {
65
- if let Err ( err) = fs:: copy ( dst. join ( lib_name) , target_dir. join ( lib_name) ) {
66
- panic ! (
67
- "copy {} from '{}' to '{}' faied: {}" ,
68
- lib_name,
69
- dst. display( ) ,
70
- target_dir. display( ) ,
71
- err
72
- ) ;
73
- }
48
+ if cfg ! ( target_os = "linux" ) {
49
+ println ! ( "cargo:rustc-link-lib=icuuc" ) ;
50
+ println ! ( "cargo:rustc-link-lib=icui18n" ) ;
51
+ println ! ( "cargo:rustc-link-lib=icudata" ) ;
52
+ println ! ( "cargo:rustc-link-lib=z" ) ;
53
+ } else if cfg ! ( target_os = "macos" ) {
54
+ println ! ( "cargo:rustc-link-lib=z" ) ;
55
+ //TODO: remove this dependicies
56
+ println ! ( "cargo:rustc-link-lib=framework=CoreFoundation" ) ;
57
+ println ! ( "cargo:rustc-link-lib=framework=Foundation" ) ;
74
58
}
75
- println ! ( "cargo:rustc-link-search=native={}" , target_dir. display( ) ) ;
76
- println ! ( "cargo:rustc-link-lib=dylib=LiteCore" ) ;
77
59
78
60
let mut includes = vec ! [
79
61
Path :: new( "couchbase-lite-core" ) . join( "C" ) . join( "include" ) ,
@@ -92,6 +74,9 @@ fn main() {
92
74
includes. append ( & mut addon_include_dirs) ;
93
75
framework_dirs. append ( & mut addon_framework_dirs) ;
94
76
77
+ let out_dir = getenv_unwrap ( "OUT_DIR" ) ;
78
+ let out_dir = Path :: new ( & out_dir) ;
79
+
95
80
run_bindgen_for_c_headers (
96
81
& target,
97
82
& includes,
@@ -120,18 +105,6 @@ fn main() {
120
105
. compile ( "couch_lite_log_retrans" ) ;
121
106
}
122
107
123
- /// Convert something like
124
- /// project/target/release/build/lib-couchbase-lite-core-sys-9daa760ee41fe7b8/out
125
- /// to
126
- /// project/target/release
127
- /// Waiting https://github.com/rust-lang/cargo/issues/5457 for proper mechanizm
128
- fn target_directory ( out_dir : & Path ) -> & Path {
129
- out_dir
130
- . ancestors ( )
131
- . nth ( 3 )
132
- . expect ( "Can not find ancestor during cargo_target_dir search" )
133
- }
134
-
135
108
fn run_bindgen_for_c_headers < P : AsRef < Path > > (
136
109
target : & str ,
137
110
include_dirs : & [ P ] ,
0 commit comments