Skip to content

Commit 557d7ea

Browse files
committed
feat(ci): Add ASAN and UBSAN build and CI job
1 parent 3debc3b commit 557d7ea

File tree

5 files changed

+146
-2
lines changed

5 files changed

+146
-2
lines changed

.github/workflows/linux-build-base.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,111 @@ jobs:
270270
with:
271271
path: ${{ env.CCACHE_DIR }}
272272
key: ccache-fedora-debug-default-gcc
273+
274+
asan-ubsan-adapters:
275+
name: Linux debug with adapters - testing asan and ubsan
276+
# prevent errors when forks ff their main branch
277+
if: ${{ github.repository == 'facebookincubator/velox' }}
278+
runs-on: ubuntu-latest
279+
container:
280+
image: ghcr.io/facebookincubator/velox-dev:adapters
281+
volumes:
282+
- /usr:/host_usr
283+
- /opt:/host_opt
284+
defaults:
285+
run:
286+
shell: bash
287+
env:
288+
CCACHE_DIR: ${{ github.workspace }}/ccache
289+
VELOX_DEPENDENCY_SOURCE: SYSTEM
290+
faiss_SOURCE: BUNDLED
291+
concurrency:
292+
group: ${{ github.workflow }}-asan-ubsan-adapters-${{ github.event.pull_request.number }}
293+
cancel-in-progress: true
294+
steps:
295+
- name: Free Disk Space
296+
run: |
297+
# Re-used from free-disk-space github action.
298+
getAvailableSpace() { echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}'); }
299+
# Show before
300+
echo "Original available disk space: " $(getAvailableSpace)
301+
# Remove DotNet.
302+
rm -rf /host_usr/share/dotnet || true
303+
# Remove android
304+
rm -rf /host_usr/local/lib/android || true
305+
# Remove CodeQL
306+
rm -rf /host_opt/hostedtoolcache/CodeQL || true
307+
# Show after
308+
echo "New available disk space: " $(getAvailableSpace)
309+
310+
- uses: actions/checkout@v5
311+
with:
312+
fetch-depth: 2
313+
persist-credentials: false
314+
315+
- name: Fix git permissions
316+
# Usually actions/checkout does this but as we run in a container
317+
# it doesn't work
318+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
319+
320+
- uses: apache/infrastructure-actions/stash/restore@3354c1565d4b0e335b78a76aedd82153a9e144d4
321+
with:
322+
path: ${{ env.CCACHE_DIR }}
323+
key: ccache-asan-ubsan-adapters
324+
325+
- name: Zero Ccache Statistics
326+
run: |
327+
ccache -sz
328+
329+
- name: Make Debug Build
330+
env:
331+
MAKEFLAGS: NUM_THREADS=4 MAX_HIGH_MEM_JOBS=3 MAX_LINK_JOBS=3
332+
CUDA_VERSION: '12.8'
333+
CUDA_ARCHITECTURES: 70
334+
CUDA_COMPILER: /usr/local/cuda-${CUDA_VERSION}/bin/nvcc
335+
# Set compiler to GCC 12 for CUDA
336+
CUDA_FLAGS: -ccbin /opt/rh/gcc-toolset-12/root/usr/bin
337+
run: |
338+
EXTRA_CMAKE_FLAGS=(
339+
"-DVELOX_ENABLE_ASAN_UBSAN_SANITIZERS=ON"
340+
"-DVELOX_ENABLE_BENCHMARKS=ON"
341+
"-DVELOX_ENABLE_EXAMPLES=ON"
342+
"-DVELOX_ENABLE_ARROW=ON"
343+
"-DVELOX_ENABLE_GEO=ON"
344+
"-DVELOX_ENABLE_PARQUET=ON"
345+
"-DVELOX_ENABLE_HDFS=ON"
346+
"-DVELOX_ENABLE_S3=ON"
347+
"-DVELOX_ENABLE_GCS=ON"
348+
"-DVELOX_ENABLE_ABFS=ON"
349+
"-DVELOX_ENABLE_WAVE=ON"
350+
"-DVELOX_MONO_LIBRARY=ON"
351+
"-DVELOX_BUILD_SHARED=ON"
352+
"-DVELOX_ENABLE_REMOTE_FUNCTIONS=ON"
353+
)
354+
clang++ --version
355+
dnf install -y compiler-rt
356+
CC=clang CXX=clang++ make debug EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS[*]}"
357+
358+
- name: Ccache after
359+
run: ccache -s
360+
361+
- uses: apache/infrastructure-actions/stash/save@3354c1565d4b0e335b78a76aedd82153a9e144d4
362+
with:
363+
path: ${{ env.CCACHE_DIR }}
364+
key: ccache-asan-ubsan-adapters
365+
366+
- name: Run Tests
367+
env:
368+
LIBHDFS3_CONF: ${{ github.workspace }}/scripts/ci/hdfs-client.xml
369+
working-directory: _build/debug
370+
run: |
371+
# Can be removed after images are rebuild
372+
if [ -f "/opt/miniforge/etc/profile.d/conda.sh" ]; then
373+
source "/opt/miniforge/etc/profile.d/conda.sh"
374+
conda activate adapters
375+
fi
376+
# Needed for HADOOP 3.3.6 minicluster. Can remove after updating to 3.4.2.
377+
wget https://repo1.maven.org/maven2/org/mockito/mockito-core/2.23.4/mockito-core-2.23.4.jar -O /usr/local/hadoop/share/hadoop/mapreduce/mockito-core-2.23.4.jar
378+
379+
export CLASSPATH=`/usr/local/hadoop/bin/hdfs classpath --glob`
380+
ctest -j 4 --label-exclude cuda_driver --output-on-failure --no-tests=error

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ option(VELOX_ENABLE_FAISS "Build faiss vector search support" OFF)
179179
# is broken if you use ninja.
180180
option(VELOX_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF)
181181

