Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation fails with C++20 on emscripten's toolchain #4218

Closed
Floris0106 opened this issue Oct 27, 2024 · 3 comments
Closed

Compilation fails with C++20 on emscripten's toolchain #4218

Floris0106 opened this issue Oct 27, 2024 · 3 comments
Labels

Comments

@Floris0106
Copy link

Floris0106 commented Oct 27, 2024

When compiling fmt using emscripten's CMake toolchain file (obtained through the emsdk) with the following errors:

error: call to consteval function 'fmt::basic_format_string<char, const char *>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, const char *>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, int &, int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, fmt::basic_string_view<char> &, const char (&)[3]>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, const char (&)[7], int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, unsigned int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, unsigned int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression
error: call to consteval function 'fmt::basic_format_string<char, int>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression

I'm able to reproduce this issue with the latest versions of emsdk (3.1.70) and fmt (11.0.2). I used the following CMakePresets.json:

{
	"version": 1,
	"configurePresets": [
		{
			"name": "Emscripten",
			"generator": "Ninja",
			"toolchainFile": "$env{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
		}
	]
}

Here EMSDK is an environment variable that points to the root directory of the emsdk. CMakeLists.txt:

include(FetchContent)

project(Test)

set(CMAKE_CXX_STANDARD 20)

FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 11.0.2 DOWNLOAD_EXTRACT_TIMESTAMP true)
FetchContent_MakeAvailable(fmt)

I'm not sure whether this is an issue with fmt or emscripten, so I've made an issue on the emscripten repository as well. (see here)

@tchaikov
Copy link
Contributor

tchaikov commented Oct 28, 2024

@Floris0106 i think it's fixed by #4187. but if you want to build with fmt 11.0.2, the patch might not apply cleanly. i'd suggest use the patch at https://src.fedoraproject.org/rpms/fmt/c/8da7a020a557972c246e4b8c927c3108c492e83c?branch=rawhide which contains a backport to 11.0.2.

@Floris0106
Copy link
Author

Floris0106 commented Oct 29, 2024

I don't know if I'm doing something wrong, but the fedora repo only gives me some source and patch files, both using FetchContent and when manually cloning. Anyway, I'll close this since it's fixed in 22701d5 (which is what I'm using now).

@tchaikov
Copy link
Contributor

@Floris0106 for applying a patch when using FetchContent_Declare() you might want to use PATCH_COMMAND like

FetchContent_Declare(fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG 11.0.2
  PATCH_COMMAND git apply --ignore-whitespace "${CMAKE_CURRENT_LIST_DIR}/path-to-patch.patch"
  DOWNLOAD_EXTRACT_TIMESTAMP true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants