Skip to content

Commit 3eaf5a9

Browse files
committed
Turn warnings into errors in CI
- Apply global warnings in warnings.cmake instead of maintaining them in separate files. - Enable errors during CI when building iwasm and wamrc. - Since GCC and Clang are the default compilers on Ubuntu and macOS, enabling `-Werror` on both platforms can be treated as checking with different compilers.
1 parent 38fe056 commit 3eaf5a9

File tree

35 files changed

+46
-63
lines changed

35 files changed

+46
-63
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
- name: Build wamrc
124124
run: |
125125
mkdir build && cd build
126-
cmake ..
126+
cmake .. -DCMAKE_C_FLAGS="-Werror"
127127
cmake --build . --config Release --parallel 4
128128
working-directory: wamr-compiler
129129

@@ -291,15 +291,15 @@ jobs:
291291
if: matrix.platform == 'linux'
292292
run: |
293293
mkdir build && cd build
294-
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
294+
cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
295295
cmake --build . --config Release --parallel 4
296296
working-directory: product-mini/platforms/${{ matrix.platform }}
297297

298298
- name: Build iwasm for android
299299
if: matrix.platform == 'android'
300300
run: |
301301
mkdir build && cd build
302-
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
302+
cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
303303
-DWAMR_BUILD_TARGET=X86_64
304304
cmake --build . --config Release --parallel 4
305305
working-directory: product-mini/platforms/${{ matrix.platform }}

.github/workflows/compilation_on_macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
- name: Build wamrc
108108
run: |
109109
mkdir build && cd build
110-
cmake ..
110+
cmake .. -DCMAKE_C_FLAGS="-Werror"
111111
cmake --build . --config Release --parallel 4
112112
working-directory: wamr-compiler
113113

@@ -212,7 +212,7 @@ jobs:
212212
- name: Build iwasm
213213
run: |
214214
mkdir build && cd build
215-
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
215+
cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
216216
cmake --build . --config Release --parallel 4
217217
working-directory: product-mini/platforms/${{ matrix.platform }}
218218

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
126126
if (NOT WIN32)
127127
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \
128128
-ffunction-sections -fdata-sections \
129-
-Wno-unused-parameter -Wno-pedantic \
130129
-fvisibility=hidden")
131130
# Remove the extra spaces for better make log
132131
string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
133-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
134132
endif()
135133

136134
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")

build-scripts/config_common.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
8181
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb")
8282
endif ()
8383

84+
include (${CMAKE_CURRENT_LIST_DIR}/warnings.cmake)
85+
8486
if (NOT WAMR_BUILD_INTERP EQUAL 1)
8587
if (NOT WAMR_BUILD_AOT EQUAL 1)
8688
message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one")

build-scripts/runtime_lib.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ endif ()
162162

163163
####################### Common sources #######################
164164
if (NOT MSVC)
165-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
166-
-Wall -Wno-unused-parameter -Wno-pedantic")
165+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections")
167166
endif ()
168167

169168
# include the build config template file

build-scripts/warnings.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
# global additional warnings. Keep those options consistent with wamr-compiler/CMakeLists.txt.
5+
if (MSVC)
6+
# warning level 4
7+
add_compile_options(/W4)
8+
else ()
9+
# refer to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
10+
add_compile_options(-Wall -Wextra -Wformat -Wformat-security -Wshadow)
11+
# -pedantic causes warnings like "ISO C forbids initialization between function pointer and ‘void *’" which
12+
# is widely used in the codebase.
13+
#
14+
# -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C"
15+
#
16+
# _Static_assert and _Alignof requires c11 or later
17+
#
18+
#
19+
add_compile_options (
20+
-Wimplicit-function-declaration
21+
-Wincompatible-pointer-types
22+
)
23+
# waivers
24+
add_compile_options (
25+
-Wno-unused
26+
-Wno-unused-parameter
27+
)
28+
29+
if (WAMR_BUILD_JIT EQUAL 1)
30+
# Friendly fire on LLVM libraries.
31+
add_compile_options (
32+
-Wno-error=shadow
33+
)
34+
endif ()
35+
endif ()

product-mini/platforms/android/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ set_version_info (vmlib)
111111

112112
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
113113

114-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
115-
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
116-
117114
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
118115
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
119116
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")

product-mini/platforms/cosmopolitan/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ set_version_info (vmlib)
136136

137137
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
138138

139-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow")
140-
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
141-
142-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
143-
144139
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
145140
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
146141
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")

product-mini/platforms/ios/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
113113

114114
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
115115

116-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
117-
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
118-
119116
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
120117
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
121118
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")

product-mini/platforms/linux/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ check_pie_supported()
139139

140140
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
141141

142-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow")
143-
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
144-
145-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
146-
147142
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
148143
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
149144
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")

0 commit comments

Comments
 (0)