Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# re-read those sources, so Windows checkouts must preserve LF for every asset.
js/core/WebFront.js text eol=lf
js/core/bootstrap/* text eol=lf
js/core/favicon.ico binary
include/webfront/system/WebFrontJsData.hpp text eol=lf
js/core/fallback/index.html text eol=lf
js/core/fallback/webfront-fallback.mjs text eol=lf
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The README introduces WebFront through the Game of Life walkthrough, demonstrati
- `include/webfront/`: public header-only library, included as `<webfront/...>`. `WebFront.hpp` is the main orchestration API; `Commands.hpp` adds an application's C++ commands to the developer environment's terminal.
- `include/webfront/http/`: HTTP and WebSocket protocol implementation.
- `include/webfront/weblink/`: bridge message encoding and routing.
- `include/webfront/system/`: layered virtual filesystems and embedded web resources.
- `include/webfront/system/`: layered virtual filesystems and the embedded web resources, a closed list guarded by the `MinimalCoreAssets` CTest case (normative list and 150 KiB decoded budget in ADR-016; changing it means amending the ADR and `test/cmake/CheckMinimalCoreAssets.cmake` together).
- `include/webfront/frontend/`: system-browser, CEF, optional Windows WebView2 and macOS WKWebView frontend adapters.
- `examples/`: only Hello World (`hello-world/`) and Game of Life (`life/`, with console, developer and embedded stages).
- `js/core/`: readable browser bridge, fallback and bootstrap loader compiled into `include/webfront/`, plus the embedding CMake modules; `js/developer/`: developer environment (its terminal and `wf`), build and vendoring tools. Production C++ remains header-only in `include/webfront/`.
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@

### Changed

- Guard of the minimal core (#314): the `MinimalCoreAssets` CTest case lists the generated resource headers of
`include/webfront/` and fails on one outside the normative list of ADR-016 or when the decoded payloads exceed 150 KiB
(currently 35 766 bytes in 99 341 bytes of headers; `include/webfront/system` went from about 2.5 MB at the start of #303 to 188 KB).
The default favicon is the source `js/core/favicon.ico` rendered by `js/core/EmbedBinaryAsset.cmake`, pure CMake with
no Node.js, into `FaviconData.hpp` (`FaviconAssetFresh` checks it); it is no longer a hand-written gzip array in
`IndexFS.hpp` and is served unencoded. `IndexFS::WebFrontIco` stays an alias of the generated struct.
- The browser integration suite `test/web/` runs through `wf test` (#311): `test/web/suite/` is a WebFront project
(`jasmine-core`, `react`, `react-dom` from the local registry), `webtest` is the `webfront-wf` driver with the
callbacks of the specs (`test/driver/WfDriver.hpp`), and the Signal Studio page is a JSX module built by esbuild-wasm.
Expand Down
16 changes: 15 additions & 1 deletion docs/EMBEDDED_ASSETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The C++ library embeds only what every application needs: the browser bridge (`WebFront.js`), the
fallback page and module, and the bootstrap page and loader of the developer environment, with the
pinned release data (`Developer*Data.hpp`). Each is generated from a readable source under `js/core/`
into a header under `include/webfront/system/`. Libraries such as React, Babel and Jasmine are not
(including the default favicon, `js/core/favicon.ico`) into a header under `include/webfront/system/`. Libraries such as React, Babel and Jasmine are not
embedded: they are npm packages that `wf install` locks and downloads (see
[DEVELOPER_ENVIRONMENT.md](DEVELOPER_ENVIRONMENT.md)), and the tests obtain them from a local registry.
Normal C++ consumer builds use the checked-in headers and need neither Node.js nor npm.
Expand All @@ -15,6 +15,17 @@ were removed. An application that served them replaces them with `wf install` of
(`react`, `react-dom`, `@babel/standalone`, `jasmine-core`) and `wf embed`, which generates a
header-only provider for the application's own build output.

## Guard

The `MinimalCoreAssets` CTest case (`test/cmake/CheckMinimalCoreAssets.cmake`, pure CMake) lists every
resource header of `include/webfront/` (named `*Data.hpp` or declaring a `dataSize` payload) and fails on one
outside the normative list of [ADR-016](adr/ADR-016-bootstrap-comme-socle.md), or when the decoded payloads exceed
150 KiB. The budget counts decoded bytes (gzip streams are measured by their trailer), so it does not depend on the
encoding; the test also prints the encoded bytes and the size of the headers. Adding a resource means amending the ADR
and the list in the script together. `MinimalCoreAssetsRejectsUnlisted` proves the guard fails on an unlisted
header, a hidden payload and an oversized resource. `du -sh include/webfront/system` was about 2.5 MB when the epic began
and is 188 KB now.

## Maintenance

Use Node.js 22.18 or newer (Node 24 in CI) and CMake 3.31 or newer. These tools are needed for
Expand All @@ -34,6 +45,9 @@ intermediate files. `EmbeddedAssetGenerator` covers empty and binary inputs, wor
line wrapping and a nonzero status for stale or missing files; a per-asset `*AssetFresh` test attributes
each stale header. `.gitattributes` keeps sources and headers at LF.

The favicon is binary and small, so `js/core/EmbedBinaryAsset.cmake` renders it (identity encoded, same header format)
with CMake alone: no Node.js and no compressor. `FaviconAssetFresh` compares the checked-in `FaviconData.hpp` with it.

The renderer can pack gzip-compressed bytes (`encoding = "gzip"`, `dataSize` excluding the trailing word
padding) with the vendored fflate `gzipSync` (level 9, mem 8, mtime 0, no filename, fixed OS byte), so
the streams are identical across platforms. The current assets are identity encoded because they are
Expand Down
8 changes: 5 additions & 3 deletions docs/adr/ADR-016-bootstrap-comme-socle.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| Version | Date | État | Auteur | Évolution | Commit |
| --- | --- | --- | --- | --- | --- |
| 1.0 | 2026-10-22 | Acceptée | Ambroise Leclerc | Décision initiale : environnement bootstrap comme architecture de base, liste normative du cœur, scripts autorisés, indépendance vis-à-vis de Node.js. | [404fed2](https://github.com/ambroise-leclerc/WebFront/commit/404fed2c2145d4faba8efee035e10522ff87a91f) |
| 1.1 | 2026-10-23 | Acceptée | Ambroise Leclerc | Garde-fou `MinimalCoreAssets` (#314) : la liste est vérifiée par CTest, budget de 150 Kio d'octets décodés ; le favicon devient `FaviconData`, généré par CMake pur depuis `js/core/favicon.ico`. | — |

## Statut et date

Expand Down Expand Up @@ -43,15 +44,16 @@ téléchargée et vérifiée, tandis que le code source de WebFront redevient mi
| `WebFrontJsData` | Bridge `WebFront.js` |
| `FallbackIndexHtmlData` | Page de repli |
| `FallbackModuleData` | Module de repli |
| favicon (`WebFrontIco`, servi par `IndexFS`) | Icône par défaut |
| `FaviconData` (alias `IndexFS::WebFrontIco`, source `js/core/favicon.ico`) | Icône par défaut |
| `DeveloperIndexHtmlData` | Page du bootstrap développeur |
| `DeveloperBootstrapData` | Chargeur bootstrap (`bootstrap.bundle.mjs`) |
| `DeveloperReleaseData` | Release épinglée (URL et SHA-512) |

Toute autre ressource web (bibliothèques, runner de test, pages de test, terminal, providers
applicatifs) est produite par un script autorisé et livrée par l'archive d'environnement ou par un
paquet npm verrouillé par intégrité. Cette liste est normative : un test garde-fou (#314) la
compare aux fichiers de ressources de `include/webfront/system/` et impose un budget de taille ;
paquet npm verrouillé par intégrité. Cette liste est normative : le test garde-fou `MinimalCoreAssets` (#314) la
compare aux en-têtes de ressources de `include/webfront/` et impose un budget de 150 Kio d'octets décodés
(somme des `dataSize` après décodage gzip, indépendante de l'encodage) ;
ajouter une ressource exige de modifier cette ADR (nouvelle version) et ce test dans le même
changement. Le C++ header-only (filesystems, serveur, bridge, frontends) n'est pas concerné.

Expand Down
37 changes: 37 additions & 0 deletions include/webfront/system/FaviconData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>

namespace webfront::fs::generated {

struct FaviconData {
static constexpr std::string_view encoding{};
static constexpr std::size_t dataSize{766};
static constexpr std::array<std::uint64_t, 96> data{
0x0000010001002020, 0x100001000400e802, 0x0000160000002800, 0x0000200000004000, 0x0000010004000000,
0x0000000000000000, 0x0000000000001000, 0x0000000000003834, 0x3200e09b1200ead9, 0xb0006c676200ae9f,
0x7500e6b24200524e, 0x4800e1a429009d7b, 0x2f00bfbab900857e, 0x6f00fbf8ef00b887, 0x2000866d3800e8c2,
0x6d0063594600bb23, 0x0000000000000000, 0x0000000032bbb900, 0x0000000000000000, 0x00000000009b2000,
0x0000000000000000, 0x000000000002a000, 0x000000006d8cc8d6, 0x0000000000036000, 0x006000d111717111,
0x1d00000000000000, 0x00006c1777777777, 0x7110000000000000, 0x0006117777777777, 0x7777f00000000000,
0x00f1777777777777, 0x77771f0000000000, 0x0017777171717177, 0x7777710000000000, 0x0117111717171717,
0x1717171000000060, 0xf111711111111111, 0x1171111f00600000, 0xc111111111111111, 0x1111111100000600,
0x1111111217be7e1b, 0xe71111116000000d, 0x111111eb7ebb111b, 0x21111111d000060d, 0x111111227b2b5112,
0x211111118060000c, 0x111115b5eb72211b, 0xb2251111c0000668, 0x11111221b21eb11b, 0x2ee5111180600608,
0x11117be5b711be1b, 0xe1111111c060066d, 0x1111eb1221112b1b, 0xe7111111d660066f, 0x1111be7be1117b5b,
0xbbbbb111f0600666, 0x1111111111111111, 0x1111111166600666, 0xd717171717171711, 0x7171771d66600f66,
0x6777777177717777, 0x1777717666606666, 0x6377777777777777, 0x7777773666f006ff, 0xf685575777575777,
0x57775a6f6f6666f6, 0xff3a575555757555, 0x5555affff6f066ff, 0x3f3fa55555555557, 0x555af33636f6f6ff,
0xf333334555555555, 0xea333333636faff3, 0xf3333333a445444a, 0x3a33333ff664b36f, 0xf333a3aaaaaaaaaa,
0xaa3a3333f332b243, 0x363f333333333333, 0x33333fffaa2bbbb9, 0x9999999999999999, 0x999999999bbbc000,
0x0003800000010000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000002, 0x1000001310000005, 0x0000002418000008, 0x9000004890000040, 0x500000905f800000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000800000008000,
0x0001e00000070000
};
};

} // namespace webfront::fs::generated
18 changes: 2 additions & 16 deletions include/webfront/system/IndexFS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "FallbackIndexHtmlData.hpp"
#include "FallbackModuleData.hpp"
#include "FaviconData.hpp"
#include "FileSystem.hpp"
#include "WebFrontJsData.hpp"

Expand All @@ -24,22 +25,7 @@ class IndexFS {
using IndexHtml = generated::FallbackIndexHtmlData;
using FallbackModule = generated::FallbackModuleData;

struct WebFrontIco {
static constexpr std::string_view encoding{"gzip"};
static constexpr size_t dataSize{510};
static constexpr std::array<uint64_t, 64> data{
0x1f8b080000000000, 0x02ff8d524f68d360, 0x14ffb56adc4171af, 0xa211c25cea1f500a, 0x0a8d94b14b863a19, 0x1e4485509c07831d, 0xdf3cac8408358740,
0xe9657af1b0ab1451, 0x705e7670ae225a03, 0xb57af2a89789b7f5, 0x301ddbc18e40103c, 0xc497a4ceced37e5f, 0x7e79eff7beefbdef, 0x7df902a478a8ea20,
0xbf77632d0d1c0670, 0x8aa932c79851fc7f, 0x0cf6ecc8b93c56ea, 0x19ac7f7b8999e9db, 0x78f1a482ef8df3b8, 0x7e65029df9d378ec, 0x9ec5fb774dcc562d,
0xfcfef5136f1fa8b8, 0x5f1ec1dac7324a37, 0x2ec13bde5f35ef35, 0xb76f5357b7ebf4d3, 0xd8941f7e5a8e9d5d, 0x2660e20bd9360d6d, 0x2d9a911d86fdb745,
0x899c04dd446ff6a4, 0x339c68d9b1195146, 0x2c5332c93d4415cc, 0x4db229864dc3bc17, 0x3ed03f7071b0c9c8, 0xadaaf2831d9edecf, 0x66a3ea919265e733,
0xa4481f7373d73291, 0xae99d84774e8f5c6, 0xddacd23849d48674, 0x87d3b38da34bca99, 0xd5685e1a207257df, 0x504be9f0fab62995, 0xb91ce7e6e2facba6,
0x6411b5dc0eb9373d, 0x6f89baa624fada21, 0xc1fa6bd23b7f1267, 0x489807c4341f8c87, 0xc3c7bc274c214ace, 0x160aa22b85c16cb1, 0xe8448f3369594204,
0xe168d1302a15c330, 0x16c3a02b425d7fce, 0xbe513426fd422108, 0x425fd3c6a3c0baa6, 0x69256bd167adcd8f, 0x5fbc3caa697a30f5, 0xcaf2b5670b3138e0,
0xe71b170abad6831e, 0x2ee4bce6a33ed4bd, 0x36df612dfac5768a, 0x345fca41e61ef64f, 0x1c0106e68009e6d8, 0x5560ee566d27256a, 0x09532bc0de3f23cd,
0x980cfe0200000000,
};
};
using WebFrontIco = generated::FaviconData;

using WebFrontJs = generated::WebFrontJsData;

Expand Down
76 changes: 76 additions & 0 deletions js/core/EmbedBinaryAsset.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Renders a small binary asset (identity encoded) as a header in the format of the embedded assets,
# in pure CMake: no Node.js, no script. Bounded lines are joined once, so the string never grows
# word by word. Used for the default favicon; larger or compressed assets are out of scope.
# cmake -DINPUT=<file> -DSTRUCT=<name> (-DOUTPUT=<header> | -DCHECK=<header>) -P EmbedBinaryAsset.cmake
if(NOT DEFINED INPUT)
message(FATAL_ERROR "INPUT must name the binary asset source")
endif()
if(NOT DEFINED STRUCT)
message(FATAL_ERROR "STRUCT must name the generated struct, e.g. FaviconData")
endif()
if(NOT DEFINED OUTPUT AND NOT DEFINED CHECK)
message(FATAL_ERROR "Set OUTPUT to regenerate the header or CHECK to verify it")
endif()

file(SIZE "${INPUT}" size)
file(READ "${INPUT}" hex HEX)
math(EXPR word_count "(${size} + 7) / 8")

set(lines "")
string(LENGTH "${hex}" hex_length)
set(offset 0)
while(offset LESS hex_length)
math(EXPR remaining "${hex_length} - ${offset}")
if(remaining GREATER 80)
set(remaining 80)
endif()
string(SUBSTRING "${hex}" ${offset} ${remaining} chunk)
string(REGEX MATCHALL ".[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?[^;]?" words "${chunk}")
set(rendered "")
foreach(word IN LISTS words)
string(LENGTH "${word}" word_length)
math(EXPR missing "16 - ${word_length}")
string(REPEAT "0" ${missing} padding)
list(APPEND rendered "0x${word}${padding}")
endforeach()
list(JOIN rendered ", " line)
list(APPEND lines " ${line}")
math(EXPR offset "${offset} + 80")
endwhile()
list(JOIN lines ",\n" body)
if(body)
set(body "\n${body}")
endif()

set(contents "#pragma once

#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>

namespace webfront::fs::generated {

struct ${STRUCT} {
static constexpr std::string_view encoding{};
static constexpr std::size_t dataSize{${size}};
static constexpr std::array<std::uint64_t, ${word_count}> data{${body}
};
};

} // namespace webfront::fs::generated
")

if(DEFINED CHECK)
if(NOT EXISTS "${CHECK}")
message(FATAL_ERROR "${CHECK} is missing; run the webfront-embedded-assets target")
endif()
file(READ "${CHECK}" current)
if(NOT current STREQUAL contents)
message(FATAL_ERROR "${CHECK} is stale; run the webfront-embedded-assets target")
endif()
else()
get_filename_component(directory "${OUTPUT}" DIRECTORY)
file(MAKE_DIRECTORY "${directory}")
file(WRITE "${OUTPUT}" "${contents}")
endif()
24 changes: 24 additions & 0 deletions js/core/WebFrontAssets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ function(_webfront_add_embedded_text_asset source header struct test_name)
endif()
endfunction()

# The favicon is binary and small: a pure CMake renderer, with no Node.js, produces its header.
function(_webfront_add_embedded_binary_asset source header struct test_name)
add_custom_command(TARGET webfront-embedded-assets POST_BUILD
COMMAND ${CMAKE_COMMAND} -DINPUT=${source} -DOUTPUT=${header} -DSTRUCT=${struct}
-P ${_WEBFRONT_ASSETS_DIR}/EmbedBinaryAsset.cmake
COMMENT "Regenerating ${header}"
VERBATIM
)
if(ENABLE_TESTING)
add_test(NAME ${test_name}
COMMAND ${CMAKE_COMMAND} -DINPUT=${source} -DCHECK=${header} -DSTRUCT=${struct}
-P ${_WEBFRONT_ASSETS_DIR}/EmbedBinaryAsset.cmake)
endif()
endfunction()

function(webfront_add_embedded_assets)
find_package(Git QUIET)
set(root "${_WEBFRONT_ASSETS_DIR}/../..")
Expand All @@ -42,6 +57,9 @@ function(webfront_add_embedded_assets)
_webfront_add_embedded_text_asset(
"${root}/js/core/fallback/webfront-fallback.mjs" "${root}/include/webfront/system/FallbackModuleData.hpp"
FallbackModuleData FallbackModuleAssetFresh)
_webfront_add_embedded_binary_asset(
"${root}/js/core/favicon.ico" "${root}/include/webfront/system/FaviconData.hpp"
FaviconData FaviconAssetFresh)

_webfront_add_embedded_text_asset(
"${root}/js/core/bootstrap/index.html" "${root}/include/webfront/system/DeveloperIndexHtmlData.hpp"
Expand All @@ -51,6 +69,12 @@ function(webfront_add_embedded_assets)
DeveloperBootstrapData DeveloperBootstrapAssetFresh)

if(ENABLE_TESTING)
add_test(NAME MinimalCoreAssets
COMMAND ${CMAKE_COMMAND} -DROOT=${root} -P ${root}/test/cmake/CheckMinimalCoreAssets.cmake)
# The guard must fail on an asset header outside the normative list.
add_test(NAME MinimalCoreAssetsRejectsUnlisted
COMMAND ${CMAKE_COMMAND} -DROOT=${root} -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/minimal-core-assets
-P ${root}/test/cmake/CheckMinimalCoreAssetsNegative.cmake)
find_program(WEBFRONT_NODE_EXECUTABLE NAMES node nodejs REQUIRED)
add_test(NAME DeveloperJavaScript COMMAND "${WEBFRONT_NODE_EXECUTABLE}"
--test "${root}/js/developer/tools/check.mjs" "${root}/js/developer/tools/distribution-check.mjs"
Expand Down
Binary file added js/core/favicon.ico
Binary file not shown.
Loading
Loading