diff options
author | Haibo Huang <hhb@google.com> | 2020-07-21 01:24:22 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-21 01:24:22 +0000 |
commit | e17ad99574683b7ccc6d339c85aa59eb37c0d5f1 (patch) | |
tree | 0e75529df5e4b36b3fbd499db54bc78fb46826e5 | |
parent | c0af8165b6bbad12354080a427a9d4b316c0f772 (diff) | |
parent | 2ddb5c754924b331b76e16534acedf50bc99bb1f (diff) | |
download | clang-sys-e17ad99574683b7ccc6d339c85aa59eb37c0d5f1.tar.gz |
Upgrade rust/crates/clang-sys to 1.0.0 am: 8b9513ee47 am: b9748b3dce am: b076b4149a am: dbb1b8f06c am: 2ddb5c7549
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/clang-sys/+/1361691
Change-Id: I95d7672445f1666e8d87b582c9af380b73a520cb
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 57 | ||||
-rw-r--r-- | .travis.yml | 28 | ||||
-rw-r--r-- | Android.bp | 26 | ||||
-rw-r--r-- | CHANGELOG.md | 13 | ||||
-rw-r--r-- | Cargo.toml | 37 | ||||
-rw-r--r-- | Cargo.toml.orig | 38 | ||||
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | appveyor.yml | 12 | ||||
-rw-r--r-- | build/common.rs | 85 | ||||
-rw-r--r-- | build/dynamic.rs | 4 | ||||
-rw-r--r-- | build/static.rs | 6 | ||||
-rw-r--r-- | ci/before_install.sh | 57 | ||||
-rw-r--r-- | ci/install.bat | 8 | ||||
-rw-r--r-- | ci/script.sh | 13 | ||||
-rw-r--r-- | ci/test_script.bat | 2 | ||||
-rw-r--r-- | docs.py | 2 | ||||
-rw-r--r-- | out/common.rs | 85 | ||||
-rw-r--r-- | out/dynamic.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 219 | ||||
-rw-r--r-- | src/link.rs | 9 | ||||
-rw-r--r-- | src/support.rs | 2 |
23 files changed, 383 insertions, 339 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4fa2e6b..4d0697a 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "4d0ce68f60cb9d9ce6c1e0f1794af7b1a5671bee" + "sha1": "f40ed4703128a5b77bbbbf7863b577585b7d5896" } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..75775cd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + ci: + name: CI + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + clang: [["10.0", "clang_10_0"]] + rust: ["1.36.0"] + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + # LLVM and Clang + - name: Cache LLVM and Clang + id: cache-llvm + uses: actions/cache@v2 + with: + path: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }} + key: ${{ matrix.os }}-llvm-${{ matrix.clang[0] }} + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + with: + version: ${{ matrix.clang[0] }} + directory: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }} + cached: ${{ steps.cache-llvm.outputs.cache-hit }} + # Rust + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + # Test + - name: Cargo Test (Dynamic) + uses: actions-rs/cargo@v1 + env: + LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }}/lib + LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }}/bin/llvm-config + with: + command: test + args: --verbose --features ${{ matrix.clang[1] }} -- --nocapture + - name: Cargo Test (Runtime) + uses: actions-rs/cargo@v1 + env: + LIBCLANG_PATH: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }}/lib + LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm-${{ matrix.clang[0] }}/bin/llvm-config + with: + command: test + args: --verbose --features "${{ matrix.clang[1] }} runtime" -- --nocapture diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fef4737..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: rust - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc-5 - -os: - - linux - -rust: - - 1.36.0 - - stable - -env: - - LLVM_VERSION=3.5 CLANG_VERSION=clang_3_5 - - LLVM_VERSION=7.0 CLANG_VERSION=clang_7_0 - -cache: - directories: - - $HOME/.cargo - - $HOME/.llvm - -before_install: . ./ci/before_install.sh - -script: . ./ci/script.sh @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --features=runtime,clang_9_0 --dependencies. +// This file is generated by cargo2android.py --run --features=runtime,clang_10_0 --dependencies. rust_library_host { name: "libclang_sys", @@ -7,17 +7,18 @@ rust_library_host { srcs: ["src/lib.rs"], edition: "2015", features: [ + "clang_10_0", + "clang_3_5", + "clang_3_6", + "clang_3_7", + "clang_3_8", + "clang_3_9", + "clang_4_0", + "clang_5_0", + "clang_6_0", + "clang_7_0", + "clang_8_0", "clang_9_0", - "gte_clang_3_6", - "gte_clang_3_7", - "gte_clang_3_8", - "gte_clang_3_9", - "gte_clang_4_0", - "gte_clang_5_0", - "gte_clang_6_0", - "gte_clang_7_0", - "gte_clang_8_0", - "gte_clang_9_0", "libloading", "runtime", ], @@ -29,7 +30,6 @@ rust_library_host { } // dependent_library ["feature_list"] -// cc-1.0.55 // glob-0.3.0 // libc-0.2.71 -// libloading-0.5.2 +// libloading-0.6.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 32ee34f..23a11a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## [1.0.0] - 2020-07-14 + +### Changed +- Bumped `libloading` version to `0.6.0` +- Updated build script to not print warnings about failures to execute +`llvm-config` and `xcode-select` unless an instance of `libclang` is not found + +### Added +- Added support for `clang` 10.0.x + +### Removed +- Removed `gte_clang_*` Cargo features (these were an implementation detail) + ## [0.29.3] - 2020-03-31 ### Added @@ -12,7 +12,7 @@ [package] name = "clang-sys" -version = "0.29.3" +version = "1.0.0" authors = ["Kyle Mayes <kyle@mayeses.com>"] build = "build.rs" links = "clang" @@ -22,7 +22,7 @@ readme = "README.md" license = "Apache-2.0" repository = "https://github.com/KyleMayes/clang-sys" [package.metadata.docs.rs] -features = ["clang_9_0", "runtime"] +features = ["clang_10_0", "runtime"] [dependencies.glob] version = "0.3" @@ -31,32 +31,23 @@ version = "0.2.39" default-features = false [dependencies.libloading] -version = "0.5" +version = "0.6" optional = true [build-dependencies.glob] version = "0.3" [features] +clang_10_0 = ["clang_9_0"] clang_3_5 = [] -clang_3_6 = ["gte_clang_3_6"] -clang_3_7 = ["gte_clang_3_6", "gte_clang_3_7"] -clang_3_8 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8"] -clang_3_9 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9"] -clang_4_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0"] -clang_5_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0"] -clang_6_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0"] -clang_7_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0"] -clang_8_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0", "gte_clang_8_0"] -clang_9_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0", "gte_clang_8_0", "gte_clang_9_0"] -gte_clang_3_6 = [] -gte_clang_3_7 = [] -gte_clang_3_8 = [] -gte_clang_3_9 = [] -gte_clang_4_0 = [] -gte_clang_5_0 = [] -gte_clang_6_0 = [] -gte_clang_7_0 = [] -gte_clang_8_0 = [] -gte_clang_9_0 = [] +clang_3_6 = ["clang_3_5"] +clang_3_7 = ["clang_3_6"] +clang_3_8 = ["clang_3_7"] +clang_3_9 = ["clang_3_8"] +clang_4_0 = ["clang_3_9"] +clang_5_0 = ["clang_4_0"] +clang_6_0 = ["clang_5_0"] +clang_7_0 = ["clang_6_0"] +clang_8_0 = ["clang_7_0"] +clang_9_0 = ["clang_8_0"] runtime = ["libloading"] static = [] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 5a35957..42a2582 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -3,7 +3,7 @@ name = "clang-sys" authors = ["Kyle Mayes <kyle@mayeses.com>"] -version = "0.29.3" +version = "1.0.0" readme = "README.md" license = "Apache-2.0" @@ -19,27 +19,17 @@ build = "build.rs" [features] clang_3_5 = [] -clang_3_6 = ["gte_clang_3_6"] -clang_3_7 = ["gte_clang_3_6", "gte_clang_3_7"] -clang_3_8 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8"] -clang_3_9 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9"] -clang_4_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0"] -clang_5_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0"] -clang_6_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0"] -clang_7_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0"] -clang_8_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0", "gte_clang_8_0"] -clang_9_0 = ["gte_clang_3_6", "gte_clang_3_7", "gte_clang_3_8", "gte_clang_3_9", "gte_clang_4_0", "gte_clang_5_0", "gte_clang_6_0", "gte_clang_7_0", "gte_clang_8_0", "gte_clang_9_0"] - -gte_clang_3_6 = [] -gte_clang_3_7 = [] -gte_clang_3_8 = [] -gte_clang_3_9 = [] -gte_clang_4_0 = [] -gte_clang_5_0 = [] -gte_clang_6_0 = [] -gte_clang_7_0 = [] -gte_clang_8_0 = [] -gte_clang_9_0 = [] +clang_3_6 = ["clang_3_5"] +clang_3_7 = ["clang_3_6"] +clang_3_8 = ["clang_3_7"] +clang_3_9 = ["clang_3_8"] +clang_4_0 = ["clang_3_9"] +clang_5_0 = ["clang_4_0"] +clang_6_0 = ["clang_5_0"] +clang_7_0 = ["clang_6_0"] +clang_8_0 = ["clang_7_0"] +clang_9_0 = ["clang_8_0"] +clang_10_0 = ["clang_9_0"] runtime = ["libloading"] static = [] @@ -48,7 +38,7 @@ static = [] glob = "0.3" libc = { version = "0.2.39", default-features = false } -libloading = { version = "0.5", optional = true } +libloading = { version = "0.6", optional = true } [build-dependencies] @@ -56,4 +46,4 @@ glob = "0.3" [package.metadata.docs.rs] -features = ["clang_9_0", "runtime"] +features = ["clang_10_0", "runtime"] @@ -9,11 +9,11 @@ third_party { type: GIT value: "https://github.com/KyleMayes/clang-sys" } - version: "0.29.3" + version: "1.0.0" license_type: NOTICE last_upgrade_date { year: 2020 - month: 3 - day: 31 + month: 7 + day: 13 } } @@ -1,8 +1,8 @@ # clang-sys -[![crates.io](https://img.shields.io/crates/v/clang-sys.svg)](https://crates.io/crates/clang-sys) -[![Travis CI](https://travis-ci.org/KyleMayes/clang-sys.svg?branch=master)](https://travis-ci.org/KyleMayes/clang-sys) -[![AppVeyor](https://ci.appveyor.com/api/projects/status/7tv5mjyg55rof356/branch/master?svg=true)](https://ci.appveyor.com/project/KyleMayes/clang-sys-vtvy5/branch/master) +![Crate](https://img.shields.io/crates/v/clang-sys.svg) +![Documentation](https://docs.rs/clang-sys/badge.svg) +![CI](https://github.com/KyleMayes/clang-sys/workflows/CI/badge.svg?branch=master) Rust bindings for `libclang`. @@ -44,6 +44,7 @@ To target a version of `libclang`, enable one of the following Cargo features: * `clang_7_0` - requires `libclang` 7.0 or later * `clang_8_0` - requires `libclang` 8.0 or later * `clang_9_0` - requires `libclang` 9.0 or later +* `clang_10_0` - requires `libclang` 10.0 or later If you do not enable one of these features, the API provided by `libclang` 3.5 will be available by default. diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 060cf73..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,12 +0,0 @@ -environment: - matrix: - - LLVM_VERSION: 7.0.0 - CLANG_VERSION: clang_7_0 - -install: - - .\ci\install.bat - -build: false - -test_script: - - .\ci\test_script.bat diff --git a/build/common.rs b/build/common.rs index 958ef9b..434bd46 100644 --- a/build/common.rs +++ b/build/common.rs @@ -14,6 +14,8 @@ extern crate glob; +use std::cell::RefCell; +use std::collections::HashMap; use std::env; use std::path::{Path, PathBuf}; use std::process::Command; @@ -46,30 +48,38 @@ const DIRECTORIES_WINDOWS: &[&str] = &[ "C:\\MSYS*\\MinGW*\\lib", ]; +thread_local! { + /// The errors encountered when attempting to execute console commands. + static COMMAND_ERRORS: RefCell<HashMap<String, Vec<String>>> = RefCell::default(); +} + /// Executes the supplied console command, returning the `stdout` output if the /// command was successfully executed. -fn run_command(command: &str, arguments: &[&str]) -> Option<String> { - macro_rules! warn { - ($error:expr) => { - println!( - "cargo:warning=couldn't execute `{} {}` ({})", - command, - arguments.join(" "), - $error, - ); - }; +fn run_command(name: &str, command: &str, arguments: &[&str]) -> Option<String> { + macro_rules! error { + ($error:expr) => {{ + COMMAND_ERRORS.with(|e| e.borrow_mut() + .entry(name.into()) + .or_insert_with(Vec::new) + .push(format!( + "couldn't execute `{} {}` ({})", + command, + arguments.join(" "), + $error, + ))); + }}; } let output = match Command::new(command).args(arguments).output() { Ok(output) => output, Err(error) => { - warn!(format!("error: {}", error)); + error!(format!("error: {}", error)); return None; } }; if !output.status.success() { - warn!(format!("exit code: {}", output.status)); + error!(format!("exit code: {}", output.status)); return None; } @@ -80,17 +90,50 @@ fn run_command(command: &str, arguments: &[&str]) -> Option<String> { /// successfully executed. pub fn run_llvm_config(arguments: &[&str]) -> Option<String> { let path = env::var("LLVM_CONFIG_PATH").unwrap_or_else(|_| "llvm-config".into()); + run_command("llvm-config", &path, arguments) +} - let output = run_command(&path, arguments); - if output.is_none() { - println!( - "cargo:warning=set the LLVM_CONFIG_PATH environment variable to \ - the full path to a valid `llvm-config` executable (including the \ - executable itself)" - ); +/// A struct that prints errors encountered when attempting to execute console +/// commands on drop if not discarded. +#[derive(Default)] +pub struct CommandErrorPrinter { + discard: bool +} + +impl CommandErrorPrinter { + pub fn discard(mut self) { + self.discard = true; } +} + +impl Drop for CommandErrorPrinter { + fn drop(&mut self) { + if self.discard { + return; + } + + let errors = COMMAND_ERRORS.with(|e| e.borrow().clone()); + + if let Some(errors) = errors.get("llvm-config") { + println!( + "cargo:warning=could not execute `llvm-config` one or more \ + times, if the LLVM_CONFIG_PATH environment variable is set to \ + a full path to valid `llvm-config` executable it will be used \ + to try to find an instance of `libclang` on your system: {}", + errors.iter().map(|e| format!("\"{}\"", e)).collect::<Vec<_>>().join("\n "), + ) + } - output + if let Some(errors) = errors.get("xcode-select") { + println!( + "cargo:warning=could not execute `xcode-select` one or more \ + times, if a valid instance of this executable is on your PATH \ + it will be used to try to find an instance of `libclang` on \ + your system: {}", + errors.iter().map(|e| format!("\"{}\"", e)).collect::<Vec<_>>().join("\n "), + ) + } + } } /// Returns the paths to and the filenames of the files matching the supplied @@ -179,7 +222,7 @@ pub fn search_libclang_directories(files: &[String], variable: &str) -> Vec<(Pat // Search the toolchain directory in the directory provided by // `xcode-select --print-path`. if cfg!(target_os = "macos") { - if let Some(output) = run_command("xcode-select", &["--print-path"]) { + if let Some(output) = run_command("xcode-select", "xcode-select", &["--print-path"]) { let directory = Path::new(output.lines().next().unwrap()).to_path_buf(); let directory = directory.join("Toolchains/XcodeDefault.xctoolchain/usr/lib"); found.extend(search_directories(&directory, files)); diff --git a/build/dynamic.rs b/build/dynamic.rs index 2054ba0..8a9e5d3 100644 --- a/build/dynamic.rs +++ b/build/dynamic.rs @@ -190,6 +190,8 @@ pub fn find(runtime: bool) -> Result<(PathBuf, String), String> { /// Find and link to `libclang` dynamically. #[cfg(not(feature = "runtime"))] pub fn link() { + let cep = common::CommandErrorPrinter::default(); + use std::fs; let (directory, filename) = find(false).unwrap(); @@ -241,4 +243,6 @@ pub fn link() { println!("cargo:rustc-link-lib=dylib={}", name); } + + cep.discard(); } diff --git a/build/static.rs b/build/static.rs index bacd4ad..83a8185 100644 --- a/build/static.rs +++ b/build/static.rs @@ -90,7 +90,7 @@ fn find() -> PathBuf { }; let files = common::search_libclang_directories(&[name.into()], "LIBCLANG_STATIC_PATH"); - if let Some((directory, _)) = files.into_iter().nth(0) { + if let Some((directory, _)) = files.into_iter().next() { directory } else { panic!("could not find any static libraries"); @@ -99,6 +99,8 @@ fn find() -> PathBuf { /// Find and link to `libclang` statically. pub fn link() { + let cep = common::CommandErrorPrinter::default(); + let directory = find(); // Specify required Clang static libraries. @@ -133,4 +135,6 @@ pub fn link() { } else if cfg!(target_os = "macos") { println!("cargo:rustc-flags=-l ffi -l ncurses -l c++ -l z"); } + + cep.discard(); } diff --git a/ci/before_install.sh b/ci/before_install.sh deleted file mode 100644 index a0de565..0000000 --- a/ci/before_install.sh +++ /dev/null @@ -1,57 +0,0 @@ -set -e -pushd ~ - -# Workaround for Travis CI macOS bug (https://github.com/travis-ci/travis-ci/issues/6307) -if [ "${TRAVIS_OS_NAME}" == "osx" ]; then - rvm get head || true -fi - -function llvm_version_triple() { - if [ "$1" == "3.5" ]; then - echo "3.5.2" - elif [ "$1" == "3.6" ]; then - echo "3.6.2" - elif [ "$1" == "3.7" ]; then - echo "3.7.1" - elif [ "$1" == "3.8" ]; then - echo "3.8.1" - elif [ "$1" == "3.9" ]; then - echo "3.9.0" - elif [ "$1" == "4.0" ]; then - echo "4.0.1" - elif [ "$1" == "5.0" ]; then - echo "5.0.2" - elif [ "$1" == "6.0" ]; then - echo "6.0.1" - elif [ "$1" == "7.0" ]; then - echo "7.0.0" - fi -} - -function llvm_download() { - export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` - export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$1 - export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" - - if [ -d "${LLVM_DIRECTORY}" ]; then - echo "Using cached LLVM download for ${LLVM}..." - else - wget http://releases.llvm.org/${LLVM_VERSION_TRIPLE}/${LLVM}.tar.xz - mkdir -p "${LLVM_DIRECTORY}" - tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 - fi - - export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" -} - -if [ "${TRAVIS_OS_NAME}" == "linux" ]; then - llvm_download x86_64-linux-gnu-ubuntu-14.04 - export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$LD_LIBRARY_PATH -else - llvm_download x86_64-apple-darwin - cp "${LLVM_DIRECTORY}/lib/libclang.dylib" /usr/local/lib/libclang.dylib - export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$DYLD_LIBRARY_PATH -fi - -popd -set +e diff --git a/ci/install.bat b/ci/install.bat deleted file mode 100644 index a3d54df..0000000 --- a/ci/install.bat +++ /dev/null @@ -1,8 +0,0 @@ -curl -sSf https://static.rust-lang.org/dist/rust-1.36.0-i686-pc-windows-msvc.exe -o rust.exe -rust.exe /VERYSILENT /NORESTART /DIR="C:\Rust" -set PATH=%PATH%;C:\Rust\bin - -curl -sSf http://releases.llvm.org/%LLVM_VERSION%/LLVM-%LLVM_VERSION%-win32.exe -o LLVM.exe -7z x LLVM.exe -oC:\LLVM -set PATH=%PATH%;C:\LLVM\bin -set LIBCLANG_PATH=C:\LLVM\bin diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index 47ca439..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,13 +0,0 @@ -if [ "${TRAVIS_OS_NAME}" == "osx" ]; then - rvm get head || true -fi - -set -e - -RUST_BACKTRACE=1 cargo test --verbose --features $CLANG_VERSION -- --nocapture - -if [ "${CLANG_VERSION}" \< "clang_3_7" ]; then - RUST_BACKTRACE=1 cargo test --verbose --features "$CLANG_VERSION static" -- --nocapture -fi - -RUST_BACKTRACE=1 cargo test --verbose --features "$CLANG_VERSION runtime" -- --nocapture diff --git a/ci/test_script.bat b/ci/test_script.bat deleted file mode 100644 index 2928409..0000000 --- a/ci/test_script.bat +++ /dev/null @@ -1,2 +0,0 @@ -set RUST_BACKTRACE=1 -cargo test --verbose --features %CLANG_VERSION% -- --nocapture @@ -5,7 +5,7 @@ import shutil import subprocess TARGET = ".docs" -VERSION = "clang_9_0" +VERSION = "clang_10_0" if os.path.isdir(TARGET): shutil.rmtree(TARGET) diff --git a/out/common.rs b/out/common.rs index 958ef9b..434bd46 100644 --- a/out/common.rs +++ b/out/common.rs @@ -14,6 +14,8 @@ extern crate glob; +use std::cell::RefCell; +use std::collections::HashMap; use std::env; use std::path::{Path, PathBuf}; use std::process::Command; @@ -46,30 +48,38 @@ const DIRECTORIES_WINDOWS: &[&str] = &[ "C:\\MSYS*\\MinGW*\\lib", ]; +thread_local! { + /// The errors encountered when attempting to execute console commands. + static COMMAND_ERRORS: RefCell<HashMap<String, Vec<String>>> = RefCell::default(); +} + /// Executes the supplied console command, returning the `stdout` output if the /// command was successfully executed. -fn run_command(command: &str, arguments: &[&str]) -> Option<String> { - macro_rules! warn { - ($error:expr) => { - println!( - "cargo:warning=couldn't execute `{} {}` ({})", - command, - arguments.join(" "), - $error, - ); - }; +fn run_command(name: &str, command: &str, arguments: &[&str]) -> Option<String> { + macro_rules! error { + ($error:expr) => {{ + COMMAND_ERRORS.with(|e| e.borrow_mut() + .entry(name.into()) + .or_insert_with(Vec::new) + .push(format!( + "couldn't execute `{} {}` ({})", + command, + arguments.join(" "), + $error, + ))); + }}; } let output = match Command::new(command).args(arguments).output() { Ok(output) => output, Err(error) => { - warn!(format!("error: {}", error)); + error!(format!("error: {}", error)); return None; } }; if !output.status.success() { - warn!(format!("exit code: {}", output.status)); + error!(format!("exit code: {}", output.status)); return None; } @@ -80,17 +90,50 @@ fn run_command(command: &str, arguments: &[&str]) -> Option<String> { /// successfully executed. pub fn run_llvm_config(arguments: &[&str]) -> Option<String> { let path = env::var("LLVM_CONFIG_PATH").unwrap_or_else(|_| "llvm-config".into()); + run_command("llvm-config", &path, arguments) +} - let output = run_command(&path, arguments); - if output.is_none() { - println!( - "cargo:warning=set the LLVM_CONFIG_PATH environment variable to \ - the full path to a valid `llvm-config` executable (including the \ - executable itself)" - ); +/// A struct that prints errors encountered when attempting to execute console +/// commands on drop if not discarded. +#[derive(Default)] +pub struct CommandErrorPrinter { + discard: bool +} + +impl CommandErrorPrinter { + pub fn discard(mut self) { + self.discard = true; } +} + +impl Drop for CommandErrorPrinter { + fn drop(&mut self) { + if self.discard { + return; + } + + let errors = COMMAND_ERRORS.with(|e| e.borrow().clone()); + + if let Some(errors) = errors.get("llvm-config") { + println!( + "cargo:warning=could not execute `llvm-config` one or more \ + times, if the LLVM_CONFIG_PATH environment variable is set to \ + a full path to valid `llvm-config` executable it will be used \ + to try to find an instance of `libclang` on your system: {}", + errors.iter().map(|e| format!("\"{}\"", e)).collect::<Vec<_>>().join("\n "), + ) + } - output + if let Some(errors) = errors.get("xcode-select") { + println!( + "cargo:warning=could not execute `xcode-select` one or more \ + times, if a valid instance of this executable is on your PATH \ + it will be used to try to find an instance of `libclang` on \ + your system: {}", + errors.iter().map(|e| format!("\"{}\"", e)).collect::<Vec<_>>().join("\n "), + ) + } + } } /// Returns the paths to and the filenames of the files matching the supplied @@ -179,7 +222,7 @@ pub fn search_libclang_directories(files: &[String], variable: &str) -> Vec<(Pat // Search the toolchain directory in the directory provided by // `xcode-select --print-path`. if cfg!(target_os = "macos") { - if let Some(output) = run_command("xcode-select", &["--print-path"]) { + if let Some(output) = run_command("xcode-select", "xcode-select", &["--print-path"]) { let directory = Path::new(output.lines().next().unwrap()).to_path_buf(); let directory = directory.join("Toolchains/XcodeDefault.xctoolchain/usr/lib"); found.extend(search_directories(&directory, files)); diff --git a/out/dynamic.rs b/out/dynamic.rs index 2054ba0..8a9e5d3 100644 --- a/out/dynamic.rs +++ b/out/dynamic.rs @@ -190,6 +190,8 @@ pub fn find(runtime: bool) -> Result<(PathBuf, String), String> { /// Find and link to `libclang` dynamically. #[cfg(not(feature = "runtime"))] pub fn link() { + let cep = common::CommandErrorPrinter::default(); + use std::fs; let (directory, filename) = find(false).unwrap(); @@ -241,4 +243,6 @@ pub fn link() { println!("cargo:rustc-link-lib=dylib={}", name); } + + cep.discard(); } @@ -48,7 +48,7 @@ use libc::*; pub type CXClientData = *mut c_void; pub type CXCursorVisitor = extern "C" fn(CXCursor, CXCursor, CXClientData) -> CXChildVisitResult; -#[cfg(feature = "gte_clang_3_7")] +#[cfg(feature = "clang_3_7")] pub type CXFieldVisitor = extern "C" fn(CXCursor, CXClientData) -> CXVisitorResult; pub type CXInclusionVisitor = extern "C" fn(CXFile, *mut CXSourceLocation, c_uint, CXClientData); @@ -438,6 +438,16 @@ cenum! { const CXCursor_OMPTargetTeamsDistributeSimdDirective = 279, /// Only produced by 'libclang' 9.0 and later. const CXCursor_BuiltinBitCastExpr = 280, + /// Only produced by `libclang` 10.0 and later. + const CXCursor_OMPMasterTaskLoopDirective = 281, + /// Only produced by `libclang` 10.0 and later. + const CXCursor_OMPParallelMasterTaskLoopDirective = 282, + /// Only produced by `libclang` 10.0 and later. + const CXCursor_OMPMasterTaskLoopSimdDirective = 283, + /// Only produced by `libclang` 10.0 and later. + const CXCursor_OMPParallelMasterTaskLoopSimdDirective = 284, + /// Only produced by `libclang` 10.0 and later. + const CXCursor_OMPParallelMasterDirective = 285, const CXCursor_TranslationUnit = 300, const CXCursor_UnexposedAttr = 400, const CXCursor_IBActionAttr = 401, @@ -526,7 +536,7 @@ cenum! { cenum! { /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] enum CXCursor_ExceptionSpecificationKind { const CXCursor_ExceptionSpecificationKind_None = 0, const CXCursor_ExceptionSpecificationKind_DynamicNone = 1, @@ -538,7 +548,7 @@ cenum! { const CXCursor_ExceptionSpecificationKind_Uninstantiated = 7, const CXCursor_ExceptionSpecificationKind_Unparsed = 8, /// Only available on `libclang` 9.0 and later. - #[cfg(feature = "gte_clang_9_0")] + #[cfg(feature = "clang_9_0")] const CXCursor_ExceptionSpecificationKind_NoThrow = 9, } } @@ -681,7 +691,7 @@ cenum! { cenum! { /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] enum CXPrintingPolicyProperty { const CXPrintingPolicy_Indentation = 0, const CXPrintingPolicy_SuppressSpecifiers = 1, @@ -739,7 +749,7 @@ cenum! { cenum! { /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] enum CXTLSKind { const CXTLS_None = 0, const CXTLS_Dynamic = 1, @@ -768,7 +778,7 @@ cenum! { cenum! { /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] enum CXTemplateArgumentKind { const CXTemplateArgumentKind_Null = 0, const CXTemplateArgumentKind_Type = 1, @@ -996,7 +1006,7 @@ cenum! { cenum! { /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] enum CXVisibilityKind { const CXVisibility_Invalid = 0, const CXVisibility_Hidden = 1, @@ -1007,7 +1017,7 @@ cenum! { cenum! { /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] enum CXTypeNullabilityKind { const CXTypeNullability_NonNull = 0, const CXTypeNullability_Nullable = 1, @@ -1034,7 +1044,7 @@ cenum! { cenum! { /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] enum CX_StorageClass { const CX_SC_Invalid = 0, const CX_SC_None = 1, @@ -1164,7 +1174,7 @@ cenum! { const CXObjCPropertyAttr_strong = 1024; const CXObjCPropertyAttr_unsafe_unretained = 2048; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] const CXObjCPropertyAttr_class = 4096; } } @@ -1183,7 +1193,7 @@ cenum! { cenum! { /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] enum CXSymbolRole { const CXSymbolRole_None = 0; const CXSymbolRole_Declaration = 1; @@ -1210,26 +1220,29 @@ cenum! { const CXTranslationUnit_SkipFunctionBodies = 64; const CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 128; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] const CXTranslationUnit_CreatePreambleOnFirstParse = 256; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] const CXTranslationUnit_KeepGoing = 512; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] const CXTranslationUnit_SingleFileParse = 1024; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] const CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 2048; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] const CXTranslationUnit_IncludeAttributedTypes = 4096; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] const CXTranslationUnit_VisitImplicitAttributes = 8192; /// Only available on `libclang` 9.0 and later. - #[cfg(feature = "gte_clang_9_0")] + #[cfg(feature = "clang_9_0")] const CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles = 16384; + /// Only available on `libclang` 10.0 and later. + #[cfg(feature = "clang_10_0")] + const CXTranslationUnit_RetainExcludedConditionalBlocks = 32768; } } @@ -1252,7 +1265,7 @@ opaque!(CXCompletionString); opaque!(CXCursorSet); opaque!(CXDiagnostic); opaque!(CXDiagnosticSet); -#[cfg(feature = "gte_clang_3_9")] +#[cfg(feature = "clang_3_9")] opaque!(CXEvalResult); opaque!(CXFile); opaque!(CXIdxClientASTFile); @@ -1262,10 +1275,10 @@ opaque!(CXIdxClientFile); opaque!(CXIndex); opaque!(CXIndexAction); opaque!(CXModule); -#[cfg(feature = "gte_clang_7_0")] +#[cfg(feature = "clang_7_0")] opaque!(CXPrintingPolicy); opaque!(CXRemapping); -#[cfg(feature = "gte_clang_5_0")] +#[cfg(feature = "clang_5_0")] opaque!(CXTargetInfo); opaque!(CXTranslationUnit); @@ -1408,7 +1421,7 @@ pub struct CXIdxEntityRefInfo { pub parentEntity: *const CXIdxEntityInfo, pub container: *const CXIdxContainerInfo, /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub role: CXSymbolRole, } @@ -1568,7 +1581,7 @@ pub struct CXString { default!(CXString); -#[cfg(feature = "gte_clang_3_8")] +#[cfg(feature = "clang_3_8")] #[derive(Copy, Clone, Debug)] #[repr(C)] pub struct CXStringSet { @@ -1576,7 +1589,7 @@ pub struct CXStringSet { pub Count: c_uint, } -#[cfg(feature = "gte_clang_3_8")] +#[cfg(feature = "clang_3_8")] default!(CXStringSet); #[derive(Copy, Clone, Debug)] @@ -1662,32 +1675,32 @@ link! { pub fn clang_CXIndex_getGlobalOptions(index: CXIndex) -> CXGlobalOptFlags; pub fn clang_CXIndex_setGlobalOptions(index: CXIndex, flags: CXGlobalOptFlags); /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] pub fn clang_CXIndex_setInvocationEmissionPathOption(index: CXIndex, path: *const c_char); /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_CXXConstructor_isConvertingConstructor(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_CXXConstructor_isCopyConstructor(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_CXXConstructor_isDefaultConstructor(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_CXXConstructor_isMoveConstructor(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_CXXField_isMutable(cursor: CXCursor) -> c_uint; pub fn clang_CXXMethod_isConst(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_CXXMethod_isDefaulted(cursor: CXCursor) -> c_uint; pub fn clang_CXXMethod_isPureVirtual(cursor: CXCursor) -> c_uint; pub fn clang_CXXMethod_isStatic(cursor: CXCursor) -> c_uint; pub fn clang_CXXMethod_isVirtual(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] pub fn clang_CXXRecord_isAbstract(cursor: CXCursor) -> c_uint; pub fn clang_CompilationDatabase_dispose(database: CXCompilationDatabase); pub fn clang_CompilationDatabase_fromDirectory(directory: *const c_char, error: *mut CXCompilationDatabase_Error) -> CXCompilationDatabase; @@ -1696,13 +1709,13 @@ link! { pub fn clang_CompileCommand_getArg(command: CXCompileCommand, index: c_uint) -> CXString; pub fn clang_CompileCommand_getDirectory(command: CXCompileCommand) -> CXString; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_CompileCommand_getFilename(command: CXCompileCommand) -> CXString; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_CompileCommand_getMappedSourceContent(command: CXCompileCommand, index: c_uint) -> CXString; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_CompileCommand_getMappedSourcePath(command: CXCompileCommand, index: c_uint) -> CXString; pub fn clang_CompileCommand_getNumArgs(command: CXCompileCommand) -> c_uint; pub fn clang_CompileCommand_getNumMappedSources(command: CXCompileCommand) -> c_uint; @@ -1710,117 +1723,117 @@ link! { pub fn clang_CompileCommands_getCommand(command: CXCompileCommands, index: c_uint) -> CXCompileCommand; pub fn clang_CompileCommands_getSize(command: CXCompileCommands) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Cursor_Evaluate(cursor: CXCursor) -> CXEvalResult; pub fn clang_Cursor_getArgument(cursor: CXCursor, index: c_uint) -> CXCursor; pub fn clang_Cursor_getBriefCommentText(cursor: CXCursor) -> CXString; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_Cursor_getCXXManglings(cursor: CXCursor) -> *mut CXStringSet; pub fn clang_Cursor_getCommentRange(cursor: CXCursor) -> CXSourceRange; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getMangling(cursor: CXCursor) -> CXString; pub fn clang_Cursor_getModule(cursor: CXCursor) -> CXModule; pub fn clang_Cursor_getNumArguments(cursor: CXCursor) -> c_int; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getNumTemplateArguments(cursor: CXCursor) -> c_int; pub fn clang_Cursor_getObjCDeclQualifiers(cursor: CXCursor) -> CXObjCDeclQualifierKind; /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] pub fn clang_Cursor_getObjCManglings(cursor: CXCursor) -> *mut CXStringSet; pub fn clang_Cursor_getObjCPropertyAttributes(cursor: CXCursor, reserved: c_uint) -> CXObjCPropertyAttrKind; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Cursor_getObjCPropertyGetterName(cursor: CXCursor) -> CXString; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Cursor_getObjCPropertySetterName(cursor: CXCursor) -> CXString; pub fn clang_Cursor_getObjCSelectorIndex(cursor: CXCursor) -> c_int; /// Only available on `libclang` 3.7 and later. - #[cfg(feature = "gte_clang_3_7")] + #[cfg(feature = "clang_3_7")] pub fn clang_Cursor_getOffsetOfField(cursor: CXCursor) -> c_longlong; /// Only available on `libclang` 9.0 and later. - #[cfg(feature = "gte_clang_9_0")] + #[cfg(feature = "clang_9_0")] pub fn clang_Cursor_isAnonymousRecordDecl(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 9.0 and later. - #[cfg(feature = "gte_clang_9_0")] + #[cfg(feature = "clang_9_0")] pub fn clang_Cursor_isInlineNamespace(cursor: CXCursor) -> c_uint; pub fn clang_Cursor_getRawCommentText(cursor: CXCursor) -> CXString; pub fn clang_Cursor_getReceiverType(cursor: CXCursor) -> CXType; pub fn clang_Cursor_getSpellingNameRange(cursor: CXCursor, index: c_uint, reserved: c_uint) -> CXSourceRange; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getStorageClass(cursor: CXCursor) -> CX_StorageClass; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getTemplateArgumentKind(cursor: CXCursor, index: c_uint) -> CXTemplateArgumentKind; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getTemplateArgumentType(cursor: CXCursor, index: c_uint) -> CXType; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getTemplateArgumentUnsignedValue(cursor: CXCursor, index: c_uint) -> c_ulonglong; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_Cursor_getTemplateArgumentValue(cursor: CXCursor, index: c_uint) -> c_longlong; pub fn clang_Cursor_getTranslationUnit(cursor: CXCursor) -> CXTranslationUnit; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Cursor_hasAttrs(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.7 and later. - #[cfg(feature = "gte_clang_3_7")] + #[cfg(feature = "clang_3_7")] pub fn clang_Cursor_isAnonymous(cursor: CXCursor) -> c_uint; pub fn clang_Cursor_isBitField(cursor: CXCursor) -> c_uint; pub fn clang_Cursor_isDynamicCall(cursor: CXCursor) -> c_int; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_Cursor_isExternalSymbol(cursor: CXCursor, language: *mut CXString, from: *mut CXString, generated: *mut c_uint) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Cursor_isFunctionInlined(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Cursor_isMacroBuiltin(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Cursor_isMacroFunctionLike(cursor: CXCursor) -> c_uint; pub fn clang_Cursor_isNull(cursor: CXCursor) -> c_int; pub fn clang_Cursor_isObjCOptional(cursor: CXCursor) -> c_uint; pub fn clang_Cursor_isVariadic(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_EnumDecl_isScoped(cursor: CXCursor) -> c_uint; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_EvalResult_dispose(result: CXEvalResult); /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_EvalResult_getAsDouble(result: CXEvalResult) -> libc::c_double; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_EvalResult_getAsInt(result: CXEvalResult) -> c_int; /// Only available on `libclang` 4.0 and later. - #[cfg(feature = "gte_clang_4_0")] + #[cfg(feature = "clang_4_0")] pub fn clang_EvalResult_getAsLongLong(result: CXEvalResult) -> c_longlong; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_EvalResult_getAsStr(result: CXEvalResult) -> *const c_char; /// Only available on `libclang` 4.0 and later. - #[cfg(feature = "gte_clang_4_0")] + #[cfg(feature = "clang_4_0")] pub fn clang_EvalResult_getAsUnsigned(result: CXEvalResult) -> c_ulonglong; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_EvalResult_getKind(result: CXEvalResult) -> CXEvalResultKind; /// Only available on `libclang` 4.0 and later. - #[cfg(feature = "gte_clang_4_0")] + #[cfg(feature = "clang_4_0")] pub fn clang_EvalResult_isUnsignedInt(result: CXEvalResult) -> c_uint; /// Only available on `libclang` 3.6 and later. - #[cfg(feature = "gte_clang_3_6")] + #[cfg(feature = "clang_3_6")] pub fn clang_File_isEqual(left: CXFile, right: CXFile) -> c_int; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_File_tryGetRealPathName(file: CXFile) -> CXString; pub fn clang_IndexAction_create(index: CXIndex) -> CXIndexAction; pub fn clang_IndexAction_dispose(index: CXIndexAction); @@ -1834,63 +1847,63 @@ link! { pub fn clang_Module_getTopLevelHeader(tu: CXTranslationUnit, module: CXModule, index: c_uint) -> CXFile; pub fn clang_Module_isSystem(module: CXModule) -> c_int; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_PrintingPolicy_dispose(policy: CXPrintingPolicy); /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_PrintingPolicy_getProperty(policy: CXPrintingPolicy, property: CXPrintingPolicyProperty) -> c_uint; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_PrintingPolicy_setProperty(policy: CXPrintingPolicy, property: CXPrintingPolicyProperty, value: c_uint); pub fn clang_Range_isNull(range: CXSourceRange) -> c_int; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_TargetInfo_dispose(info: CXTargetInfo); /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_TargetInfo_getPointerWidth(info: CXTargetInfo) -> c_int; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_TargetInfo_getTriple(info: CXTargetInfo) -> CXString; pub fn clang_Type_getAlignOf(type_: CXType) -> c_longlong; pub fn clang_Type_getCXXRefQualifier(type_: CXType) -> CXRefQualifierKind; pub fn clang_Type_getClassType(type_: CXType) -> CXType; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Type_getNamedType(type_: CXType) -> CXType; pub fn clang_Type_getNumTemplateArguments(type_: CXType) -> c_int; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getObjCObjectBaseType(type_: CXType) -> CXType; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getNumObjCProtocolRefs(type_: CXType) -> c_uint; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getObjCProtocolDecl(type_: CXType, index: c_uint) -> CXCursor; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getNumObjCTypeArgs(type_: CXType) -> c_uint; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getObjCTypeArg(type_: CXType, index: c_uint) -> CXType; /// Only available on `libclang` 3.9 and later. - #[cfg(feature = "gte_clang_3_9")] + #[cfg(feature = "clang_3_9")] pub fn clang_Type_getObjCEncoding(type_: CXType) -> CXString; pub fn clang_Type_getOffsetOf(type_: CXType, field: *const c_char) -> c_longlong; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getModifiedType(type_: CXType) -> CXType; pub fn clang_Type_getSizeOf(type_: CXType) -> c_longlong; pub fn clang_Type_getTemplateArgumentAsType(type_: CXType, index: c_uint) -> CXType; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_Type_isTransparentTagTypedef(type_: CXType) -> c_uint; /// Only available on `libclang` 8.0 and later. - #[cfg(feature = "gte_clang_8_0")] + #[cfg(feature = "clang_8_0")] pub fn clang_Type_getNullability(type_: CXType) -> CXTypeNullabilityKind; /// Only available on `libclang` 3.7 and later. - #[cfg(feature = "gte_clang_3_7")] + #[cfg(feature = "clang_3_7")] pub fn clang_Type_visitFields(type_: CXType, visitor: CXFieldVisitor, data: CXClientData) -> CXVisitorResult; pub fn clang_annotateTokens(tu: CXTranslationUnit, tokens: *mut CXToken, n_tokens: c_uint, cursors: *mut CXCursor); pub fn clang_codeCompleteAt(tu: CXTranslationUnit, file: *const c_char, line: c_uint, column: c_uint, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXCodeComplete_Flags) -> *mut CXCodeCompleteResults; @@ -1927,7 +1940,7 @@ link! { pub fn clang_disposeSourceRangeList(list: *mut CXSourceRangeList); pub fn clang_disposeString(string: CXString); /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_disposeStringSet(set: *mut CXStringSet); pub fn clang_disposeTokens(tu: CXTranslationUnit, tokens: *mut CXToken, n_tokens: c_uint); pub fn clang_disposeTranslationUnit(tu: CXTranslationUnit); @@ -1941,13 +1954,13 @@ link! { pub fn clang_findReferencesInFile(cursor: CXCursor, file: CXFile, visitor: CXCursorAndRangeVisitor) -> CXResult; pub fn clang_formatDiagnostic(diagnostic: CXDiagnostic, flags: CXDiagnosticDisplayOptions) -> CXString; /// Only available on `libclang` 3.7 and later. - #[cfg(feature = "gte_clang_3_7")] + #[cfg(feature = "clang_3_7")] pub fn clang_free(buffer: *mut c_void); /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_getAddressSpace(type_: CXType) -> c_uint; /// Only available on `libclang` 4.0 and later. - #[cfg(feature = "gte_clang_4_0")] + #[cfg(feature = "clang_4_0")] pub fn clang_getAllSkippedRanges(tu: CXTranslationUnit) -> *mut CXSourceRangeList; pub fn clang_getArgType(type_: CXType, index: c_uint) -> CXType; pub fn clang_getArrayElementType(type_: CXType) -> CXType; @@ -1966,11 +1979,11 @@ link! { pub fn clang_getCompletionChunkKind(string: CXCompletionString, index: c_uint) -> CXCompletionChunkKind; pub fn clang_getCompletionChunkText(string: CXCompletionString, index: c_uint) -> CXString; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_getCompletionFixIt(results: *mut CXCodeCompleteResults, completion_index: c_uint, fixit_index: c_uint, range: *mut CXSourceRange) -> CXString; pub fn clang_getCompletionNumAnnotations(string: CXCompletionString) -> c_uint; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_getCompletionNumFixIts(results: *mut CXCodeCompleteResults, completion_index: c_uint) -> c_uint; pub fn clang_getCompletionParent(string: CXCompletionString, kind: *mut CXCursorKind) -> CXString; pub fn clang_getCompletionPriority(string: CXCompletionString) -> c_uint; @@ -1980,7 +1993,7 @@ link! { pub fn clang_getCursorDefinition(cursor: CXCursor) -> CXCursor; pub fn clang_getCursorDisplayName(cursor: CXCursor) -> CXString; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_getCursorExceptionSpecificationType(cursor: CXCursor) -> CXCursor_ExceptionSpecificationKind; pub fn clang_getCursorExtent(cursor: CXCursor) -> CXSourceRange; pub fn clang_getCursorKind(cursor: CXCursor) -> CXCursorKind; @@ -1991,10 +2004,10 @@ link! { pub fn clang_getCursorLocation(cursor: CXCursor) -> CXSourceLocation; pub fn clang_getCursorPlatformAvailability(cursor: CXCursor, deprecated: *mut c_int, deprecated_message: *mut CXString, unavailable: *mut c_int, unavailable_message: *mut CXString, availability: *mut CXPlatformAvailability, n_availability: c_int) -> c_int; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_getCursorPrettyPrinted(cursor: CXCursor, policy: CXPrintingPolicy) -> CXString; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_getCursorPrintingPolicy(cursor: CXCursor) -> CXPrintingPolicy; pub fn clang_getCursorReferenceNameRange(cursor: CXCursor, flags: CXNameRefFlags, index: c_uint) -> CXSourceRange; pub fn clang_getCursorReferenced(cursor: CXCursor) -> CXCursor; @@ -2002,12 +2015,12 @@ link! { pub fn clang_getCursorSemanticParent(cursor: CXCursor) -> CXCursor; pub fn clang_getCursorSpelling(cursor: CXCursor) -> CXString; /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] pub fn clang_getCursorTLSKind(cursor: CXCursor) -> CXTLSKind; pub fn clang_getCursorType(cursor: CXCursor) -> CXType; pub fn clang_getCursorUSR(cursor: CXCursor) -> CXString; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_getCursorVisibility(cursor: CXCursor) -> CXVisibilityKind; pub fn clang_getDeclObjCTypeEncoding(cursor: CXCursor) -> CXString; pub fn clang_getDefinitionSpellingAndExtent(cursor: CXCursor, start: *mut *const c_char, end: *mut *const c_char, start_line: *mut c_uint, start_column: *mut c_uint, end_line: *mut c_uint, end_column: *mut c_uint); @@ -2030,13 +2043,13 @@ link! { pub fn clang_getEnumConstantDeclValue(cursor: CXCursor) -> c_longlong; pub fn clang_getEnumDeclIntegerType(cursor: CXCursor) -> CXType; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_getExceptionSpecificationType(type_: CXType) -> CXCursor_ExceptionSpecificationKind; pub fn clang_getExpansionLocation(location: CXSourceLocation, file: *mut CXFile, line: *mut c_uint, column: *mut c_uint, offset: *mut c_uint); pub fn clang_getFieldDeclBitWidth(cursor: CXCursor) -> c_int; pub fn clang_getFile(tu: CXTranslationUnit, file: *const c_char) -> CXFile; /// Only available on `libclang` 6.0 and later. - #[cfg(feature = "gte_clang_6_0")] + #[cfg(feature = "clang_6_0")] pub fn clang_getFileContents(tu: CXTranslationUnit, file: CXFile, size: *mut size_t) -> *const c_char; pub fn clang_getFileLocation(location: CXSourceLocation, file: *mut CXFile, line: *mut c_uint, column: *mut c_uint, offset: *mut c_uint); pub fn clang_getFileName(file: CXFile) -> CXString; @@ -2074,7 +2087,7 @@ link! { pub fn clang_getSpellingLocation(location: CXSourceLocation, file: *mut CXFile, line: *mut c_uint, column: *mut c_uint, offset: *mut c_uint); pub fn clang_getTUResourceUsageName(kind: CXTUResourceUsageKind) -> *const c_char; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_getTranslationUnitTargetInfo(tu: CXTranslationUnit) -> CXTargetInfo; pub fn clang_getTemplateCursorKind(cursor: CXCursor) -> CXCursorKind; pub fn clang_getTokenExtent(tu: CXTranslationUnit, token: CXToken) -> CXSourceRange; @@ -2088,14 +2101,14 @@ link! { pub fn clang_getTypeSpelling(type_: CXType) -> CXString; pub fn clang_getTypedefDeclUnderlyingType(cursor: CXCursor) -> CXType; /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_getTypedefName(type_: CXType) -> CXString; pub fn clang_hashCursor(cursor: CXCursor) -> c_uint; pub fn clang_indexLoc_getCXSourceLocation(location: CXIdxLoc) -> CXSourceLocation; pub fn clang_indexLoc_getFileLocation(location: CXIdxLoc, index_file: *mut CXIdxClientFile, file: *mut CXFile, line: *mut c_uint, column: *mut c_uint, offset: *mut c_uint); pub fn clang_indexSourceFile(index: CXIndexAction, data: CXClientData, callbacks: *mut IndexerCallbacks, n_callbacks: c_uint, index_flags: CXIndexOptFlags, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, tu: *mut CXTranslationUnit, tu_flags: CXTranslationUnit_Flags) -> CXErrorCode; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_indexSourceFileFullArgv(index: CXIndexAction, data: CXClientData, callbacks: *mut IndexerCallbacks, n_callbacks: c_uint, index_flags: CXIndexOptFlags, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, tu: *mut CXTranslationUnit, tu_flags: CXTranslationUnit_Flags) -> CXErrorCode; pub fn clang_indexTranslationUnit(index: CXIndexAction, data: CXClientData, callbacks: *mut IndexerCallbacks, n_callbacks: c_uint, flags: CXIndexOptFlags, tu: CXTranslationUnit) -> c_int; pub fn clang_index_getCXXClassDeclInfo(info: *const CXIdxDeclInfo) -> *const CXIdxCXXClassDeclInfo; @@ -2119,7 +2132,7 @@ link! { pub fn clang_isFunctionTypeVariadic(type_: CXType) -> c_uint; pub fn clang_isInvalid(kind: CXCursorKind) -> c_uint; /// Only available on `libclang` 7.0 and later. - #[cfg(feature = "gte_clang_7_0")] + #[cfg(feature = "clang_7_0")] pub fn clang_isInvalidDeclaration(cursor: CXCursor) -> c_uint; pub fn clang_isPODType(type_: CXType) -> c_uint; pub fn clang_isPreprocessing(kind: CXCursorKind) -> c_uint; @@ -2134,7 +2147,7 @@ link! { pub fn clang_parseTranslationUnit(index: CXIndex, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXTranslationUnit_Flags) -> CXTranslationUnit; pub fn clang_parseTranslationUnit2(index: CXIndex, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXTranslationUnit_Flags, tu: *mut CXTranslationUnit) -> CXErrorCode; /// Only available on `libclang` 3.8 and later. - #[cfg(feature = "gte_clang_3_8")] + #[cfg(feature = "clang_3_8")] pub fn clang_parseTranslationUnit2FullArgv(index: CXIndex, file: *const c_char, arguments: *const *const c_char, n_arguments: c_int, unsaved: *mut CXUnsavedFile, n_unsaved: c_uint, flags: CXTranslationUnit_Flags, tu: *mut CXTranslationUnit) -> CXErrorCode; pub fn clang_remap_dispose(remapping: CXRemapping); pub fn clang_remap_getFilenames(remapping: CXRemapping, index: c_uint, original: *mut CXString, transformed: *mut CXString); @@ -2143,7 +2156,7 @@ link! { pub fn clang_saveTranslationUnit(tu: CXTranslationUnit, file: *const c_char, options: CXSaveTranslationUnit_Flags) -> CXSaveError; pub fn clang_sortCodeCompletionResults(results: *mut CXCompletionResult, n_results: c_uint); /// Only available on `libclang` 5.0 and later. - #[cfg(feature = "gte_clang_5_0")] + #[cfg(feature = "clang_5_0")] pub fn clang_suspendTranslationUnit(tu: CXTranslationUnit) -> c_uint; pub fn clang_toggleCrashRecovery(recovery: c_uint); pub fn clang_tokenize(tu: CXTranslationUnit, range: CXSourceRange, tokens: *mut *mut CXToken, n_tokens: *mut c_uint); diff --git a/src/link.rs b/src/link.rs index 11a73ab..082eb81 100644 --- a/src/link.rs +++ b/src/link.rs @@ -150,7 +150,8 @@ macro_rules! link { } $( - #[cfg_attr(feature="cargo-clippy", allow(too_many_arguments))] + #[cfg_attr(feature="cargo-clippy", allow(clippy::missing_safety_doc))] + #[cfg_attr(feature="cargo-clippy", allow(clippy::too_many_arguments))] $(#[doc=$doc] #[cfg($cfg)])* pub unsafe fn $name($($pname: $pty), *) $(-> $ret)* { let f = with_library(|l| { @@ -189,7 +190,7 @@ macro_rules! link { pub mod dynamic { include!("../out/dynamic.rs"); } } - let (directory, filename) = try!(build::dynamic::find(true)); + let (directory, filename) = build::dynamic::find(true)?; let path = directory.join(filename); let library = libloading::Library::new(&path).map_err(|e| { @@ -200,7 +201,7 @@ macro_rules! link { ) }); - let mut library = SharedLibrary::new(try!(library), path); + let mut library = SharedLibrary::new(library?, path); $(load::$name(&mut library);)+ Ok(library) } @@ -218,7 +219,7 @@ macro_rules! link { /// * the `libclang` shared library could not be opened #[allow(dead_code)] pub fn load() -> Result<(), String> { - let library = Arc::new(try!(load_manually())); + let library = Arc::new(load_manually()?); LIBRARY.with(|l| *l.borrow_mut() = Some(library)); Ok(()) } diff --git a/src/support.rs b/src/support.rs index acf6522..f061275 100644 --- a/src/support.rs +++ b/src/support.rs @@ -181,7 +181,7 @@ fn parse_version_number(number: &str) -> Option<c_int> { fn parse_version(path: &Path) -> Option<CXVersion> { let output = run_clang(path, &["--version"]).0; let start = try_opt!(output.find("version ")) + 8; - let mut numbers = try_opt!(output[start..].split_whitespace().nth(0)).split('.'); + let mut numbers = try_opt!(output[start..].split_whitespace().next()).split('.'); let major = try_opt!(numbers.next().and_then(parse_version_number)); let minor = try_opt!(numbers.next().and_then(parse_version_number)); let subminor = numbers.next().and_then(parse_version_number).unwrap_or(0); |