Skip to content

Commit ebf7866

Browse files
committed
Okay.
1 parent bb7b9bb commit ebf7866

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

.github/workflows/reusable-san.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ jobs:
5252
else
5353
sudo ./llvm.sh 20
5454
fi
55-
env:
56-
SANITIZER: ${{ inputs.sanitizer }}
5755
5856
- name: Sanitizer option setup
5957
run: |
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Fallback <stdatomic.h> for bindgen.
3+
*
4+
* Some libclang builds ship a <stdatomic.h> that silently provides no
5+
* declarations. This makes any header that relies on C11 atomics
6+
* (e.g. mimalloc) unparseable by bindgen.
7+
*
8+
* This file provides the standard C11 atomics API with non-atomic stubs.
9+
* Bindgen only needs correct type layouts -- it never executes atomic
10+
* operations -- so plain loads/stores are sufficient.
11+
*
12+
* The build script adds this directory via -isystem so it shadows a
13+
* broken system header while remaining invisible when the real header
14+
* works (libclang picks whichever it finds first on the include path).
15+
*/
16+
#ifndef _STDATOMIC_BINDGEN_FALLBACK_H
17+
#define _STDATOMIC_BINDGEN_FALLBACK_H
18+
19+
/* Strip _Atomic qualifier -- bindgen cares about layout, not atomicity. */
20+
#define _Atomic(tp) tp
21+
22+
typedef enum {
23+
memory_order_relaxed,
24+
memory_order_consume,
25+
memory_order_acquire,
26+
memory_order_release,
27+
memory_order_acq_rel,
28+
memory_order_seq_cst
29+
} memory_order;
30+
31+
#define ATOMIC_VAR_INIT(value) (value)
32+
33+
#define atomic_load_explicit(p, mo) (*(p))
34+
#define atomic_store_explicit(p, v, mo) ((void)(*(p) = (v)))
35+
#define atomic_fetch_add_explicit(p, v, mo) (*(p))
36+
#define atomic_fetch_sub_explicit(p, v, mo) (*(p))
37+
#define atomic_fetch_or_explicit(p, v, mo) (*(p))
38+
#define atomic_fetch_and_explicit(p, v, mo) (*(p))
39+
#define atomic_compare_exchange_weak_explicit(p, e, d, s, f) 1
40+
#define atomic_compare_exchange_strong_explicit(p, e, d, s, f) 1
41+
#define atomic_exchange_explicit(p, v, mo) (*(p))
42+
#define atomic_thread_fence(mo) ((void)0)
43+
44+
#endif /* _STDATOMIC_BINDGEN_FALLBACK_H */

Modules/cpython-sys/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ fn generate_c_api_bindings(srcdir: &Path, builddir: Option<&str>, out_path: &Pat
150150
for dir in include_dirs {
151151
builder = builder.clang_arg(format!("-I{}", dir.display()));
152152
}
153+
154+
// Provide a fallback <stdatomic.h> for libclang versions that ship a
155+
// broken one (e.g. libclang-18 on Ubuntu 24.04). Using -isystem places
156+
// it after -I paths but before the default system headers, so it only
157+
// takes effect when the real <stdatomic.h> is unusable.
158+
let fallback_dir = manifest_dir.join("bindgen-fallback");
159+
builder = builder.clang_arg(format!("-isystem{}", fallback_dir.display()));
160+
153161
builder = add_target_clang_args(builder, builddir);
154162

155163
let bindings = builder

0 commit comments

Comments
 (0)