| 1 | // SPDX-License-Identifier: Apache-2.0 or MIT |
| 2 | // |
| 3 | // Copyright 2021 Sony Group Corporation |
| 4 | // |
| 5 | |
| 6 | use std::env; |
| 7 | |
| 8 | const LIBSECCOMP_LIB_PATH: &str = "LIBSECCOMP_LIB_PATH"; |
| 9 | const LIBSECCOMP_LINK_TYPE: &str = "LIBSECCOMP_LINK_TYPE"; |
| 10 | |
| 11 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 12 | println!("cargo:rerun-if-env-changed={}", LIBSECCOMP_LIB_PATH); |
| 13 | println!("cargo:rerun-if-env-changed={}", LIBSECCOMP_LINK_TYPE); |
| 14 | |
| 15 | if let Ok(path) = env::var(LIBSECCOMP_LIB_PATH) { |
| 16 | println!("cargo:rustc-link-search=native={}", path); |
| 17 | } |
| 18 | |
| 19 | let link_type = match env::var(LIBSECCOMP_LINK_TYPE) { |
| 20 | Ok(link_type) if link_type == "framework" => { |
| 21 | return Err("Seccomp is a Linux specific technology".into()); |
| 22 | } |
| 23 | Ok(link_type) => link_type, // static or dylib |
| 24 | Err(_) => String::from("dylib"), |
| 25 | }; |
| 26 | |
| 27 | println!("cargo:rustc-link-lib={}=seccomp", link_type); |
| 28 | |
| 29 | Ok(()) |
| 30 | } |