Skip to content

Commit

Permalink
WIP on using a build.rs to avoid having Gradle set environment variab…
Browse files Browse the repository at this point in the history
…les.

This DOES NOT WORK.  What's needed is a solution for rust-lang/cargo#4121.
  • Loading branch information
ncalexan committed Jan 2, 2019
1 parent 1fa9ec9 commit f291aa2
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
91 changes: 91 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::env;
use std::fs::canonicalize;
use std::path::Path;
use std::process::Command;

fn main() {
// uncomment to print all env vars
for (k, v) in std::env::vars() {
println!("{} -> {}", k, v);
}

let out_dir = env::var("OUT_DIR").unwrap();

// /Users/nalexander/Mozilla/application-services/target/debug/build/logins_ffi-d0290628a891f004/out
let target = Path::new(&out_dir).ancestors().find(|p| p.ends_with("target")).unwrap();

// path.ends_with("passwd"));

// run the build scripts from the lib dir.
let libs_dir =
canonicalize(target.join("..").join("build").join("libs")).unwrap();

// canonicalize(Path::new(".").join("build").join("libs")).unwrap();
// canonicalize(Path::new(".").join("..").join("..").join("..").join("build").join("libs")).unwrap();

let target_os = env::var("CARGO_CFG_TARGET_OS");
let build_info = match target_os.as_ref().map(|x| &**x) {
Ok("linux") => Some(("desktop", "linux-x86-64")),
Ok("windows") => Some(("desktop", "win32-x86-64")),
Ok("macos") => Some(("desktop", "darwin")),
// Ok("android") => Some("android"), - TODO - need to do better at x-compile support.
_ => None,
};
match build_info {
None => println!(
"Unknown target OS '{:?}' - not executing external build script",
target_os
),
Some((build_platform, target_dir)) => {
// let status = Command::new("sh")
// .args(&["-c", &format!("./build-all.sh {}", build_platform)])
// .current_dir(libs_dir.as_os_str())
// .status()
// .unwrap();
// if !status.success() {
// panic!("external build script failed: {:?}", status);
// }
// println!("external build script succeeded");

println!("cargo:rustc-env=OPENSSL_STATIC=1");

let openssl = libs_dir
.join(build_platform)
.join(target_dir)
.join("openssl");
println!("cargo:rustc-env=OPENSSL_DIR={}", openssl.to_str().unwrap());

let sqlcipher = libs_dir
.join(build_platform)
.join(target_dir)
.join("sqlcipher");
println!("cargo:rustc-env=SQLCIPHER_LIB_DIR={}", sqlcipher.join("lib").to_str().unwrap());
println!("cargo:rustc-env=SQLCIPHER_INCLUDE_DIR={}", sqlcipher.join("include").to_str().unwrap());

// // point at the libraries
// let openssl = libs_dir
// .join(build_platform)
// .join(target_dir)
// .join("openssl")
// .join("lib");
// println!(
// "cargo:rustc-link-search=native={}",
// openssl.to_str().unwrap()
// );

// let sqlcipher = libs_dir
// .join(build_platform)
// .join(target_dir)
// .join("sqlcipher")
// .join("lib");
// println!(
// "cargo:rustc-link-search=native={}",
// sqlcipher.to_str().unwrap()
// );
}
};
}
1 change: 1 addition & 0 deletions components/logins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "logins"
edition = "2018"
version = "0.1.0"
authors = ["Thom Chiovoloni <tchiovoloni@mozilla.com>"]
build = "../../build.rs"

[features]
ffi = ["ffi-support"]
Expand Down
1 change: 1 addition & 0 deletions components/logins/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "logins_ffi"
edition = "2018"
version = "0.1.0"
authors = ["Thom Chiovoloni <tchiovoloni@mozilla.com>"]
build = "../../../build.rs"

[lib]
name = "logins_ffi"
Expand Down
1 change: 1 addition & 0 deletions components/places/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "places"
edition = "2018"
version = "0.1.0"
authors = []
build = "../../build.rs"

[features]
ffi = ["ffi-support"]
Expand Down
1 change: 1 addition & 0 deletions components/places/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "places-ffi"
edition = "2018"
version = "0.1.0"
authors = ["Thom Chiovoloni <tchiovoloni@mozilla.com>"]
build = "../../../build.rs"

[lib]
name = "places_ffi"
Expand Down
1 change: 1 addition & 0 deletions components/support/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "sql-support"
edition = "2018"
version = "0.1.0"
authors = ["Thom Chiovoloni <tchiovoloni@mozilla.com>"]
build = "../../../build.rs"

[features]
default = ["sqlcipher"]
Expand Down

0 comments on commit f291aa2

Please sign in to comment.