Skip to content

Commit 2f352bc

Browse files
authored
Add -Werror CI job (#1845)
* Remove commented out directives from top-level CMakeLists * Use add_compiler_options instead of some weird helper in CMake * Suppress CMake policy version warning from Abseil We really should update it. * Suppress existing warnings This is not particularly precise as I disabled warnings on file level (and warning suppression mappings allow specifying function scope) but is good enough to add -Werror CI job in next commit. * Add -Werror CI job
1 parent 2aed6e4 commit 2f352bc

File tree

4 files changed

+213
-138
lines changed

4 files changed

+213
-138
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Ubuntu TON -Werror build (shared, x86-64)
2+
3+
on: [push, pull_request, workflow_dispatch, workflow_call]
4+
5+
jobs:
6+
build:
7+
if: github.repository == 'ton-blockchain/ton'
8+
9+
runs-on: ubuntu-24.04
10+
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v3
14+
with:
15+
submodules: 'recursive'
16+
17+
- name: Date Stamp
18+
shell: bash
19+
id: date-stamp
20+
run: |
21+
echo "timestamp=$(date -u "+%Y%m%d%H%M_%S")" >> "$GITHUB_OUTPUT"
22+
23+
- name: Install system libraries
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y build-essential git cmake ninja-build zlib1g-dev libsecp256k1-dev libmicrohttpd-dev libsodium-dev liblz4-dev libjemalloc-dev
27+
28+
- name: Install Clang 21
29+
run: |
30+
wget https://apt.llvm.org/llvm.sh
31+
chmod +x llvm.sh
32+
sudo ./llvm.sh 21 clang
33+
34+
# TODO: Preserve ccache cache between runs once we get rid of warning suppression mappings.
35+
36+
- name: Build TON
37+
run: |
38+
cmake -S . -B build -G Ninja \
39+
-DCMAKE_C_COMPILER=clang-21 \
40+
-DCMAKE_CXX_COMPILER=clang++-21 \
41+
-DCMAKE_BUILD_TYPE=Release \
42+
-DTON_USE_JEMALLOC=ON \
43+
-DTON_USE_LLD=On \
44+
-DTON_WERROR_BUILD=On
45+
ninja -C build

CMake/AddCXXCompilerFlag.cmake

Lines changed: 0 additions & 74 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
22

33
project(TON VERSION 0.5 LANGUAGES C CXX)
44
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
5-
#set(OPENSSL_USE_STATIC_LIBS TRUE)
65

76
# Define the two required variables before including the source code for watching a git repository.
87
set(PRE_CONFIGURE_FILE "git.cc.in")
@@ -35,6 +34,16 @@ set(CMAKE_CXX_EXTENSIONS FALSE)
3534

3635
set(CMAKE_COLOR_DIAGNOSTICS TRUE)
3736

37+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
38+
set(GCC 1)
39+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
40+
set(CLANG 1)
41+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
42+
set(INTEL 1)
43+
elseif (NOT MSVC)
44+
message(FATAL_ERROR "Compiler isn't supported")
45+
endif()
46+
3847
#BEGIN internal
3948
option(BUILD_SHARED_LIBS "Use \"ON\" to build shared libraries instead of static where it's not specified (not recommended)" OFF)
4049
option(USE_EMSCRIPTEN "Use \"ON\" for config building wasm." OFF)
@@ -77,16 +86,29 @@ if ((ARCHITECTURE MATCHES "arm64") AND (CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND
7786
endif()
7887
#END M1 support
7988

89+
if (CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "20")
90+
add_compile_options(--warning-suppression-mappings=${CMAKE_SOURCE_DIR}/suppression_mappings.txt)
91+
endif()
92+
93+
option(TON_WERROR_BUILD "Use -Werror" OFF)
94+
95+
# If we want to check -Werror build in CI, we want to use it for third party projects as well but we
96+
# don't want to force our warning options on them.
97+
if (TON_WERROR_BUILD)
98+
add_compile_options(-Werror)
99+
endif()
100+
80101
if (TON_USE_ABSEIL)
81102
message("Add abseil-cpp")
82-
set(ABSL_PROPAGATE_CXX_STD TRUE)
83-
add_subdirectory(third-party/abseil-cpp EXCLUDE_FROM_ALL)
103+
function(abseil_scope)
104+
set(ABSL_PROPAGATE_CXX_STD TRUE)
105+
set(CMAKE_POLICY_VERSION_MINIMUM "3.10")
106+
add_subdirectory(third-party/abseil-cpp EXCLUDE_FROM_ALL)
107+
endfunction()
108+
abseil_scope()
84109
set(ABSL_FOUND 1)
85110
endif()
86111

87-
#add_subdirectory(third-party/libcuckoo EXCLUDE_FROM_ALL)
88-
#add_subdirectory(third-party/junction EXCLUDE_FROM_ALL)
89-
90112
if (WIN32)
91113
message("Add wingetopt")
92114
function(wingetopt_scope)
@@ -166,16 +188,6 @@ else()
166188
message(STATUS "Could NOT find ccache")
167189
endif()
168190

169-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
170-
set(GCC 1)
171-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
172-
set(CLANG 1)
173-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
174-
set(INTEL 1)
175-
elseif (NOT MSVC)
176-
message(FATAL_ERROR "Compiler isn't supported")
177-
endif()
178-
179191
include(CheckCXXCompilerFlag)
180192

181193
set(CMAKE_THREAD_PREFER_PTHREAD ON)
@@ -282,33 +294,37 @@ set(TONLIB_COMPILE "0")
282294
set(TONLIB_COMPILE "1")
283295
#END tonlib
284296

285-
include(AddCXXCompilerFlag)
286297
if (MSVC)
287-
add_cxx_compiler_flag("/experimental:external /external:anglebrackets /external:W0")
288-
endif()
289-
if (NOT MSVC)
290-
add_cxx_compiler_flag("-Wall")
291-
add_cxx_compiler_flag("-Wextra")
292-
endif()
293-
294-
add_cxx_compiler_flag("-Wimplicit-fallthrough=2")
295-
add_cxx_compiler_flag("-Wpointer-arith")
296-
add_cxx_compiler_flag("-Wcast-qual")
297-
add_cxx_compiler_flag("-Wsign-compare")
298-
add_cxx_compiler_flag("-Wduplicated-branches")
299-
add_cxx_compiler_flag("-Wduplicated-cond")
300-
add_cxx_compiler_flag("-Walloc-zero")
301-
add_cxx_compiler_flag("-Wlogical-op")
302-
add_cxx_compiler_flag("-Wno-tautological-compare")
303-
add_cxx_compiler_flag("-Wpointer-arith")
304-
add_cxx_compiler_flag("-Wvla")
305-
add_cxx_compiler_flag("-Wnon-virtual-dtor")
306-
add_cxx_compiler_flag("-Wno-unused-parameter")
307-
add_cxx_compiler_flag("-Wconversion")
308-
add_cxx_compiler_flag("-Wno-sign-conversion")
309-
add_cxx_compiler_flag("-Qunused-arguments")
310-
add_cxx_compiler_flag("-Wno-unused-private-field")
311-
add_cxx_compiler_flag("-Wno-redundant-move")
298+
add_compile_options(/experimental:external /external:anglebrackets /external:W0)
299+
endif()
300+
301+
if (GCC OR CLANG)
302+
add_compile_options(-Wall)
303+
add_compile_options(-Wextra)
304+
305+
add_compile_options(-Wpointer-arith)
306+
add_compile_options(-Wcast-qual)
307+
add_compile_options(-Wsign-compare)
308+
add_compile_options(-Wpointer-arith)
309+
add_compile_options(-Wvla)
310+
add_compile_options(-Wnon-virtual-dtor)
311+
add_compile_options(-Wconversion)
312+
313+
# TODO: Either justify all of these or remove.
314+
add_compile_options(-Wno-tautological-compare)
315+
add_compile_options(-Wno-unused-parameter)
316+
add_compile_options(-Wno-sign-conversion)
317+
add_compile_options(-Wno-unused-private-field)
318+
add_compile_options(-Wno-redundant-move)
319+
320+
if (GCC)
321+
add_compile_options(-Wimplicit-fallthrough=2)
322+
add_compile_options(-Wduplicated-branches)
323+
add_compile_options(-Wduplicated-cond)
324+
add_compile_options(-Walloc-zero)
325+
add_compile_options(-Wlogical-op)
326+
endif()
327+
endif()
312328

313329
if (GCC OR CLANG)
314330
if (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
@@ -318,30 +334,19 @@ if (GCC OR CLANG)
318334
endif()
319335
endif()
320336

321-
#add_cxx_compiler_flag("-Wno-unused-function")
322-
#add_cxx_compiler_flag("-Wno-unused-variable")
323-
#add_cxx_compiler_flag("-Wno-shorten-64-to-32")
324-
#add_cxx_compiler_flag("-Werror")
325-
326-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/include/c++/v1")
327-
if (CLANG)
328-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
329-
endif()
330337
if (TON_USE_ASAN)
331-
add_cxx_compiler_flag("-fsanitize=address")
338+
add_compile_options(-fsanitize=address)
339+
add_link_options(-fsanitize=address)
332340
add_definitions(-DTD_USE_ASAN=1)
333341
endif()
334342
if (TON_USE_TSAN)
335-
add_cxx_compiler_flag("-fsanitize=thread")
343+
add_compile_options(-fsanitize=thread)
344+
add_link_options(-fsanitize=thread)
336345
endif()
337346
if (TON_USE_UBSAN)
338-
add_cxx_compiler_flag("-fsanitize=undefined")
347+
add_compile_options(-fsanitize=undefined)
348+
add_link_options(-fsanitize=undefined)
339349
endif()
340-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
341-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
342-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
343-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
344-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finstrument-functions")
345350

346351
#Compilation database
347352
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
@@ -451,10 +456,6 @@ target_link_libraries(test-fift PRIVATE fift-lib)
451456

452457
add_executable(test-tdutils test/test-td-main.cpp ${TDUTILS_TEST_SOURCE})
453458
target_link_libraries(test-tdutils PRIVATE tdutils ${CMAKE_THREAD_LIBS_INIT} memprof ${JEMALLOC_LIBRARIES})
454-
#target_link_libraries_system(test-tdutils absl::base absl::container absl::hash )
455-
#target_link_libraries_system(test-tdutils libcuckoo)
456-
#target_include_directories(test-tdutils PRIVATE SYSTEM ${JUNCTION_ALL_INCLUDE_DIRS})
457-
#target_link_libraries(test-tdutils PRIVATE ${JUNCTION_ALL_LIBRARIES})
458459

459460
add_executable(test-tdactor test/test-td-main.cpp ${TDACTOR_TEST_SOURCE})
460461
target_link_libraries(test-tdactor PRIVATE tdactor ${CMAKE_THREAD_LIBS_INIT})
@@ -535,7 +536,7 @@ if (HAS_PARENT)
535536
${ED25519_TEST_SOURCE}
536537
${TONDB_TEST_SOURCE}
537538
${BIGNUM_TEST_SOURCE}
538-
${CELLS_TEST_SOURCE} # ${TONVM_TEST_SOURCE} ${FIFT_TEST_SOURCE} ${TONLIB_ONLINE_TEST_SOURCE}
539+
${CELLS_TEST_SOURCE}
539540
PARENT_SCOPE)
540541
endif()
541542
add_library(all_tests INTERFACE)

0 commit comments

Comments
 (0)