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
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Commits that only reformat or re-header files; `git config blame.ignoreRevsFile .git-blame-ignore-revs` makes git blame skip them.
# Reformat the C++ sources with clang-format (#653)
48eea66d540c4921c447bebab1811f40ed177cd5
# Reformat with clang-format 23.1.5, the reference version (#653)
32b8d55a732e6333de9537fa6b73b4bc30321a58
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Exclude files from exporting
.gitattributes export-ignore
.gitignore export-ignore
.git-blame-ignore-revs export-ignore
.gitkeep export-ignore

# Embedded headers hold the exact bytes of their text sources. Freshness tests
Expand Down
30 changes: 30 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ To ensure consistency, we use `.clang-format` and `clang-tidy` to enforce our co

Please run these tools on your code before submitting a pull request.

CI runs `.github/scripts/check-clang-format.sh` weekly, on pull requests into `master` and on manual dispatch (not on every pull request into `develop`), on every tracked C++ source (`clang-format --dry-run --Werror`) with a pinned version of `clang-format`
(`.github/workflows/SourceFormat.yml`); the reference version is **clang-format 23.1.5** (`python3 -m pip install clang-format==23.1.5`, or any 23.x: a patch release does not change the output, another major version may); run the script locally with it before you push, and never run `clang-format -i` with another major version. Generated headers (the embedded assets) and the gzip
fixtures are exempt. The commit that reformatted the whole code base is listed in `.git-blame-ignore-revs`; to make `git blame` skip it, run
`git config blame.ignoreRevsFile .git-blame-ignore-revs` once (GitHub applies the file by itself).

## File header

Every tracked C++ source (`.hpp`, `.cpp`, `.h`, `.cu`, `.cuh`, `.mm`) starts with this header, before `#pragma once` or the first `#include`:

```cpp
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: AAAA-MM-JJ
//
// WebFront — <subsystem / component>
// Role: <exact responsibility of the file in one short sentence>.
// Thread: <ui-loop | bridge-io | worker-safe | thread-safe> | Alloc: <zero-hot-path | heap-init | unrestricted>
// LLM: <how to read or modify the file, for example "public API; read struct contracts before impl">
```

- **Author** is the author of the file; **Created** is the date of its first commit, in ISO format.
- **Thread** tells where the code may run: `ui-loop` (the thread of `show()` or of the frontend's interface loop), `bridge-io` (the server's I/O context thread),
`worker-safe` (a pure or self-contained unit that any thread may use on its own objects) or `thread-safe` (shared objects synchronized inside).
- **Alloc** tells what the code may allocate: `zero-hot-path` (nothing on the hot path), `heap-init` (heap allocation at construction or setup only) or `unrestricted`.
- **Role** and **LLM** are written for the file, from its content and the invariants of `AGENTS.md` and the ADRs; never copy a generic value. An agent reads them
first, so keep them true when the file changes.
- Files with another license (third-party code) and generated files (the embedded asset headers, the gzip fixtures) keep their own header; they are listed in
`test/cmake/CheckSourceHeaders.cmake`, which fails the `SourceHeaders` CTest case for a tracked source whose header is missing or malformed.
- Build files (`CMakeLists.txt`, `*.cmake`) and the TypeScript under `js/` do not need the header.

## Changelog format

