| 1 |
// SPDX-License-Identifier: Apache-2.0 |
| 2 |
|
| 3 |
//! Finds `libclang` static or shared libraries and links to them. |
| 4 |
//! |
| 5 |
//! # Environment Variables |
| 6 |
//! |
| 7 |
//! This build script can make use of several environment variables to help it |
| 8 |
//! find the required static or shared libraries. |
| 9 |
//! |
| 10 |
//! * `LLVM_CONFIG_PATH` - provides a path to an `llvm-config` executable |
| 11 |
//! * `LIBCLANG_PATH` - provides a path to a directory containing a `libclang` |
| 12 |
//! shared library or a path to a specific `libclang` shared library |
| 13 |
//! * `LIBCLANG_STATIC_PATH` - provides a path to a directory containing LLVM |
| 14 |
//! and Clang static libraries |
| 15 |
|
| 16 |
#![allow(unused_attributes)] |
| 17 |
|
| 18 |
use std::path::Path; |
| 19 |
|
| 20 |
#[macro_use] |
| 21 |
#[path = "build/macros.rs"] |
| 22 |
pub mod macros; |
| 23 |
|
| 24 |
#[path = "build/common.rs"] |
| 25 |
pub mod common; |
| 26 |
#[path = "build/dynamic.rs"] |
| 27 |
pub mod dynamic; |
| 28 |
#[path = "build/static.rs"] |
| 29 |
pub mod r#static; |
| 30 |
|
| 31 |
/// Copies the code used to find and link to `libclang` shared libraries into |
| 32 |
/// the build output directory so that it may be used when linking at runtime. |
| 33 |
#[cfg(feature = "runtime")] |
| 34 |
fn main() { |
| 35 |
if cfg!(feature = "static") { |
| 36 |
panic!("`runtime` and `static` features can't be combined"); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/// Finds and links to the required libraries dynamically or statically. |
| 41 |
#[cfg(not(feature = "runtime"))] |
| 42 |
fn main() { |
| 43 |
if cfg!(feature = "static") { |
| 44 |
r#static::link(); |
| 45 |
} else { |
| 46 |
dynamic::link(); |
| 47 |
} |
| 48 |
|
| 49 |
if let Some(output) = common::run_llvm_config(&["--includedir"]) { |
| 50 |
let directory = Path::new(output.trim_end()); |
| 51 |
println!("cargo:include={}", directory.display()); |
| 52 |
} |
| 53 |
} |