Skip to content

Commit 523cf6b

Browse files
cursoragentlovasoa
andcommitted
Add ASAN CI job and documentation
Co-authored-by: contact <[email protected]>
1 parent f137561 commit 523cf6b

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ jobs:
3838
name: sqlpage-linux-debug
3939
path: "target/debug/sqlpage"
4040

41+
test_asan:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Install clang for ASAN
46+
run: sudo apt-get update && sudo apt-get install -y clang
47+
- name: Set up cargo cache
48+
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6
49+
- name: Build with ASAN-instrumented C dependencies
50+
env:
51+
CFLAGS: "-fsanitize=address -fno-omit-frame-pointer -g"
52+
CXXFLAGS: "-fsanitize=address -fno-omit-frame-pointer -g"
53+
CC: clang
54+
CXX: clang++
55+
run: cargo build --features odbc-static
56+
- name: Run tests with ASAN
57+
env:
58+
ASAN_OPTIONS: "detect_leaks=1:abort_on_error=1"
59+
CFLAGS: "-fsanitize=address -fno-omit-frame-pointer -g"
60+
CXXFLAGS: "-fsanitize=address -fno-omit-frame-pointer -g"
61+
CC: clang
62+
CXX: clang++
63+
run: cargo test --features odbc-static --no-fail-fast
64+
4165
test:
4266
runs-on: ubuntu-latest
4367
strategy:

ASAN-NOTES.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Address Sanitizer (ASAN) Configuration
2+
3+
## C Dependencies with ASAN
4+
5+
This project successfully compiles C dependencies with ASAN enabled:
6+
- aws-lc-sys (AWS-LC crypto library)
7+
- libsqlite3-sys (SQLite)
8+
- zstd-sys (Zstandard compression)
9+
- unix-odbc (when using odbc-static feature)
10+
11+
### Configuration
12+
13+
The C dependencies are compiled with ASAN using these environment variables:
14+
```bash
15+
export CFLAGS="-fsanitize=address -fno-omit-frame-pointer -g"
16+
export CXXFLAGS="-fsanitize=address -fno-omit-frame-pointer -g"
17+
export CC=clang
18+
export CXX=clang++
19+
```
20+
21+
A custom linker wrapper ensures ASAN runtime is linked:
22+
```bash
23+
#!/bin/bash
24+
exec clang -fsanitize=address "$@"
25+
```
26+
27+
### Known Limitation: Proc-Macros with `-Zbuild-std`
28+
29+
Enabling full Rust ASAN (`-Zsanitizer=address`) with `-Zbuild-std` causes issues with proc-macro crates.
30+
The sqlx-oldapi dependency uses sqlx-macros-oldapi (a proc-macro), which cannot be loaded when
31+
the standard library is rebuilt with ASAN.
32+
33+
## Workaround for Testing
34+
35+
For CI/testing purposes, we can:
36+
1. Compile C dependencies with ASAN only (catches memory issues in native code)
37+
2. Run tests with ASAN enabled to detect memory errors
38+
3. Use LeakSanitizer (LSAN) in addition to catch memory leaks
39+
40+
This provides significant value as the C dependencies are where most memory safety issues occur.

Cargo.lock

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)