[`docs/CHANGELOG.md`](../docs/CHANGELOG.md) answers three questions quickly: what changes for me, is anything breaking, and
Expand Down
39 changes: 39 additions & 0 deletions .github/scripts/check-clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Fails when a tracked C++ source differs from what its clang-format configuration produces (#653).
# .github/scripts/check-clang-format.sh [clang-format] the executable defaults to clang-format
# Each source uses the .clang-format of its directory (include/webfront/, test/, examples/); cmake/ has none and follows include/webfront/.
# Generated or fixed data is exempt; the list matches test/cmake/CheckSourceHeaders.cmake. The reference version is the one pinned in
# .github/workflows/SourceFormat.yml (clang-format 23.1.5): another major version may format differently.
set -euo pipefail

clang_format="${1:-clang-format}"
cd "$(git rev-parse --show-toplevel)"

reference_major=23
version="$("$clang_format" --version)"
if ! grep -Eq "version ${reference_major}\." <<< "$version"; then
echo "warning: the reference is clang-format ${reference_major}.x, this is: $version" >&2
fi

exempt='^(include/webfront/system/(DeveloperBootstrapData|DeveloperIndexHtmlData|DeveloperReleaseData|DomInterpreterData|FallbackIndexHtmlData|FallbackModuleData|FaviconData|WebFrontJsData)\.hpp|test/unit/GzipFixtures\.hpp)$'

status=0
count=0
while IFS= read -r file; do
style=file
case "$file" in
cmake/*) style=file:include/webfront/.clang-format ;;
esac
count=$((count + 1))
if ! "$clang_format" --dry-run --Werror --style="$style" "$file" 2> /dev/null; then
echo "not formatted: $file"
status=1
fi
done < <(git ls-files '*.hpp' '*.cpp' '*.h' '*.cu' '*.cuh' '*.mm' | grep -Ev "$exempt")

if [ "$status" -ne 0 ]; then
echo "Run clang-format -i on the files above (version: $("$clang_format" --version))." >&2
else
echo "$count files formatted"
fi
exit "$status"
28 changes: 28 additions & 0 deletions .github/workflows/SourceFormat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Source Format

# Rare on purpose (#653): the advanced tier only, like the other weekly and release-branch checks. A pull request into develop is not checked.
on:
pull_request:
branches: [ master ]
schedule:
- cron: '23 4 * * 1'
workflow_dispatch:

permissions:
contents: read

jobs:
clang-format:
name: clang-format
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false

# The version is pinned: clang-format changes its output from one release to the next.
- name: Install clang-format
run: python3 -m pip install --user clang-format==23.1.5

- name: Check the tracked sources
run: .github/scripts/check-clang-format.sh "$HOME/.local/bin/clang-format"
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Exception: a purely C++ change that reuses an existing encoding, introduces no n
## Coding and testing conventions

- Use C++23, four-space indentation, the `.clang-format` of the directory (`include/webfront/`, `test/`, `examples/`), and the naming rules in `.github/CONTRIBUTING.md`.
- Every tracked C++ source starts with the normalized file header (SPDX, Author, Created, subsystem, Role, Thread, Alloc, LLM) described in `.github/CONTRIBUTING.md`; read it first, keep it true when you change the file, and give a new file one. The `SourceHeaders` CTest case checks it, and CI checks the format with `.github/scripts/check-clang-format.sh` (pinned `clang-format`); generated headers are exempt.
- Keep production implementation header-only under `include/`; browser resources live in `js/`.
- Prefer standard-library facilities and explicit ownership. Keep public headers ODR-safe (`inline`/templates as appropriate).
- Unit tests are named `const Scenario` objects whose `given`/`when`/`then` sections are lambdas, checked with `require`/`check` (`include/webfront/testing/Bdd.hpp`), and use deterministic mocks.
Expand Down
30 changes: 19 additions & 11 deletions cmake/mddlog/Logger.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/** @brief WebFront-owned module-consuming TU; the facade header remains independent of modules. */
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-10-01
//
// WebFront — build/mddlog
// Role: WebFront-owned module-consuming translation unit implementing the logger facade over mddlog; the facade header stays independent of modules.
// Thread: thread-safe | Alloc: unrestricted
// LLM: compiled only when modules are available; keep module types out of LoggerApi.hpp

import std;
import mddlog.core.loglevel;
import mddlog.adapter.textlogger;
Expand Down Expand Up @@ -307,7 +315,7 @@ RingClaim::~RingClaim() {

/** @brief Stops the consumer during static destruction, before the text adapter it may use. */
struct LaneShutdown {
explicit LaneShutdown(TransportLane& value) : lane(&value) {}
explicit LaneShutdown(TransportLane& value) : lane(&value) { }
LaneShutdown(const LaneShutdown&) = delete;
LaneShutdown& operator=(const LaneShutdown&) = delete;
LaneShutdown(LaneShutdown&&) = delete;
Expand Down Expand Up @@ -503,15 +511,15 @@ TransportHandle addTransport(std::function<void(const TransportRecord&)> write)
const auto text = renderTransportText(record);
try {
write({.level = facadeLevel(record.level),
.timeAvailable = record.timeAvailable,
.time = std::chrono::time_point_cast<std::chrono::nanoseconds>(record.timestamp),
.location = record.location,
.message = record.message,
.messageTruncated = record.messageTruncated,
.component = record.category,
.operationId = record.operationId,
.correlationId = record.correlationId,
.text = text});
.timeAvailable = record.timeAvailable,
.time = std::chrono::time_point_cast<std::chrono::nanoseconds>(record.timestamp),
.location = record.location,
.message = record.message,
.messageTruncated = record.messageTruncated,
.component = record.category,
.operationId = record.operationId,
.correlationId = record.correlationId,
.text = text});
} catch (...) {
// TransportConsumer detaches this transport and counts the failure.
static_cast<void>(lane.detach(*attached));
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ in a native pseudoterminal, and a faster, less flashy start of the native window
- Choose the colour of the WebKitGTK view under the page with `WindowOptions::background` (WebKitGTK; the other embedded frontends are listed here), and read the start-up milestones of a WebKitGTK view with `WEBFRONT_STARTUP_TRACE=1` (#611, `docs/WEBKITGTK.md`).

### Changed
- The whole C++ code base is reformatted with `clang-format` and every source starts with a normalized header (SPDX, author, creation date, role, thread and allocation model, reading hint); CI checks both (`SourceHeaders` case, `.github/workflows/SourceFormat.yml`), and `.git-blame-ignore-revs` skips the reformatting in `git blame` (#653, `.github/CONTRIBUTING.md`).
- WebKitGTK takes a `startupTimeout` (30 s by default), and WebView2 refuses a secondary window once the first one closed, even for a page already open (#652).
- Open every native window from one `ViewOptions` (`WKWebViewOptions` and `WebView2Options` are aliases), whose test injections reach the secondary windows too (#652, `docs/FRONTENDS.md`).
- Write a native frontend from shared headers: `EmbeddedFrontend` (facade and every `open()` overload), `WindowRegistry`/`InterfaceSession`, `StartupTrace` and `Presentation`, tested on Linux with fake windows (#652, `docs/FRONTENDS.md`).
Expand Down
2 changes: 1 addition & 1 deletion examples/.clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Modern C++20+ clang-format configuration for WebFront project
# Compatible with clang-format 22+
# Reference version: clang-format 23.1.5 (pinned in .github/workflows/SourceFormat.yml); another major version may format differently
Language: Cpp
BasedOnStyle: WebKit

Expand Down
9 changes: 9 additions & 0 deletions examples/PortOption.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-11-20
//
// WebFront — examples
// Role: Handles `--port <n>` and `--port=<n>` of an example and makes it the default port of the applications that follow.
// Thread: ui-loop | Alloc: heap-init
// LLM: example support; prints the reason and returns false on an invalid value

#pragma once

#include <webfront/WebFront.hpp>
Expand Down
9 changes: 9 additions & 0 deletions examples/hello-world/HelloWorld.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2022-02-03
//
// WebFront — examples
// Role: Minimal example: a C++ callback called from the browser, served by an embedded page.
// Thread: ui-loop | Alloc: unrestricted
// LLM: smallest complete application; the README quick start must stay in step with it

#include <webfront/WebFront.hpp>

// Switching to an embedded Chromium window only changes this alias (CEF must be enabled at
Expand Down
13 changes: 11 additions & 2 deletions examples/host-loop/BoingCuda.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-11-16
//
// WebFront — examples
// Role: CUDA unit of the host-loop example: the ray-traced Boing Ball computed on the device.
// Thread: worker-safe | Alloc: unrestricted
// LLM: optional CUDA build; device memory is allocated lazily and freed by cudaRelease

// The CUDA renderer of the Boing Ball: one thread per pixel runs the same pixel() as the CPU renderer.
// Compiled by nvcc at C++17; includes no WebFront header.

Expand Down Expand Up @@ -25,8 +34,8 @@ const char* failure(cudaError_t status) {
} // namespace

const char* cudaDevice() {
static char name[256] = "";
int count = 0;
static char name[256] = "";
int count = 0;
cudaDeviceProp properties;
if (name[0] == '\0' && cudaGetDeviceCount(&count) == cudaSuccess && count > 0 && cudaGetDeviceProperties(&properties, 0) == cudaSuccess)
for (std::size_t i = 0; i + 1 < sizeof name && properties.name[i] != '\0'; ++i)
Expand Down
11 changes: 10 additions & 1 deletion examples/host-loop/BoingCuda.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-11-16
//
// WebFront — examples
// Role: Interface of the optional CUDA unit: device name, whole-image computation, copy back and release.
// Thread: worker-safe | Alloc: zero-hot-path
// LLM: functions return nullptr or the reason of a failure; see docs/HOST_LOOP_EXAMPLE.md

#pragma once

// The optional CUDA renderer of the Boing Ball (BoingCuda.cu). Its interface is plain C++ so that the unit nvcc
Expand Down Expand Up @@ -30,7 +39,7 @@ inline const char* cudaCompute(const Scene&) {
inline const char* cudaCopy(std::uint32_t*, std::size_t) {
return "this build has no CUDA renderer";
}
inline void cudaRelease() {}
inline void cudaRelease() { }
#endif

} // namespace boing
11 changes: 10 additions & 1 deletion examples/host-loop/BoingHost.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-11-16
//
// WebFront — examples
// Role: Host of the Boing Ball example: engines, image quality and the frames the host loop produces for the browser.
// Thread: worker-safe | Alloc: unrestricted
// LLM: example of an application keeping its own loop; see docs/HOST_LOOP_EXAMPLE.md

#pragma once

// The host application of the example: it owns the scene, its clock, the renderers and its loop. Nothing here knows
Expand Down Expand Up @@ -265,7 +274,7 @@ class Host {
Settings settings;
std::uint32_t revision{0};
std::map<std::uint64_t, Deliver> waiting;
std::set<std::uint64_t> inFlight; // retained until this consumer's delivery begins
std::set<std::uint64_t> inFlight; // retained until this consumer's delivery begins
Displayed lastDisplayed;
bool stopping{false}, ended{false};

Expand Down
19 changes: 14 additions & 5 deletions examples/host-loop/BoingScene.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
// Author: Ambroise Leclerc
// Created: 2026-11-16
//
// WebFront — examples
// Role: The animated Boing Ball scene and its CPU ray tracer, a pure function of time.
// Thread: worker-safe | Alloc: zero-hot-path
// LLM: deterministic computation; the CUDA unit must produce the same image

#pragma once

// The Boing Ball scene: the colour of one pixel as a function of the scene of a frame. The CPU renderer and the CUDA
Expand Down Expand Up @@ -236,11 +245,11 @@ BOING_FN std::uint32_t pixel(const Scene& scene, int x, int y) {
const float toBall = hitBall(scene, camera, direction), toFloor = hitFloor(camera, direction);
const auto ray = static_cast<unsigned>(x) * 1973U + static_cast<unsigned>(y) * 9277U + static_cast<unsigned>(sy * 2 + sx) * 26699U;
sum = sum
+ beamsAlong(scene,
camera,
direction,
toBall > 0.F && (toFloor <= 0.F || toBall < toFloor) ? toBall : toFloor,
static_cast<float>(ray & 255U) / 256.F);
+ beamsAlong(scene,
camera,
direction,
toBall > 0.F && (toFloor <= 0.F || toBall < toFloor) ? toBall : toFloor,
static_cast<float>(ray & 255U) / 256.F);
}
}
const float scale = 1.F / static_cast<float>(scene.samples * scene.samples);
Expand Down
Loading
Loading