1 // Copyright 2019 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 /// Minijail's build script invoked by cargo. 6 /// 7 /// This script prefers linking against a pkg-config provided libminijail, but will fall back to 8 /// building libminijail statically. 9 use std::env; 10 use std::io; 11 use std::process::Command; 12 main() -> io::Result<()>13fn main() -> io::Result<()> { 14 // Minijail requires libcap at runtime. 15 pkg_config::Config::new().probe("libcap").unwrap(); 16 17 // Prefer a system-provided Minijail library. 18 if pkg_config::Config::new().probe("libminijail").is_ok() { 19 return Ok(()); 20 } 21 22 let current_dir = env::var("CARGO_MANIFEST_DIR").unwrap() + "/../.."; 23 let out_dir = env::var("OUT_DIR").unwrap(); 24 let profile = env::var("PROFILE").unwrap(); 25 26 let status = Command::new("make") 27 .current_dir(&out_dir) 28 .env("OUT", &out_dir) 29 .env("MODE", if profile == "release" { "opt" } else { "debug" }) 30 .arg("-C") 31 .arg(¤t_dir) 32 .arg("CC_STATIC_LIBRARY(libminijail.pic.a)") 33 .status()?; 34 if !status.success() { 35 std::process::exit(status.code().unwrap_or(1)); 36 } 37 println!("cargo:rustc-link-search=native={}", &out_dir); 38 println!("cargo:rustc-link-lib=static=minijail.pic"); 39 Ok(()) 40 } 41