1
1
use glob:: glob;
2
2
use std:: env;
3
3
use std:: ffi:: OsString ;
4
- use std:: fs:: { self , OpenOptions } ;
5
- use std:: io:: { self , Write } ;
4
+ use std:: fs;
5
+ use std:: io;
6
6
use std:: path:: { Path , PathBuf } ;
7
7
use std:: process:: Command ;
8
8
@@ -29,7 +29,7 @@ fn main() {
29
29
30
30
if std:: env:: var ( "LIBSQL_DEV" ) . is_ok ( ) {
31
31
make_amalgamation ( ) ;
32
- build_multiple_ciphers ( & target , & out_path) ;
32
+ build_multiple_ciphers ( & out_path) ;
33
33
}
34
34
35
35
let bindgen_rs_path = if cfg ! ( feature = "session" ) {
@@ -50,7 +50,7 @@ fn main() {
50
50
}
51
51
52
52
if cfg ! ( feature = "multiple-ciphers" ) {
53
- copy_multiple_ciphers ( & target , & out_dir, & out_path) ;
53
+ copy_multiple_ciphers ( & out_dir, & out_path) ;
54
54
return ;
55
55
}
56
56
@@ -409,18 +409,19 @@ pub fn build_bundled(out_dir: &str, out_path: &Path) {
409
409
println ! ( "cargo:lib_dir={out_dir}" ) ;
410
410
}
411
411
412
- fn copy_multiple_ciphers ( target : & str , out_dir : & str , out_path : & Path ) {
413
- let dylib = format ! ( "{out_dir}/sqlite3mc/libsqlite3mc_static.a" ) ;
414
- if !Path :: new ( & dylib) . exists ( ) {
415
- build_multiple_ciphers ( target, out_path) ;
416
- }
412
+ fn copy_multiple_ciphers ( out_dir : & str , out_path : & Path ) {
413
+ let dst = dbg ! ( build_multiple_ciphers( out_path) ) ;
417
414
418
- copy_with_cp ( dylib, format ! ( "{out_dir}/libsqlite3mc.a" ) ) . unwrap ( ) ;
415
+ copy_with_cp (
416
+ dbg ! ( dst. join( "build" ) . join( "libsqlite3mc_static.a" ) ) ,
417
+ dbg ! ( format!( "{out_dir}/libsqlite3mc.a" ) ) ,
418
+ )
419
+ . unwrap ( ) ;
419
420
println ! ( "cargo:rustc-link-lib=static=sqlite3mc" ) ;
420
421
println ! ( "cargo:rustc-link-search={out_dir}" ) ;
421
422
}
422
423
423
- fn build_multiple_ciphers ( target : & str , out_path : & Path ) {
424
+ fn build_multiple_ciphers ( out_path : & Path ) -> PathBuf {
424
425
let bindgen_rs_path = if cfg ! ( feature = "session" ) {
425
426
"bundled/bindings/session_bindgen.rs"
426
427
} else {
@@ -450,112 +451,33 @@ fn build_multiple_ciphers(target: &str, out_path: &Path) {
450
451
. unwrap ( ) ;
451
452
452
453
let bundled_dir = format ! ( "{out_dir}/sqlite3mc" ) ;
453
- let sqlite3mc_build_dir = env:: current_dir ( ) . unwrap ( ) . join ( out_dir) . join ( "sqlite3mc" ) ;
454
-
455
- let mut cmake_opts: Vec < & str > = vec ! [ ] ;
456
-
457
- let target_postfix = target. to_string ( ) . replace ( "-" , "_" ) ;
458
- let cross_cc_var_name = format ! ( "CC_{}" , target_postfix) ;
459
- println ! ( "cargo:warning=CC_var_name={}" , cross_cc_var_name) ;
460
- let cross_cc = env:: var ( & cross_cc_var_name) . ok ( ) ;
461
-
462
- let cross_cxx_var_name = format ! ( "CXX_{}" , target_postfix) ;
463
- let cross_cxx = env:: var ( & cross_cxx_var_name) . ok ( ) ;
464
-
465
- let toolchain_path = sqlite3mc_build_dir. join ( "toolchain.cmake" ) ;
466
- let cmake_toolchain_opt = "-DCMAKE_TOOLCHAIN_FILE=toolchain.cmake" . to_string ( ) ;
467
-
468
- let mut toolchain_file = OpenOptions :: new ( )
469
- . create ( true )
470
- . write ( true )
471
- . append ( true )
472
- . open ( toolchain_path. clone ( ) )
473
- . unwrap ( ) ;
474
-
475
- if let Some ( ref cc) = cross_cc {
476
- let system_name = if cc. contains ( "linux" ) {
477
- "Linux"
478
- } else if cc. contains ( "darwin" ) {
479
- "Darwin"
480
- } else if cc. contains ( "w64" ) {
481
- "Windows"
482
- } else {
483
- panic ! ( "Unsupported cross target {}" , cc)
484
- } ;
485
454
486
- let system_processor = if cc. contains ( "x86_64" ) {
487
- "x86_64"
488
- } else if cc. contains ( "aarch64" ) {
489
- "arm64"
490
- } else if cc. contains ( "arm" ) {
491
- "arm"
492
- } else {
493
- panic ! ( "Unsupported cross target {}" , cc)
494
- } ;
495
-
496
- cmake_opts. push ( & cmake_toolchain_opt) ;
497
- writeln ! ( toolchain_file, "set(CMAKE_SYSTEM_NAME \" {}\" )" , system_name) . unwrap ( ) ;
498
- writeln ! (
499
- toolchain_file,
500
- "set(CMAKE_SYSTEM_PROCESSOR \" {}\" )" ,
501
- system_processor
502
- )
503
- . unwrap ( ) ;
504
- writeln ! ( toolchain_file, "set(CMAKE_C_COMPILER {})" , cc) . unwrap ( ) ;
505
- }
506
-
507
- if let Some ( cxx) = cross_cxx {
508
- writeln ! ( toolchain_file, "set(CMAKE_CXX_COMPILER {})" , cxx) . unwrap ( ) ;
509
- }
455
+ let mut config = cmake:: Config :: new ( & bundled_dir) ;
456
+
457
+ config
458
+ . define ( "CMAKE_BUILD_TYPE" , "Release" )
459
+ . define ( "SQLITE3MC_STATIC" , "ON" )
460
+ . define ( "CODEC_TYPE" , "AES256" )
461
+ . define ( "SQLITE3MC_BUILD_SHELL" , "OFF" )
462
+ . define ( "SQLITE_SHELL_IS_UTF8" , "OFF" )
463
+ . define ( "SQLITE_USER_AUTHENTICATION" , "OFF" )
464
+ . define ( "SQLITE_SECURE_DELETE" , "OFF" )
465
+ . define ( "SQLITE_ENABLE_COLUMN_METADATA" , "ON" )
466
+ . define ( "SQLITE_USE_URI" , "ON" )
467
+ . define ( "CMAKE_POSITION_INDEPENDENT_CODE" , "ON" )
468
+ . define ( "CMAKE_BUILD_TYPE" , "Release" ) ;
510
469
511
- cmake_opts. push ( "-DCMAKE_BUILD_TYPE=Release" ) ;
512
- cmake_opts. push ( "-DSQLITE3MC_STATIC=ON" ) ;
513
- cmake_opts. push ( "-DCODEC_TYPE=AES256" ) ;
514
- cmake_opts. push ( "-DSQLITE3MC_BUILD_SHELL=OFF" ) ;
515
- cmake_opts. push ( "-DSQLITE_SHELL_IS_UTF8=OFF" ) ;
516
- cmake_opts. push ( "-DSQLITE_USER_AUTHENTICATION=OFF" ) ;
517
- cmake_opts. push ( "-DSQLITE_SECURE_DELETE=OFF" ) ;
518
- cmake_opts. push ( "-DSQLITE_ENABLE_COLUMN_METADATA=ON" ) ;
519
- cmake_opts. push ( "-DSQLITE_USE_URI=ON" ) ;
520
- cmake_opts. push ( "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ) ;
521
-
522
- if target. contains ( "musl" ) {
523
- cmake_opts. push ( "-DCMAKE_C_FLAGS=\" -U_FORTIFY_SOURCE\" -D_FILE_OFFSET_BITS=32" ) ;
524
- cmake_opts. push ( "-DCMAKE_CXX_FLAGS=\" -U_FORTIFY_SOURCE\" -D_FILE_OFFSET_BITS=32" ) ;
525
- }
526
-
527
- let mut cmake = Command :: new ( "cmake" ) ;
528
- cmake. current_dir ( sqlite3mc_build_dir. clone ( ) ) ;
529
- cmake. args ( cmake_opts. clone ( ) ) ;
530
- cmake. arg ( bundled_dir. clone ( ) ) ;
531
470
if cfg ! ( feature = "wasmtime-bindings" ) {
532
- cmake . arg ( "-DLIBSQL_ENABLE_WASM_RUNTIME= 1") ;
471
+ config . define ( "LIBSQL_ENABLE_WASM_RUNTIME" , " 1") ;
533
472
}
473
+
534
474
if cfg ! ( feature = "session" ) {
535
- cmake. arg ( "-DSQLITE_ENABLE_PREUPDATE_HOOK=ON" ) ;
536
- cmake. arg ( "-DSQLITE_ENABLE_SESSION=ON" ) ;
537
- }
538
- println ! ( "Running `cmake` with options: {}" , cmake_opts. join( " " ) ) ;
539
- let status = cmake. status ( ) . unwrap ( ) ;
540
- if !status. success ( ) {
541
- panic ! ( "Failed to run cmake with options: {}" , cmake_opts. join( " " ) ) ;
542
- }
543
-
544
- let mut make = Command :: new ( "cmake" ) ;
545
- make. current_dir ( sqlite3mc_build_dir. clone ( ) ) ;
546
- make. args ( [ "--build" , "." ] ) ;
547
- make. args ( [ "--config" , "Release" ] ) ;
548
- if !make. status ( ) . unwrap ( ) . success ( ) {
549
- panic ! ( "Failed to run make" ) ;
550
- }
551
- // The `msbuild` tool puts the output in a different place so let's move it.
552
- if Path :: exists ( & sqlite3mc_build_dir. join ( "Release/sqlite3mc_static.lib" ) ) {
553
- fs:: rename (
554
- sqlite3mc_build_dir. join ( "Release/sqlite3mc_static.lib" ) ,
555
- sqlite3mc_build_dir. join ( "libsqlite3mc_static.a" ) ,
556
- )
557
- . unwrap ( ) ;
475
+ config
476
+ . define ( "SQLITE_ENABLE_PREUPDATE_HOOK" , "ON" )
477
+ . define ( "SQLITE_ENABLE_SESSION" , "ON" ) ;
558
478
}
479
+
480
+ config. build ( )
559
481
}
560
482
561
483
fn env ( name : & str ) -> Option < OsString > {
0 commit comments