Skip to content

Commit 9995400

Browse files
fix: patch WAMR win_file.c trailing backslashes that break Windows build
WAMR 2.4.4 win_file.c has three comments ending with backslash + trailing whitespace, which clang treats as line continuations, swallowing the next line of code and causing compile errors. Replace the previous -Wno-backslash-newline-escape workaround (which only suppressed the warning, not the parse error) with a proper git patch applied between FetchContent_Populate and add_subdirectory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b85c9fa commit 9995400

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

cmake/FetchWamr.cmake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ FetchContent_Declare(
2424
GIT_SHALLOW TRUE
2525
)
2626

27-
FetchContent_MakeAvailable(wamr)
27+
# Populate separately so we can patch before building
28+
FetchContent_GetProperties(wamr)
29+
if(NOT wamr_POPULATED)
30+
FetchContent_Populate(wamr)
2831

29-
# WAMR 2.4.4 win_file.c has trailing backslashes in comments that
30-
# clang treats as line continuations, causing compile errors.
31-
if(WIN32)
32-
target_compile_options(vmlib PRIVATE -Wno-backslash-newline-escape)
32+
# WAMR 2.4.4 win_file.c has trailing backslashes in comments that
33+
# clang treats as line continuations, causing compile errors.
34+
execute_process(
35+
COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/wamr-fix-win-backslash-comments.patch"
36+
WORKING_DIRECTORY "${wamr_SOURCE_DIR}"
37+
RESULT_VARIABLE _patch_result
38+
)
39+
if(_patch_result)
40+
message(WARNING "WAMR win_file.c patch failed (may already be applied)")
41+
endif()
42+
43+
add_subdirectory("${wamr_SOURCE_DIR}" "${wamr_BINARY_DIR}")
3344
endif()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c
2+
index 55ea77a..ae14b1a 100644
3+
--- a/core/shared/platform/windows/win_file.c
4+
+++ b/core/shared/platform/windows/win_file.c
5+
@@ -1295,13 +1295,13 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf,
6+
7+
if (wbufsize >= 4 && wbuf[0] == L'\\' && wbuf[1] == L'?'
8+
&& wbuf[2] == L'?' && wbuf[3] == L'\\') {
9+
- // Starts with \??\
10+
+ // Has \??\ prefix
11+
if (wbufsize >= 6
12+
&& ((wbuf[4] >= L'A' && wbuf[4] <= L'Z')
13+
|| (wbuf[4] >= L'a' && wbuf[4] <= L'z'))
14+
&& wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\'))
15+
{
16+
- // \??\<drive>:\
17+
+ // \??\<drive>:\ path
18+
wbuf += 4;
19+
wbufsize -= 4;
20+
}
21+
@@ -1310,7 +1310,7 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf,
22+
&& (wbuf[6] == L'C' || wbuf[6] == L'c')
23+
&& wbuf[7] == L'\\')
24+
{
25+
- // \??\UNC\<server>\<share>\ - make sure the final path looks like \\<server>\<share>\
26+
+ // \??\UNC\<server>\<share>\ - make sure the final path looks like \\<server>\<share>
27+
wbuf += 6;
28+
wbuf[0] = L'\\';
29+
wbufsize -= 6;

0 commit comments

Comments
 (0)