Skip to content

Commit 0050677

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 17be90d commit 0050677

File tree

35 files changed

+39
-63
lines changed

35 files changed

+39
-63
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

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

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

300300
- name: Build iwasm for android
301301
if: matrix.platform == 'android'
302302
run: |
303303
mkdir build && cd build
304-
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
304+
cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
305305
-DWAMR_BUILD_TARGET=X86_64
306306
cmake --build . --config Release --parallel 4
307307
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

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

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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(
11+
-Wall -Wextra -Wformat -Wformat-security
12+
$<$<COMPILE_LANGUAGE:C>:-Wshadow>
13+
)
14+
# -pedantic causes warnings like "ISO C forbids initialization between function pointer and ‘void *’" which
15+
# is widely used in the codebase.
16+
#
17+
# -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C"
18+
#
19+
add_compile_options (
20+
$<$<COMPILE_LANGUAGE:C>:-Wincompatible-pointer-types>
21+
$<$<COMPILE_LANGUAGE:C>:-Wimplicit-function-declaration>
22+
)
23+
# waivers
24+
add_compile_options (
25+
-Wno-unused
26+
-Wno-unused-parameter
27+
)
28+
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)