Skip to content

Commit ffcebb7

Browse files
authored
[cmake] Run normal compiler auto-detection by default (#23537)
This change disables `EMSCRIPTEN_FORCE_COMPILERS` by default which means cmake will run all the normal compiler detection phases. This has the advantage that things get setup correctly without taking any shortcuts. See #23444. The downside is the that cmake phase itself is now slower since its needs to compiler, link and run a bunch of test binaries. On my machine running all the cmake tests went from 27 to 36 seconds. Running a single empty cmake project when from 1s to 4.5s. Since running cmake is normally rare compared to building the project itself I think this slowdown is worth it, but I've left the `EMSCRIPTEN_FORCE_COMPILERS` setting in place for now that folks that want fast cmake. Also, remember that cmake itself caches all this stuff so its only the first run that get slowed down.
1 parent 1b46dde commit ffcebb7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ See docs/process.md for more on how version tagging works.
3434
- The system JS libraries in `src/` were renamed from `library_foo.js` to
3535
`lib/libfoo.js`. They are still included via the same `-lfoo.js` flag so
3636
this should not be a user-visible change. (#23348)
37+
- When using cmake the emscripten toolchain will no longer skip the toolchain
38+
detection stages. This means the initial cmake run will be slower, but will
39+
result in more accruate information. If cmake is running too slow for you,
40+
you can revert to the previous behaviour with `-DEMSCRIPTEN_FORCE_COMPILERS=ON`.
3741

3842
4.0.1 - 01/17/25
3943
----------------

cmake/Modules/Platform/Emscripten.cmake

+3-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ endif()
120120
file(TO_CMAKE_PATH "${_emcache_output}" _emcache_output)
121121
set(EMSCRIPTEN_SYSROOT "${_emcache_output}/sysroot")
122122

123-
# Don't allow CMake to autodetect the compiler, since this is quite slow with
124-
# Emscripten.
125-
# Pass -DEMSCRIPTEN_FORCE_COMPILERS=OFF to disable (sensible mostly only for
126-
# testing/debugging purposes).
127-
option(EMSCRIPTEN_FORCE_COMPILERS "Force C/C++ compiler" ON)
123+
# Allow skipping of CMake compiler autodetection, since this is quite slow with
124+
# Emscripten. Pass -DEMSCRIPTEN_FORCE_COMPILERS=ON to enable
125+
option(EMSCRIPTEN_FORCE_COMPILERS "Force C/C++ compiler" OFF)
128126
if (EMSCRIPTEN_FORCE_COMPILERS)
129127

130128
# Detect version of the 'emcc' executable. Note that for CMake, we tell it the

test/test_other.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,11 @@ def test_cmake(self, test_dir, output_file, cmake_args):
966966
# If we update LLVM version and this test fails, copy over the new advertised features from Clang
967967
# and place them to cmake/Modules/Platform/Emscripten.cmake.
968968
@no_windows('Skipped on Windows because CMake does not configure native Clang builds well on Windows.')
969-
def test_cmake_compile_features(self):
969+
@parameterized({
970+
'': ([],),
971+
'force': (['-DEMSCRIPTEN_FORCE_COMPILERS=ON'],),
972+
})
973+
def test_cmake_compile_features(self, args):
970974
os.mkdir('build_native')
971975
cmd = ['cmake',
972976
'-DCMAKE_C_COMPILER=' + CLANG_CC, '-DCMAKE_C_FLAGS=--target=' + clang_native.get_native_triple(),
@@ -976,7 +980,7 @@ def test_cmake_compile_features(self):
976980
native_features = self.run_process(cmd, stdout=PIPE, cwd='build_native').stdout
977981

978982
os.mkdir('build_emcc')
979-
cmd = [EMCMAKE, 'cmake', test_file('cmake/stdproperty')]
983+
cmd = [EMCMAKE, 'cmake', test_file('cmake/stdproperty')] + args
980984
print(str(cmd))
981985
emscripten_features = self.run_process(cmd, stdout=PIPE, cwd='build_emcc').stdout
982986

@@ -1023,7 +1027,7 @@ def test_cmake_bitcode_static_libraries(self):
10231027
@crossplatform
10241028
@parameterized({
10251029
'': ([],),
1026-
'noforce': (['-DEMSCRIPTEN_FORCE_COMPILERS=OFF'],),
1030+
'force': (['-DEMSCRIPTEN_FORCE_COMPILERS=ON'],),
10271031
})
10281032
def test_cmake_compile_commands(self, args):
10291033
self.run_process([EMCMAKE, 'cmake', test_file('cmake/static_lib'), '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'] + args)

0 commit comments

Comments
 (0)