Skip to content

Commit b58fb52

Browse files
committed
Optimize build size: disable RTTI
platform | before | after ----------------+--------+------ darwin-x64.node | 874K | 867K linux-x64.node | 872K | 857K win32-ia32.node | 541K | 536K win32-x64.node | 700K | 692K
1 parent 9fef214 commit b58fb52

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/workflows/build-website.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/checkout@v2
2323

2424
- name: C++ configure
25-
run: emcmake cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='-Os -flto' -DCMAKE_CXX_FLAGS='-Os -fno-rtti -fno-exceptions -flto'
25+
run: emcmake cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS='-Os -flto' -DCMAKE_CXX_FLAGS='-Os -fno-exceptions -flto'
2626
- name: C++ build
2727
run: emmake cmake --build build --target quick-lint-js-vscode quick-lint-js-vscode-licenses
2828
- name: C++ install

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ include(QuickLintJSCompiler)
4141
quick_lint_js_set_cxx_standard()
4242
quick_lint_js_enable_char8_t_if_supported()
4343
quick_lint_js_configure_exception_handling()
44+
quick_lint_js_configure_rtti()
4445
quick_lint_js_work_around_implicit_link_directories()
4546
quick_lint_js_enable_dead_code_stripping()
4647

cmake/QuickLintJSCompiler.cmake

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function (quick_lint_js_configure_exception_handling)
6868
endif ()
6969
endfunction ()
7070

71+
# RTTI stands for Run-Time Type Information.
72+
function (quick_lint_js_configure_rtti)
73+
quick_lint_js_add_cxx_flag_if_supported(-fno-rtti QUICK_LINT_JS_HAVE_FNO_RTTI)
74+
quick_lint_js_add_cxx_flag_if_supported(/GR- QUICK_LINT_JS_HAVE_GR_)
75+
endfunction ()
76+
7177
function (quick_lint_js_set_cxx_standard)
7278
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
7379
if (cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
@@ -195,13 +201,20 @@ function (quick_lint_js_have_charconv OUT_VAR)
195201
endfunction ()
196202

197203
function (quick_lint_js_add_c_cxx_flag_if_supported FLAG VAR)
198-
check_c_compiler_flag("${FLAG}" "${VAR}_C")
199-
if ("${${VAR}_C}")
204+
quick_lint_js_add_c_flag_if_supported("${FLAG}" "${VAR}_C")
205+
quick_lint_js_add_cxx_flag_if_supported("${FLAG}" "${VAR}_CXX")
206+
endfunction ()
207+
208+
function (quick_lint_js_add_c_flag_if_supported FLAG VAR)
209+
check_c_compiler_flag("${FLAG}" "${VAR}")
210+
if ("${${VAR}}")
200211
add_compile_options($<$<COMPILE_LANGUAGE:C>:${FLAG}>)
201212
endif ()
213+
endfunction ()
202214

203-
check_cxx_compiler_flag("${FLAG}" "${VAR}_CXX")
204-
if ("${${VAR}_CXX}")
215+
function (quick_lint_js_add_cxx_flag_if_supported FLAG VAR)
216+
check_cxx_compiler_flag("${FLAG}" "${VAR}")
217+
if ("${${VAR}}")
205218
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${FLAG}>)
206219
endif ()
207220
endfunction ()

0 commit comments

Comments
 (0)