diff options
author | Joel Galenson <jgalenson@google.com> | 2021-05-25 21:41:17 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-25 21:41:17 +0000 |
commit | 9d63edf81d51dd6d02672654641aa4a03353e043 (patch) | |
tree | 4941bfbece03f55b22c58b2459505e705d14586d | |
parent | 5c62d6e8f1497ff4c8675ced720d9cfdc8d0084f (diff) | |
parent | 27ab2c839335d2bda48a8e305ef2957218ed816c (diff) | |
download | clang-sys-9d63edf81d51dd6d02672654641aa4a03353e043.tar.gz |
Upgrade rust/crates/clang-sys to 1.2.0 am: 83337ed14d am: 27ab2c8393
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/clang-sys/+/1712591
Change-Id: Ia68195418b248d8a4c1aef92d18886e5d21d89ae
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 12 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 14 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | TEST_MAPPING | 5 | ||||
-rw-r--r-- | build/common.rs | 36 | ||||
-rw-r--r-- | out/common.rs | 36 | ||||
-rw-r--r-- | src/lib.rs | 24 | ||||
-rw-r--r-- | src/support.rs | 37 | ||||
-rw-r--r-- | tests/lib.rs | 7 |
14 files changed, 137 insertions, 70 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index b4474d7..630eef7 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "fae8e5e15f060bc1fb11c26eac168eaf8a50632b" + "sha1": "c9ae24a7a218e73e1eccd320174349eef5a3bd1a" } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 993f360..103c19e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,18 +21,11 @@ jobs: - 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 @@ -41,17 +34,14 @@ jobs: # 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: + # Needed to not find MinGW when loading at runtime 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 @@ -62,5 +62,5 @@ rust_library_host { // dependent_library ["feature_list"] // cfg-if-1.0.0 // glob-0.3.0 -// libc-0.2.86 +// libc-0.2.94 // libloading-0.7.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index a4940fa..50af79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [1.2.0] - 2021-04-08 + +### Changed +- Changed `Clang::find` to prefer target-prefixed binaries when a `-target` +argument is provided (e.g., if the arguments `-target` and +`x86_64-unknown-linux-gnu` are provided, a target-prefixed Clang executable +such as `x86_64-unknown-linux-gnu-clang` will be preferred over a non-target +prefixed Clang executable) + +### Fixed +- Fixed build script to split paths in environment variables (e.g., +`LD_LIBRARY_PATH`) using the appropriate separator for the platform (previously +`:` was used as the separator but some platforms such as Windows use `;`) + ## [1.1.1] - 2021-02-19 ### Changed @@ -12,7 +12,7 @@ [package] name = "clang-sys" -version = "1.1.1" +version = "1.2.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_10_0", "runtime"] +features = ["clang_11_0", "runtime"] [dependencies.glob] version = "0.3" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index f7abf3c..e34929a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -3,7 +3,7 @@ name = "clang-sys" authors = ["Kyle Mayes <kyle@mayeses.com>"] -version = "1.1.1" +version = "1.2.0" readme = "README.md" license = "Apache-2.0" @@ -47,4 +47,4 @@ glob = "0.3" [package.metadata.docs.rs] -features = ["clang_10_0", "runtime"] +features = ["clang_11_0", "runtime"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/clang-sys/clang-sys-1.1.1.crate" + value: "https://static.crates.io/crates/clang-sys/clang-sys-1.2.0.crate" } - version: "1.1.1" + version: "1.2.0" license_type: NOTICE last_upgrade_date { year: 2021 - month: 2 - day: 22 + month: 5 + day: 19 } } @@ -14,20 +14,14 @@ Minimum supported Rust version: **1.40.0** Released under the Apache License 2.0. -## Documentation +## [Documentation](https://docs.rs/clang-sys) -There are two versions of the documentation, one for the API exposed when -linking dynamically or statically and one for the API exposed when linking at -runtime (see the -[Dependencies](https://github.com/KyleMayes/clang-sys#dependencies) section -of the README for more information on the linking options). +Note that the documentation on https://docs.rs for this crate assumes usage of the `runtime` Cargo feature as well as the Cargo feature for the latest supported version of `libclang` (e.g., `clang_11_0`), neither of which are enabled by default. -The only difference between the APIs exposed is that when linking at runtime a -few additional types and functions are exposed to manage the loaded `libclang` -shared library. +Due to the usage of the `runtime` Cargo feature, this documentation will contain some additional types and functions to manage a dynamically loaded +`libclang` instance at runtime. -* Runtime - [Documentation](https://kylemayes.github.io/clang-sys/runtime/clang_sys) -* Dynamic / Static - [Documentation](https://kylemayes.github.io/clang-sys/default/clang_sys) +Due to the usage of the Cargo feature for the latest supported version of `libclang`, this documentation will contain constants and functions that are not available in the oldest supported version of `libclang` (3.5). All of these types and functions have a documentation comment which specifies the minimum `libclang` version required to use the item. ## Supported Versions diff --git a/TEST_MAPPING b/TEST_MAPPING index 7de080a..a731acb 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -2,10 +2,13 @@ { "presubmit": [ { + "name": "keystore2_test" + }, + { "name": "libsqlite3-sys_device_test_src_lib" }, { - "name": "keystore2_test" + "name": "vpnprofilestore_test" } ] } diff --git a/build/common.rs b/build/common.rs index 265a0cf..f06aff5 100644 --- a/build/common.rs +++ b/build/common.rs @@ -61,15 +61,17 @@ thread_local! { 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, - ))); + COMMAND_ERRORS.with(|e| { + e.borrow_mut() + .entry(name.into()) + .or_insert_with(Vec::new) + .push(format!( + "couldn't execute `{} {}` ({})", + command, + arguments.join(" "), + $error, + )) + }); }}; } @@ -100,7 +102,7 @@ pub fn run_llvm_config(arguments: &[&str]) -> Option<String> { /// commands on drop if not discarded. #[derive(Default)] pub struct CommandErrorPrinter { - discard: bool + discard: bool, } impl CommandErrorPrinter { @@ -123,7 +125,11 @@ impl Drop for CommandErrorPrinter { 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 "), + errors + .iter() + .map(|e| format!("\"{}\"", e)) + .collect::<Vec<_>>() + .join("\n "), ) } @@ -133,7 +139,11 @@ impl Drop for CommandErrorPrinter { 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 "), + errors + .iter() + .map(|e| format!("\"{}\"", e)) + .collect::<Vec<_>>() + .join("\n "), ) } } @@ -235,7 +245,7 @@ pub fn search_libclang_directories(files: &[String], variable: &str) -> Vec<(Pat // Search the directories provided by the `LD_LIBRARY_PATH` environment // variable. if let Ok(path) = env::var("LD_LIBRARY_PATH") { - for directory in path.split(':').map(Path::new) { + for directory in env::split_paths(&path) { found.extend(search_directories(&directory, files)); } } diff --git a/out/common.rs b/out/common.rs index 265a0cf..f06aff5 100644 --- a/out/common.rs +++ b/out/common.rs @@ -61,15 +61,17 @@ thread_local! { 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, - ))); + COMMAND_ERRORS.with(|e| { + e.borrow_mut() + .entry(name.into()) + .or_insert_with(Vec::new) + .push(format!( + "couldn't execute `{} {}` ({})", + command, + arguments.join(" "), + $error, + )) + }); }}; } @@ -100,7 +102,7 @@ pub fn run_llvm_config(arguments: &[&str]) -> Option<String> { /// commands on drop if not discarded. #[derive(Default)] pub struct CommandErrorPrinter { - discard: bool + discard: bool, } impl CommandErrorPrinter { @@ -123,7 +125,11 @@ impl Drop for CommandErrorPrinter { 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 "), + errors + .iter() + .map(|e| format!("\"{}\"", e)) + .collect::<Vec<_>>() + .join("\n "), ) } @@ -133,7 +139,11 @@ impl Drop for CommandErrorPrinter { 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 "), + errors + .iter() + .map(|e| format!("\"{}\"", e)) + .collect::<Vec<_>>() + .join("\n "), ) } } @@ -235,7 +245,7 @@ pub fn search_libclang_directories(files: &[String], variable: &str) -> Vec<(Pat // Search the directories provided by the `LD_LIBRARY_PATH` environment // variable. if let Ok(path) = env::var("LD_LIBRARY_PATH") { - for directory in path.split(':').map(Path::new) { + for directory in env::split_paths(&path) { found.extend(search_directories(&directory, files)); } } @@ -14,20 +14,22 @@ //! Rust bindings for `libclang`. //! -//! ## Documentation +//! ## [Documentation](https://docs.rs/clang-sys) //! -//! There are two versions of the documentation, one for the API exposed when -//! linking dynamically or statically and one for the API exposed when linking -//! at runtime (see the -//! [Dependencies](https://github.com/KyleMayes/clang-sys#dependencies) section -//! of the README for more information on the linking options). +//! Note that the documentation on https://docs.rs for this crate assumes usage +//! of the `runtime` Cargo feature as well as the Cargo feature for the latest +//! supported version of `libclang` (e.g., `clang_11_0`), neither of which are +//! enabled by default. //! -//! The only difference between the APIs exposed is that when linking at runtime -//! a few additional types and functions are exposed to manage the loaded -//! `libclang` shared library. +//! Due to the usage of the `runtime` Cargo feature, this documentation will +//! contain some additional types and functions to manage a dynamically loaded +//! `libclang` instance at runtime. //! -//! * Runtime - [Documentation](https://kylemayes.github.io/clang-sys/runtime/clang_sys) -//! * Dynamic / Static - [Documentation](https://kylemayes.github.io/clang-sys/default/clang_sys) +//! Due to the usage of the Cargo feature for the latest supported version of +//! `libclang`, this documentation will contain constants and functions that are +//! not available in the oldest supported version of `libclang` (3.5). All of +//! these types and functions have a documentation comment which specifies the +//! minimum `libclang` version required to use the item. #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))] diff --git a/src/support.rs b/src/support.rs index 8422f59..4e698ff 100644 --- a/src/support.rs +++ b/src/support.rs @@ -74,20 +74,41 @@ impl Clang { /// directory returned by `llvm-config --bindir` is searched. On macOS /// systems, `xcodebuild -find clang` will next be queried. Last, the /// directories in the system's `PATH` are searched. + /// + /// ## Cross-compilation + /// + /// If target arguments are provided (e.g., `-target` followed by a target + /// like `x86_64-unknown-linux-gnu`) then this method will prefer a + /// target-prefixed instance of `clang` (e.g., + /// `x86_64-unknown-linux-gnu-clang` for the above example). pub fn find(path: Option<&Path>, args: &[String]) -> Option<Clang> { if let Ok(path) = env::var("CLANG_PATH") { return Some(Clang::new(path, args)); } + // Determine the cross-compilation target, if any. + + let mut target = None; + for i in 0..args.len() { + if args[i] == "-target" && i + 1 < args.len() { + target = Some(&args[i + 1]); + } + } + + // Collect the paths to search for a `clang` executable in. + let mut paths = vec![]; + if let Some(path) = path { paths.push(path.into()); } + if let Ok(path) = run_llvm_config(&["--bindir"]) { if let Some(line) = path.lines().next() { paths.push(line.into()); } } + if cfg!(target_os = "macos") { if let Ok((path, _)) = run("xcodebuild", &["-find", "clang"]) { if let Some(line) = path.lines().next() { @@ -95,8 +116,24 @@ impl Clang { } } } + paths.extend(env::split_paths(&env::var("PATH").unwrap())); + // First, look for a target-prefixed `clang` executable. + + if let Some(target) = target { + let default = format!("{}-clang{}", target, env::consts::EXE_SUFFIX); + let versioned = format!("{}-clang-[0-9]*{}", target, env::consts::EXE_SUFFIX); + let patterns = &[&default[..], &versioned[..]]; + for path in &paths { + if let Some(path) = find(&path, patterns) { + return Some(Clang::new(path, args)); + } + } + } + + // Otherwise, look for any other `clang` executable. + let default = format!("clang{}", env::consts::EXE_SUFFIX); let versioned = format!("clang-[0-9]*{}", env::consts::EXE_SUFFIX); let patterns = &[&default[..], &versioned[..]]; diff --git a/tests/lib.rs b/tests/lib.rs index 100a6c6..b50055a 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -46,3 +46,10 @@ fn test_support() { let clang = support::Clang::find(None, &[]).unwrap(); println!("{:?}", clang); } + +#[test] +fn test_support_target() { + let args = &["-target".into(), "x86_64-unknown-linux-gnu".into()]; + let clang = support::Clang::find(None, args).unwrap(); + println!("{:?}", clang); +} |