182+
# Enable the address and undefined behavior sanitizers. They can run together.
183+
option(
184+
VELOX_ENABLE_ASAN_UBSAN_SANITIZERS
185+
"Builds velox with Clang ASAN and UBSAN sanitizer flags"
186+
OFF
187+
)
188+
182189
if(${VELOX_BUILD_MINIMAL} OR ${VELOX_BUILD_MINIMAL_WITH_DWIO})
183190
# Enable and disable components for velox base build
184191
set(VELOX_BUILD_TESTING OFF)
@@ -729,7 +736,23 @@ if("${TREAT_WARNINGS_AS_ERRORS}")
729736
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
730737
endif()
731738

739+
# Enable the ASAN and UBSAN sanitzers for Clang 20 and above.
740+
# Also only eligible with the type debug build.
741+
if(
742+
VELOX_ENABLE_ASAN_UBSAN_SANITIZERS
743+
AND CMAKE_BUILD_TYPE STREQUAL "Debug"
744+
AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
745+
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20
746+
)
747+
set(
748+
CMAKE_CXX_FLAGS
749+
"${CMAKE_CXX_FLAGS} -O1 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
750+
)
751+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=undefined")
752+
endif()
753+
732754
message("FINAL CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
755+
message("FINAL CMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}")
733756

734757
if(VELOX_ENABLE_ARROW)
735758
velox_set_source(Arrow)

scripts/setup-centos9.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function install_build_prerequisites {
5656
dnf config-manager --set-enabled crb
5757
dnf update -y
5858
fi
59-
dnf_install autoconf automake ccache clang gcc-toolset-12 gcc-toolset-14 git libtool \
59+
dnf_install autoconf automake ccache clang compiler-rt \
60+
gcc-toolset-12 gcc-toolset-14 git libtool \
6061
llvm ninja-build python3-pip python3-devel wget which
6162

6263
install_uv

velox/common/base/Macros.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
_Pragma("GCC diagnostic pop");
2929
#endif
3030

31+
#ifdef __clang__
32+
#define VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING \
33+
_Pragma("clang diagnostic push"); \
34+
_Pragma("clang diagnostic ignored \"-Wmissing-designated-field-initializers\"")
35+
#define VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING \
36+
_Pragma("clang diagnostic pop");
37+
#else
38+
#define VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
39+
#define VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
40+
#endif
41+
3142
#define VELOX_CONCAT(x, y) x##y
3243
// Need this extra layer to expand __COUNTER__.
3344
#define VELOX_VARNAME_IMPL(x, y) VELOX_CONCAT(x, y)

velox/functions/prestosql/DateTimeFunctions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,10 +1948,11 @@ struct ParseDurationFunction {
19481948
FOLLY_ALWAYS_INLINE void call(
19491949
out_type<IntervalDayTime>& result,
19501950
const arg_type<Varchar>& amountUnit) {
1951+
VELOX_SUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
19511952
static const LazyRE2 kDurationRegex{
19521953
.pattern_ = R"(^\s*(\d+(?:\.\d+)?)\s*([a-zA-Z]+)\s*$)",
1953-
.options_ = {},
19541954
};
1955+
VELOX_UNSUPPRESS_MISSING_DESIGNATED_FIELD_INITIALIZERS_WARNING
19551956
// TODO: Remove re2::StringPiece != std::string_view hacks.
19561957
// It's needed because for some systems in CI,
19571958
// re2 and abseil libraries are old.

0 commit comments

Comments
 (0)