Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

Commit 242dccf

Browse files
committed
Streams: emit the embedded bundle as <=16 KB literals; link Streams into the Android test host
MSVC caps a single string literal at 16,380 bytes (C2026) and a concatenated one at 65,535; the 71 KB bundle was emitted as two 60,000/11,188-byte raw strings, so every Windows and UWP job failed at "Build Solution". CMake now emits consecutive parts of at most 16,000 bytes, abutting with no separator (the split stays byte-transparent), and a variadic consteval Join reassembles them into the same std::array as before. The desktop UnitTests target links Streams for the Shared.cpp coverage but the Android UnitTestsJNI host did not, so the Android build failed on the include.
1 parent 517b298 commit 242dccf

3 files changed

Lines changed: 46 additions & 20 deletions

File tree

‎Polyfills/Streams/CMakeLists.txt‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ set(WEB_STREAMS_POLYFILL_FILE
33
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
44
"${WEB_STREAMS_POLYFILL_FILE}")
55
file(READ "${WEB_STREAMS_POLYFILL_FILE}" WEB_STREAMS_POLYFILL_SOURCE)
6-
string(SUBSTRING "${WEB_STREAMS_POLYFILL_SOURCE}" 0 60000 WEB_STREAMS_POLYFILL_SOURCE_1)
7-
string(SUBSTRING "${WEB_STREAMS_POLYFILL_SOURCE}" 60000 -1 WEB_STREAMS_POLYFILL_SOURCE_2)
6+
# MSVC caps a single string literal at 16,380 bytes (C2026) and a concatenated one at 65,535, so
7+
# the bundle is emitted as consecutive raw-string parts of at most 16,000 bytes and joined back
8+
# into one array at compile time. Parts abut with no separator so the split stays byte-transparent
9+
# (a separator could land inside an identifier or string literal when the bundle is regenerated).
10+
string(LENGTH "${WEB_STREAMS_POLYFILL_SOURCE}" _streams_length)
11+
set(_streams_part_size 16000)
12+
set(_streams_offset 0)
13+
set(_streams_index 0)
14+
set(WEB_STREAMS_POLYFILL_PARTS "")
15+
set(WEB_STREAMS_POLYFILL_PART_NAMES "")
16+
while(_streams_offset LESS _streams_length)
17+
math(EXPR _streams_index "${_streams_index} + 1")
18+
math(EXPR _streams_remaining "${_streams_length} - ${_streams_offset}")
19+
if(_streams_remaining LESS _streams_part_size)
20+
set(_streams_take ${_streams_remaining})
21+
else()
22+
set(_streams_take ${_streams_part_size})
23+
endif()
24+
string(SUBSTRING "${WEB_STREAMS_POLYFILL_SOURCE}" ${_streams_offset} ${_streams_take} _streams_part)
25+
string(APPEND WEB_STREAMS_POLYFILL_PARTS
26+
" inline constexpr char PonyfillPart${_streams_index}[] = R\"JSRHSTREAM(${_streams_part})JSRHSTREAM\";\n")
27+
string(APPEND WEB_STREAMS_POLYFILL_PART_NAMES ", PonyfillPart${_streams_index}")
28+
math(EXPR _streams_offset "${_streams_offset} + ${_streams_take}")
29+
endwhile()
830
configure_file(
931
"Source/StreamsScripts.h.in"
1032
"${CMAKE_CURRENT_BINARY_DIR}/Generated/StreamsScripts.h"

‎Polyfills/Streams/Source/StreamsScripts.h.in‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,36 @@
55

66
namespace Babylon::Polyfills::Internal::StreamsScripts
77
{
8-
inline constexpr char PonyfillPart1[] = R"JSRHSTREAM(
8+
// The vendored bundle is split by CMake into PonyfillPart1..N raw-string literals of at most
9+
// 16,000 bytes each (MSVC C2026) and joined below. The prologue and epilogue wrap it as a
10+
// CommonJS module so its exports can be read back. Nothing is inserted between parts: a
11+
// separator could divide an identifier or string literal when the bundle is regenerated.
12+
inline constexpr char PonyfillPrologue[] = R"JSRHSTREAM(
913
(function() {
1014
var exports = {};
1115
var module = { exports: exports };
12-
@WEB_STREAMS_POLYFILL_SOURCE_1@)JSRHSTREAM";
16+
)JSRHSTREAM";
1317

14-
// Keep the split transparent: inserting whitespace here can divide an
15-
// identifier or string literal when the vendored bundle is regenerated.
16-
inline constexpr char PonyfillPart2[] = R"JSRHSTREAM(@WEB_STREAMS_POLYFILL_SOURCE_2@
18+
@WEB_STREAMS_POLYFILL_PARTS@
19+
inline constexpr char PonyfillEpilogue[] = R"JSRHSTREAM(
1720
return module.exports;
1821
})()
1922
)JSRHSTREAM";
2023

21-
template<std::size_t Part1Size, std::size_t Part2Size>
22-
consteval auto Join(const char (&part1)[Part1Size], const char (&part2)[Part2Size])
24+
template<std::size_t... Sizes>
25+
consteval auto Join(const char (&... parts)[Sizes])
2326
{
24-
std::array<char, Part1Size + Part2Size - 1> result{};
25-
for (std::size_t index{}; index < Part1Size - 1; ++index)
26-
{
27-
result[index] = part1[index];
28-
}
29-
for (std::size_t index{}; index < Part2Size; ++index)
30-
{
31-
result[Part1Size - 1 + index] = part2[index];
32-
}
27+
std::array<char, (Sizes + ...) - sizeof...(Sizes) + 1> result{};
28+
std::size_t offset{};
29+
auto append = [&](const char* part, std::size_t size) {
30+
for (std::size_t index{}; index + 1 < size; ++index)
31+
{
32+
result[offset++] = part[index];
33+
}
34+
};
35+
(append(parts, Sizes), ...);
3336
return result;
3437
}
3538

36-
inline constexpr auto Ponyfill = Join(PonyfillPart1, PonyfillPart2);
39+
inline constexpr auto Ponyfill = Join(PonyfillPrologue@WEB_STREAMS_POLYFILL_PART_NAMES@, PonyfillEpilogue);
3740
}

‎Tests/UnitTests/Android/app/src/main/cpp/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ target_link_libraries(UnitTestsJNI
5555
PRIVATE File
5656
PRIVATE TextDecoder
5757
PRIVATE TextEncoder
58-
PRIVATE Performance)
58+
PRIVATE Performance
59+
PRIVATE Streams)

0 commit comments

Comments
 (0)