Skip to content

Commit 92e2d07

Browse files
committed
Enable AddressSanitizer for rustc in CI
Just running AddressSanitizer may not be enough; it needs to be explicitly enabled for Rust in addition to C++. External resources: * https://rustc-dev-guide.rust-lang.org/sanitizers.html#how-to-use-the-sanitizers * https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html
1 parent 50e1401 commit 92e2d07

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

.github/composite/godot-itest/action.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ inputs:
4545
default: ''
4646
description: "Extra values for the RUSTFLAGS env var"
4747

48+
rust-target:
49+
required: false
50+
default: ''
51+
description: "If provided, acts as an argument for '--target', and results in output files written to ./target/{target}"
52+
4853
with-llvm:
4954
required: false
5055
default: ''
@@ -118,11 +123,23 @@ runs:
118123
shell: bash
119124

120125
- name: "Build gdext (itest)"
121-
run: |
122-
cargo build -p itest ${{ inputs.rust-extra-args }}
123-
shell: bash
124126
env:
125127
RUSTFLAGS: ${{ inputs.rust-env-rustflags }}
128+
TARGET: ${{ inputs.rust-target }}
129+
run: |
130+
targetArgs=""
131+
if [[ -n "$TARGET" ]]; then
132+
targetArgs="--target $TARGET"
133+
fi
134+
135+
cargo build -p itest ${{ inputs.rust-extra-args }} $targetArgs
136+
137+
# Instead of modifying .gdextension, rename the output directory
138+
if [[ -n "$TARGET" ]]; then
139+
rm -rf target/debug
140+
mv target/$TARGET/debug target
141+
fi
142+
shell: bash
126143

127144
# This step no longer fails if there's a diff, as we expect header to be forward-compatible; instead issues a warning
128145
# However, still fails if patch cannot be applied (conflict).

.github/composite/rust/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ runs:
3131
steps:
3232
- name: "Configure"
3333
id: configure
34+
env:
35+
CS: ${{ inputs.components }}
3436
run: |
3537
echo "Rust cache shared-key: '${{ runner.os }}-${{ inputs.rust }}${{ inputs.cache-key }}'"
36-
echo "components=$( for c in ${cs//,/ }; do echo -n ' --component' $c; done )" >> $GITHUB_OUTPUT
37-
env:
38-
cs: ${{ inputs.components }}
38+
echo "components=$( for c in ${CS//,/ }; do echo -n ' --component' $c; done )" >> $GITHUB_OUTPUT
3939
shell: bash
4040

4141
- name: "Rustup"

.github/workflows/full-ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,22 @@ jobs:
202202
godot-prebuilt-patch: '4.1'
203203

204204
# Special Godot binaries compiled with AddressSanitizer/LeakSanitizer to detect UB/leaks.
205+
# See also https://rustc-dev-guide.rust-lang.org/sanitizers.html.
206+
#
205207
# Additionally, the Godot source is patched to make dlclose() a no-op, as unloading dynamic libraries loses stacktrace and
206208
# cause false positives like println!. See https://github.com/google/sanitizers/issues/89.
207-
# The gcc version can possibly be removed later, as it is slower and needs a larger artifact than the clang one.
209+
#
210+
# There is also a gcc variant besides clang, which is currently not used.
208211
- name: linux-memcheck-nightly
209212
os: ubuntu-20.04
210213
artifact-name: linux-memcheck-clang-nightly
211214
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
212215
godot-args: -- --disallow-focus
213216
rust-toolchain: nightly
214-
rust-env-rustflags: -Zrandomize-layout
217+
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
215218
rust-extra-args: --features godot/custom-godot
219+
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
220+
rust-target: x86_64-unknown-linux-gnu
216221
godot-prebuilt-patch: '4.1'
217222

218223
# Linux under Godot 4.0.x
@@ -246,8 +251,9 @@ jobs:
246251
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
247252
godot-args: -- --disallow-focus
248253
rust-toolchain: nightly
249-
rust-env-rustflags: -Zrandomize-layout
250-
254+
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
255+
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
256+
rust-target: x86_64-unknown-linux-gnu
251257

252258
steps:
253259
- uses: actions/checkout@v3
@@ -262,6 +268,7 @@ jobs:
262268
rust-extra-args: ${{ matrix.rust-extra-args }}
263269
rust-toolchain: ${{ matrix.rust-toolchain || 'stable' }}
264270
rust-env-rustflags: ${{ matrix.rust-env-rustflags }}
271+
rust-target: ${{ matrix.rust-target }}
265272
with-llvm: ${{ contains(matrix.name, 'macos') && contains(matrix.rust-extra-args, 'custom-godot') }}
266273
godot-check-header: ${{ matrix.godot-check-header }}
267274

0 commit comments

Comments
 (0)