|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +use std::env; |
| 6 | +use std::fs::canonicalize; |
| 7 | +use std::path::Path; |
| 8 | +use std::process::Command; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + // uncomment to print all env vars |
| 12 | + for (k, v) in std::env::vars() { |
| 13 | + println!("{} -> {}", k, v); |
| 14 | + } |
| 15 | + |
| 16 | + let out_dir = env::var("OUT_DIR").unwrap(); |
| 17 | + |
| 18 | + // /Users/nalexander/Mozilla/application-services/target/debug/build/logins_ffi-d0290628a891f004/out |
| 19 | + let target = Path::new(&out_dir).ancestors().find(|p| p.ends_with("target")).unwrap(); |
| 20 | + |
| 21 | + // path.ends_with("passwd")); |
| 22 | + |
| 23 | + // run the build scripts from the lib dir. |
| 24 | + let libs_dir = |
| 25 | + canonicalize(target.join("..").join("build").join("libs")).unwrap(); |
| 26 | + |
| 27 | + // canonicalize(Path::new(".").join("build").join("libs")).unwrap(); |
| 28 | + // canonicalize(Path::new(".").join("..").join("..").join("..").join("build").join("libs")).unwrap(); |
| 29 | + |
| 30 | + let target_os = env::var("CARGO_CFG_TARGET_OS"); |
| 31 | + let build_info = match target_os.as_ref().map(|x| &**x) { |
| 32 | + Ok("linux") => Some(("desktop", "linux-x86-64")), |
| 33 | + Ok("windows") => Some(("desktop", "win32-x86-64")), |
| 34 | + Ok("macos") => Some(("desktop", "darwin")), |
| 35 | + // Ok("android") => Some("android"), - TODO - need to do better at x-compile support. |
| 36 | + _ => None, |
| 37 | + }; |
| 38 | + match build_info { |
| 39 | + None => println!( |
| 40 | + "Unknown target OS '{:?}' - not executing external build script", |
| 41 | + target_os |
| 42 | + ), |
| 43 | + Some((build_platform, target_dir)) => { |
| 44 | + // let status = Command::new("sh") |
| 45 | + // .args(&["-c", &format!("./build-all.sh {}", build_platform)]) |
| 46 | + // .current_dir(libs_dir.as_os_str()) |
| 47 | + // .status() |
| 48 | + // .unwrap(); |
| 49 | + // if !status.success() { |
| 50 | + // panic!("external build script failed: {:?}", status); |
| 51 | + // } |
| 52 | + // println!("external build script succeeded"); |
| 53 | + |
| 54 | + println!("cargo:rustc-env=OPENSSL_STATIC=1"); |
| 55 | + |
| 56 | + let openssl = libs_dir |
| 57 | + .join(build_platform) |
| 58 | + .join(target_dir) |
| 59 | + .join("openssl"); |
| 60 | + println!("cargo:rustc-env=OPENSSL_DIR={}", openssl.to_str().unwrap()); |
| 61 | + |
| 62 | + let sqlcipher = libs_dir |
| 63 | + .join(build_platform) |
| 64 | + .join(target_dir) |
| 65 | + .join("sqlcipher"); |
| 66 | + println!("cargo:rustc-env=SQLCIPHER_LIB_DIR={}", sqlcipher.join("lib").to_str().unwrap()); |
| 67 | + println!("cargo:rustc-env=SQLCIPHER_INCLUDE_DIR={}", sqlcipher.join("include").to_str().unwrap()); |
| 68 | + |
| 69 | + // // point at the libraries |
| 70 | + // let openssl = libs_dir |
| 71 | + // .join(build_platform) |
| 72 | + // .join(target_dir) |
| 73 | + // .join("openssl") |
| 74 | + // .join("lib"); |
| 75 | + // println!( |
| 76 | + // "cargo:rustc-link-search=native={}", |
| 77 | + // openssl.to_str().unwrap() |
| 78 | + // ); |
| 79 | + |
| 80 | + // let sqlcipher = libs_dir |
| 81 | + // .join(build_platform) |
| 82 | + // .join(target_dir) |
| 83 | + // .join("sqlcipher") |
| 84 | + // .join("lib"); |
| 85 | + // println!( |
| 86 | + // "cargo:rustc-link-search=native={}", |
| 87 | + // sqlcipher.to_str().unwrap() |
| 88 | + // ); |
| 89 | + } |
| 90 | + }; |
| 91 | +} |
0 commit comments