blob: 51cef31a87289aca0d4384e722e57c1c3ae7abd2 [file] [log] [blame]
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Minijail's build script invoked by cargo.
/// This script prefers linking against a pkg-config provided libminijail, but will fall back to
/// building libminijail statically.
use std::env;
use std::io;
use std::process::Command;
fn main() -> io::Result<()> {
// Minijail requires libcap at runtime.
// Prefer a system-provided Minijail library.
if pkg_config::Config::new().probe("libminijail").is_ok() {
return Ok(());
let current_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let profile = env::var("PROFILE").unwrap();
let status = Command::new("make")
.env("OUT", &out_dir)
.env("MODE", if profile == "release" { "opt" } else { "debug" })
if !status.success() {
println!("cargo:rustc-link-search=native={}", &out_dir);