Skip to content

Commit e27e32c

Browse files
adetaylorvadimsht
authored andcommitted
[rust] Rebuild libclang dependents on clang rolls
Sometimes clang libraries can be added or removed, so we need to ensure we rebuild libclang's dependencies whenever clang rolls. Previously we (effectively) expanded *.a into a .rsp file which wouldn't necessarily be updated in these circumstances, leading to stale information and potential build failure. This CL contains two significant changes: * We rerun find_clanglibs.py whenever the clang revision changes; * We cease to generate a .rsp file and instead generate a synthetic Rust static library. The reason for this second change is that the names of the various clang libraries were persisted in intermediate .rlib files as metadata. We therefore needed to force rebuild of every dependent .rlib, not just the final linker invocation, when the clang libraries were updated. Altering 'inputs' for many such rlib targets would be fragile; instead, have them all (transitively) depend on a static library. Bug: 1296236 Change-Id: Iea406b2394bbd2231ca8f4cb1b367666277fff9a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3516695 Reviewed-by: danakj <[email protected]> Commit-Queue: Adrian Taylor <[email protected]> Cr-Commit-Position: refs/heads/main@{#979978} NOKEYCHECK=True GitOrigin-RevId: f8b3a9a06116a0d2a9d87473eac635a2605577e3
1 parent dee3a2c commit e27e32c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

clang_sys/v1/crate/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
3535
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
3636

37+
/// Chromium customization: in order to find the libraries shipped with our
38+
/// version of clang, we generate a synthetic Rust crate called clanglibs
39+
/// containing lots of #[link(...)] directives and nothing else. We need to
40+
/// ensure that clang_sys and all its dependencies duly absorb that crate
41+
/// so that the final linking step (performed by rustc) reads all these
42+
/// library names from crate metadata and passes them to the linker.
43+
/// If we don't have this 'extern crate' line, the clanglibs crate does not
44+
/// get used by clang_sys or its dependencies, and those extra libraries
45+
/// are discarded.
46+
extern crate clanglibs;
47+
3748
extern crate glob;
3849
extern crate libc;
3950
#[cfg(feature = "runtime")]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From f8cada38a88b48ca4ab68e690b1977abc23bb53b Mon Sep 17 00:00:00 2001
2+
From: Adrian Taylor <[email protected]>
3+
Date: Thu, 10 Mar 2022 10:59:47 -0800
4+
Subject: [PATCH 1/1] Link against clanglibs
5+
6+
Change-Id: Icaedc6dc749850df73ded4a8b0e49beb7da2e4c9
7+
---
8+
third_party/rust/clang_sys/v1/crate/src/lib.rs | 11 +++++++++++
9+
1 file changed, 11 insertions(+)
10+
11+
diff --git a/third_party/rust/clang_sys/v1/crate/src/lib.rs b/third_party/rust/clang_sys/v1/crate/src/lib.rs
12+
index 5bc0d2a68bef2..fec6acf7bf795 100644
13+
--- a/third_party/rust/clang_sys/v1/crate/src/lib.rs
14+
+++ b/third_party/rust/clang_sys/v1/crate/src/lib.rs
15+
@@ -34,6 +34,17 @@
16+
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
17+
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
18+
19+
+/// Chromium customization: in order to find the libraries shipped with our
20+
+/// version of clang, we generate a synthetic Rust crate called clanglibs
21+
+/// containing lots of #[link(...)] directives and nothing else. We need to
22+
+/// ensure that clang_sys and all its dependencies duly absorb that crate
23+
+/// so that the final linking step (performed by rustc) reads all these
24+
+/// library names from crate metadata and passes them to the linker.
25+
+/// If we don't have this 'extern crate' line, the clanglibs crate does not
26+
+/// get used by clang_sys or its dependencies, and those extra libraries
27+
+/// are discarded.
28+
+extern crate clanglibs;
29+
+
30+
extern crate glob;
31+
extern crate libc;
32+
#[cfg(feature = "runtime")]
33+
--
34+
2.35.1.723.g4982287a31-goog
35+

0 commit comments

Comments
 (0)