diff --git a/CMakeLists.txt b/CMakeLists.txt index 7121eb19..5f3c361d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,17 @@ string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_STRING "${VERSION_STRING project(WebFront LANGUAGES CXX VERSION ${VERSION_STRING}) include(cmake/Frontends.cmake) +# The examples need no -DWEBFRONT_EMBED_* option: unless the user decided, this platform's native window +# engine is enabled when its dependencies are present. Test and fuzzing builds keep explicit selection. +if(WEBFRONT_IS_TOP_LEVEL AND WEBFRONT_BUILD_EXAMPLES AND NOT ENABLE_TESTING AND NOT ENABLE_FUZZING) + set(WEBFRONT_AUTODETECT_NATIVE_DEFAULT ON) +else() + set(WEBFRONT_AUTODETECT_NATIVE_DEFAULT OFF) +endif() +option(WEBFRONT_AUTODETECT_NATIVE "Enable the native window engine of this platform when its dependencies are found" ${WEBFRONT_AUTODETECT_NATIVE_DEFAULT}) +if(WEBFRONT_AUTODETECT_NATIVE) + webfront_autodetect_native_frontends() +endif() webfront_declare_frontend_options() # The library requires threads; consumers inherit the flag through the WebFront target. diff --git a/README.md b/README.md index be5c32c5..c65ceb44 100644 --- a/README.md +++ b/README.md @@ -64,27 +64,32 @@ The example starts with a C++ simulation, adds a React interface, then embeds th ```bash git clone https://github.com/ambroise-leclerc/WebFront.git cd WebFront -cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -cmake --build build --parallel 2 +mkdir build +cd build +cmake .. +cmake --build . ``` +No option is needed: the build enables this platform's native window engine when its dependencies are found (see [step 2](#2-add-a-window-and-bootstrap-the-tools)). The commands below start from this `build` directory. With a multi-configuration generator such as Visual Studio, executables are in `examples\Debug\` (`--config Release` selects `examples\Release\`). + ### 1. Start with the C++ simulation [Life.hpp](examples/life/Life.hpp) implements Conway's B3/S23 rules on a wrapping 32 × 32 grid. Each step creates a new `std::bitset<1024>`. [LifeConsole.cpp](examples/life/LifeConsole.cpp) runs it without a GUI: ```bash -# From the repository root: -./build/examples/WebFrontLifeConsole +examples/WebFrontLifeConsole ``` -On Windows the executable is `build\examples\Release\WebFrontLifeConsole.exe`. +On Windows with Visual Studio run `examples\Debug\WebFrontLifeConsole.exe`. ### 2. Add a window and bootstrap the tools The essential change in [LifeDeveloper.cpp](examples/life/LifeDeveloper.cpp) is: ```cpp -webfront::NativeApp app{"life-project"}; +#include "LifeFrontend.hpp" + +webfront::demo::LifeApp app{"life-project"}; app.cppFunction("life.step", &webfront::demo::nextLife); app.bootstrap("developer"); app.show(); @@ -92,24 +97,36 @@ app.show(); The project directory gives the application access to its development files. `bootstrap("developer")` opens the integrated terminal and loads the version-pinned developer environment, checking its SHA-512 integrity. Downloads are cached, so later launches work offline. The terminal runs `wf` commands; no system shell is exposed and nothing is installed on your machine. -Enable **one** engine for your platform: +The build you made above is enough. Start the example from the `build` directory: + +```bash +examples/WebFrontLifeDeveloper +``` + +On Windows with Visual Studio run `examples\Debug\WebFrontLifeDeveloper.exe`. Without argument, the example uses `life-project` in the current directory (`build/life-project`), creates it when it is missing and reuses an existing one without touching its files; every `life-project/...` path below is relative to it. The pinned environment is used. -| Platform | CMake option | Runtime | +**Native window.** At configuration, CMake enables the native engine of your platform when it finds its dependencies, with no option to pass: + +| Platform | Engine | Detected when | | --- | --- | --- | -| Windows | `-DWEBFRONT_EMBED_WEBVIEW2=ON` | Microsoft Edge WebView2 Evergreen | -| macOS 13.3+ | `-DWEBFRONT_EMBED_WKWEBVIEW=ON` | System Cocoa / WebKit | -| Linux | `-DWEBFRONT_EMBED_WEBKITGTK=ON` | WebKitGTK 6.0; [installation](docs/WEBKITGTK.md) | +| Windows | Microsoft Edge WebView2 Evergreen | an MSVC-compatible compiler is used (the SDK is downloaded; the Evergreen runtime is checked at start) | +| macOS 13.3+ | System Cocoa / WebKit | Clang and a deployment target of at least 13.3 | +| Linux | WebKitGTK 6.0 | `pkg-config webkitgtk-6.0` succeeds; [installation](docs/WEBKITGTK.md) | -Then, on macOS, from the repository root, build and start the example on a new project directory: +On macOS, this opens a WKWebView window using the system Cocoa and WebKit frameworks, with no engine download. +The example constructs the application and calls `show()` on the main thread; the HTTP/WebSocket server runs on its own thread. +Closing the window stops the server and exits the example. An explicit deployment target below 13.3 disables automatic detection; +explicitly enabling WKWebView with such a target fails configuration. See [the macOS guide](docs/WKWEBVIEW.md). -```bash -cmake -S . -B build-native -DCMAKE_BUILD_TYPE=Release -DWEBFRONT_EMBED_WKWEBVIEW=ON -cmake --build build-native --target WebFrontLifeDeveloper --parallel 2 -mkdir -p life-project -./build-native/examples/WebFrontLifeDeveloper "$PWD/life-project" -``` +When the engine is missing, configuration still succeeds. CMake prints a `Native window: no native engine will be built` notice that says what to install, and `WebFrontLifeDeveloper` is compiled for the default browser: at start it prints that notice, serves the same application and opens it in your system browser. Install the dependency and run `cmake ..` again to get the native window. CEF (`-DWEBFRONT_EMBED_CEF=ON`) makes `CEFFrontend` available to your own applications; the examples do not select it. + +**Advanced options.** -Replace the engine option on Linux or Windows. With Visual Studio, add `--config Release` when building and start it with the project directory, `build-native\examples\Release\WebFrontLifeDeveloper.exe life-project` (after `mkdir life-project`). The example reports startup failures with a nonzero exit status. Two extra arguments, ` `, select another environment archive, for instance one [built from the sources](docs/DEVELOPER_ENVIRONMENT.md#environment-distribution-and-offline-tests-maintainers). +- Choose the engine yourself with `-DWEBFRONT_EMBED_WEBVIEW2=ON|OFF`, `-DWEBFRONT_EMBED_WKWEBVIEW=ON|OFF` or `-DWEBFRONT_EMBED_WEBKITGTK=ON|OFF`; an explicit value is never replaced by the detection. `-DWEBFRONT_AUTODETECT_NATIVE=OFF` disables it. Test builds (`-DENABLE_TESTING=ON`) keep the explicit selection. +- Automatic engine choices are recalculated on each configuration and do not create an engine option in the cache. To return from an explicit macOS choice to automatic detection, run `cmake .. -UWEBFRONT_EMBED_WKWEBVIEW` (or remove the corresponding engine option on another platform). +- Another project directory, and another environment archive, can be passed: `examples/WebFrontLifeDeveloper [ ]`, for instance an environment [built from the sources](docs/DEVELOPER_ENVIRONMENT.md#environment-distribution-and-offline-tests-maintainers). + +The example reports startup failures with a nonzero exit status. ### 3. Create the project and install its dependencies @@ -199,27 +216,31 @@ Declare the entry and the provider in `webfront.project.json` (`"entries": {"mai wf embed ui/main.tsx --output generated/LifeUI.hpp ``` -This builds the interface and packages its resources and dependency notices into a compressed C++ header. Close the development window, then reconfigure with the **same engine option** used above. On macOS: +This builds the interface and packages its resources and dependency notices into a compressed C++ header. Close the development window, then reconfigure the same `build` directory (the engine is kept): ```bash -cmake -S . -B build-native -DWEBFRONT_EMBED_WKWEBVIEW=ON \ - -DWEBFRONT_LIFE_ASSETS="$PWD/life-project/generated/LifeUI.hpp" -cmake --build build-native --target WebFrontLifeEmbedded --parallel 2 -./build-native/examples/WebFrontLifeEmbedded +cmake .. -DWEBFRONT_LIFE_ASSETS="$PWD/life-project/generated/LifeUI.hpp" +cmake --build . --target WebFrontLifeEmbedded +examples/WebFrontLifeEmbedded ``` -For Visual Studio add `--config Release` and launch `build-native\examples\Release\WebFrontLifeEmbedded.exe`. +For Visual Studio launch `examples\Debug\WebFrontLifeEmbedded.exe`. [LifeEmbedded.cpp](examples/life/LifeEmbedded.cpp) replaces the development project and bootstrap with the generated provider: ```cpp -webfront::NativeAppWithAssets app; +#include "LifeFrontend.hpp" + +webfront::demo::LifeAppWithAssets app; app.cppFunction("life.step", &webfront::demo::nextLife); app.show(); ``` Recompilation is explicit. The resulting application runs offline without the project directory, developer callbacks or downloaded tool cache. The selected native engine's deployment requirements still apply; this is not an application installer. +The examples' [LifeFrontend.hpp](examples/life/LifeFrontend.hpp) selects the native engine or the default browser for both stages. +Your own application can select `webfront::NativeApp` or `webfront::NativeAppWithAssets` explicitly when it requires a native window. + ## Use WebFront in your project WebFront's implementation lives under `include/`. There is no WebFront library binary to build; CMake supplies its C++ dependencies and platform settings: @@ -232,7 +253,7 @@ target_link_libraries(MyApp PRIVATE WebFront::WebFront) As a subproject, examples and tests are off by default and compiler settings do not leak into your targets. `WEBFRONT_BUILD_EXAMPLES=OFF` disables examples in a standalone build too. -`webfront::WebFront` always uses the system browser. Native adapters are explicit choices and remain optional; CEF is available when you need an embedded Chromium distribution. See [WKWebView](docs/WKWEBVIEW.md), [WebKitGTK](docs/WEBKITGTK.md) and the [frontend architecture](docs/adr/README.md). +`webfront::WebFront` always uses the system browser. Native adapters remain optional: the examples enable the one of your platform when its dependencies are found, while your own application selects its frontend explicitly; CEF is available when you need an embedded Chromium distribution. See [WKWebView](docs/WKWEBVIEW.md), [WebKitGTK](docs/WEBKITGTK.md) and the [frontend architecture](docs/adr/README.md). ## Build and test diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 3b76e614..8fb735a6 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -70,6 +70,12 @@ function(set_project_warnings project_name) -Wlogical-op # warn about logical operations being used where bitwise were probably wanted ) + # GCC 16 at -O2/-O3 reports a stringop-overflow inside stdexec's task_scheduler (std::optional of a type-erased + # scheduler) for every coroutine awaiting continues_on. The code is not ours: keep the warning, never fail on it. + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + list(APPEND GCC_WARNINGS -Wno-error=stringop-overflow) + endif() + # Vérifier si -Wdangling-reference est supporté (GCC 13+ ou certaines versions de GCC 12) include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-Wdangling-reference" COMPILER_SUPPORTS_DANGLING_REF) diff --git a/cmake/Frontends.cmake b/cmake/Frontends.cmake index 742a9f5c..8e77c5d0 100644 --- a/cmake/Frontends.cmake +++ b/cmake/Frontends.cmake @@ -11,7 +11,7 @@ function(webfront_register_frontend name) if(NOT "${name}" MATCHES "^[A-Za-z_][A-Za-z0-9_]*$") message(FATAL_ERROR "Frontend name '${name}' must be a C++ identifier") endif() - cmake_parse_arguments(PARSE_ARGV 1 ARG "XVFB_LINUX;ALWAYS_AVAILABLE" "OPTION;POLICY;DESCRIPTION;SUPPORT;SETUP;TEST_SETUP;TEST_NAME;TEST_TIMEOUT" "PLATFORMS;TEST_PLATFORMS") + cmake_parse_arguments(PARSE_ARGV 1 ARG "XVFB_LINUX;ALWAYS_AVAILABLE;NATIVE" "OPTION;POLICY;DESCRIPTION;SUPPORT;SETUP;TEST_SETUP;TEST_NAME;TEST_TIMEOUT" "PLATFORMS;TEST_PLATFORMS") if(name IN_LIST WEBFRONT_FRONTEND_REGISTRY) message(FATAL_ERROR "Frontend '${name}' is already registered") endif() @@ -70,29 +70,32 @@ function(webfront_register_frontend name) if(ARG_XVFB_LINUX) message(FATAL_ERROR "Frontend '${name}' cannot use XVFB_LINUX without OPTION") endif() + if(ARG_NATIVE) + message(FATAL_ERROR "Frontend '${name}' cannot use NATIVE without OPTION") + endif() endif() list(APPEND WEBFRONT_FRONTEND_REGISTRY "${name}") set(WEBFRONT_FRONTEND_REGISTRY "${WEBFRONT_FRONTEND_REGISTRY}" PARENT_SCOPE) - foreach(field OPTION POLICY DESCRIPTION SUPPORT SUPPORT_FILE SETUP TEST_SETUP TEST_NAME TEST_TIMEOUT PLATFORMS TEST_PLATFORMS XVFB_LINUX) + foreach(field OPTION POLICY DESCRIPTION SUPPORT SUPPORT_FILE SETUP TEST_SETUP TEST_NAME TEST_TIMEOUT PLATFORMS TEST_PLATFORMS XVFB_LINUX NATIVE) set(WEBFRONT_FRONTEND_${name}_${field} "${ARG_${field}}" PARENT_SCOPE) endforeach() endfunction() webfront_register_frontend(DefaultBrowser ALWAYS_AVAILABLE) webfront_register_frontend(WebView2 - OPTION WEBFRONT_EMBED_WEBVIEW2 POLICY strict + NATIVE OPTION WEBFRONT_EMBED_WEBVIEW2 POLICY strict DESCRIPTION "Download the pinned WebView2 SDK and link its static loader (Windows only)" PLATFORMS Windows SUPPORT WebView2Support TEST_PLATFORMS Windows TEST_NAME WebFrontWebView2Integration TEST_TIMEOUT 90 TEST_SETUP webfront_add_webview2_tests) webfront_register_frontend(WKWebView - OPTION WEBFRONT_EMBED_WKWEBVIEW POLICY strict + NATIVE OPTION WEBFRONT_EMBED_WKWEBVIEW POLICY strict DESCRIPTION "Link the system Cocoa and WebKit frameworks for WKWebViewFrontend (macOS 13.3+ only)" PLATFORMS Darwin SUPPORT WKWebViewSupport TEST_PLATFORMS Darwin TEST_NAME WebFrontWKWebViewIntegration TEST_TIMEOUT 90 TEST_SETUP webfront_add_wkwebview_tests) webfront_register_frontend(WebKitGTK - OPTION WEBFRONT_EMBED_WEBKITGTK POLICY strict + NATIVE OPTION WEBFRONT_EMBED_WEBKITGTK POLICY strict DESCRIPTION "Enable the system WebKitGTK 6.0 embedded frontend (Linux only)" PLATFORMS Linux SUPPORT WebKitGTKSupport TEST_PLATFORMS Linux TEST_NAME WebFrontWebKitGTKIntegration TEST_TIMEOUT 90 XVFB_LINUX @@ -127,6 +130,73 @@ function(webfront_declare_frontend_options) endforeach() endfunction() + +# Probes whether the native engine can be built here. Sets to ON or OFF and to a +# diagnostic for the OFF case. Only the registry's native engines are probed, never CEF. Kept +# separate so that configure-only tests can supply a deterministic answer. +function(webfront_probe_native_frontend name out reason) + set(available OFF) + set(why "") + if(name STREQUAL "WebKitGTK") + find_package(PkgConfig QUIET) + if(PkgConfig_FOUND) + pkg_check_modules(WEBFRONT_AUTODETECT_WEBKITGTK QUIET webkitgtk-6.0) + endif() + if(WEBFRONT_AUTODETECT_WEBKITGTK_FOUND) + set(available ON) + else() + set(why "pkg-config webkitgtk-6.0 was not found; install libwebkitgtk-6.0-dev (Ubuntu/Debian) or webkitgtk6.0-devel (Fedora), see docs/WEBKITGTK.md") + endif() + elseif(name STREQUAL "WKWebView") + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(why "WKWebViewFrontend requires Clang with Apple Blocks support") + elseif(CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "13.3") + set(why "CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET} is older than 13.3") + elseif(NOT CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS "22.4") + set(why "macOS 13.3 or later is required (Darwin ${CMAKE_HOST_SYSTEM_VERSION})") + else() + set(available ON) + endif() + elseif(name STREQUAL "WebView2") + if(MSVC) + set(available ON) + else() + set(why "WebView2Frontend requires an MSVC-compatible compiler (MSVC or clang-cl)") + endif() + else() + set(why "no probe is defined for ${name}") + endif() + set(${out} "${available}" PARENT_SCOPE) + set(${reason} "${why}" PARENT_SCOPE) +endfunction() + +# Enables, for this platform's native engine, an option the user has not set. Automatic values stay +# in normal variables: option() honors them (CMP0077), without creating a cache entry. A later +# configure probes again, while an explicit normal or cached value always wins, even when unchanged. +# A missing engine only produces a status message; the application reports it at run time. +function(webfront_autodetect_native_frontends) + foreach(name IN LISTS WEBFRONT_FRONTEND_REGISTRY) + set(option "${WEBFRONT_FRONTEND_${name}_OPTION}") + if(option STREQUAL "" OR NOT WEBFRONT_FRONTEND_${name}_NATIVE) + continue() + endif() + webfront_frontend_supports_platform("${name}" supported) + if(NOT supported) + continue() + endif() + if(DEFINED ${option}) + continue() + endif() + webfront_probe_native_frontend("${name}" available reason) + set(${option} "${available}" PARENT_SCOPE) + if(available) + message(STATUS "Native window: ${name} detected, ${option}=ON") + else() + message(STATUS "Native window: ${name} unavailable (${reason}), so applications using NativeApp will report it when started. Set -D${option}=ON once it is installed") + endif() + endforeach() +endfunction() + # Hook functions are supplied by the support module. Validate them immediately after loading it, # rather than deferring an unknown-command error until target or test setup. function(webfront_validate_frontend_hooks name) @@ -323,3 +393,16 @@ function(webfront_select_frontend var default description) endforeach() set(${var}_TYPE "webfront::frontend::${selected}Frontend" PARENT_SCOPE) endfunction() + +# Sets to the option of the native engine registered for this platform, or to "" when there is none. +function(webfront_native_frontend_option out) + set(result "") + foreach(name IN LISTS WEBFRONT_FRONTEND_REGISTRY) + webfront_frontend_supports_platform("${name}" supported) + if(WEBFRONT_FRONTEND_${name}_NATIVE AND supported) + set(result "${WEBFRONT_FRONTEND_${name}_OPTION}") + break() + endif() + endforeach() + set(${out} "${result}" PARENT_SCOPE) +endfunction() diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 63f3f9a3..173ae300 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +- `WebFrontLifeDeveloper` starts without argument on `./life-project` (created when missing, reused untouched otherwise) and the + pinned environment; the explicit ` [ ]` form remains. At configuration, the + native window engine of the platform is enabled automatically when its dependencies are found (top-level builds with examples, + without `ENABLE_TESTING`; `-DWEBFRONT_AUTODETECT_NATIVE=OFF` disables it, an explicit `WEBFRONT_EMBED_*` value always wins). + A missing engine does not fail the configuration: CMake explains how to install it and the Life examples are built for the default browser instead. The README Game of Life walkthrough builds with `mkdir build`, `cd build`, + `cmake ..` and `cmake --build .` (#366). The developer terminal drops its redundant banner line; the sources advance to environment 0.6.3 (unpublished, the pin stays on 0.6.2). + Automatic engine values stay outside the cache so an explicit choice equal to the previous detection is still respected; + removing an explicit engine cache entry resumes detection. Platforms without a registered engine configure the browser fallback. + - Cold gzip identity fallback uses one server-owned worker with bounded jobs, consumers and buffer capacities (#283). The new compressed-input cap defaults to 4 MiB and returns 500 before cache lookup when exceeded, including HEAD; configure `maxGzipEncodedAssetSize` @@ -262,7 +271,7 @@ ### Added - `std::bitset` callback arguments and results, C++ call arguments and typed future/sender results cross the bridge as packed `Uint8Array` bytes (bit `i` in byte `i / 8`, least-significant first), with exact-length and zero-padding validation. A packed Life demonstration exchanges 128 bytes per generation. -- Opt-in browser-powered developer environment: `NativeApp::bootstrap("developer")` downloads a SHA-512-pinned environment (distribution 0.3.1 on GitHub Pages) whose terminal offers `wf create|install|list|preview|embed`. It resolves npm packages in the browser, locks and re-verifies them, compiles with esbuild-WASM, previews in an iframe and generates a gzip-compressed C++ resource header. The bridge callbacks `webfront.developer.*` publish files through staged, bounded, transactional writes confined to the explicit project directory; abandoned transactions expire and stale staging is purged at startup. WebSocket clients without an `Origin` are refused. +- Opt-in developer environment: `NativeApp::bootstrap("developer")` downloads a SHA-512-pinned environment (distribution 0.3.1 on GitHub Pages) whose terminal offers `wf create|install|list|preview|embed`. It resolves npm packages in the browser, locks and re-verifies them, compiles with esbuild-WASM, previews in an iframe and generates a gzip-compressed C++ resource header. The bridge callbacks `webfront.developer.*` publish files through staged, bounded, transactional writes confined to the explicit project directory; abandoned transactions expire and stale staging is purged at startup. WebSocket clients without an `Origin` are refused. - `webfront::Task`, `app.spawn(task)` and `ui.spawn(task)` launch application-owned coroutines without execution plumbing; a returned `TaskHandle` cancels an individual task. `app.shutdown()` joins owned work explicitly. Spawning during stop/shutdown returns a stopped handle when rejected; destructor joins log and wait for stalled external work instead of propagating drain errors. `jsFunctionSender(name)` defaults to `void`. `WebFrontAwaitBrowser` is a compiled example matching the README. diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 51e989a9..807d773e 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -32,8 +32,8 @@ ship developer mode as the distribution configuration: `wf embed` produces the a `.d.ts` files and the type packages (`@types/*`, `types` and `typings` fields) of the locked graph. No external compiler is installed or required (see [Type checking](#type-checking-wf-check)). -The current environment is **0.6.2**, published as `developer-v0.6.2` and pinned by the release data. Earlier published -versions stay immutable; the sources advance to 0.6.2, which is not published yet. +The latest published environment is **0.6.2**, published as `developer-v0.6.2` and pinned by the release data. Earlier published +versions stay immutable; the sources advance to 0.6.3 (the terminal no longer prints its banner line), which is not published yet. ## Minimal C++ application diff --git a/docs/FRONTENDS.md b/docs/FRONTENDS.md index e34e2420..9543dd89 100644 --- a/docs/FRONTENDS.md +++ b/docs/FRONTENDS.md @@ -132,6 +132,16 @@ do not change the production HTTP/WebSocket transport. Enabling an engine makes its adapter available; select it explicitly in your application. `webfront::NativeApp` chooses the native engine for the current platform. +The options default to `OFF`. In a top-level build with examples and without `ENABLE_TESTING` or `ENABLE_FUZZING`, configuration first +probes the native engine of the platform (registered with `NATIVE`: WebKitGTK through `pkg-config webkitgtk-6.0`, WKWebView on Clang with +macOS 13.3+, WebView2 with an MSVC-compatible compiler) and sets `ON` or `OFF` in a normal variable, so `cmake ..` is enough to build the Life +example with a native window. Automatic values do not create engine cache entries and are probed again at the next configuration. +An explicit normal or cached option is never replaced, even if it equals the last detected value. Remove the cache entry with +`-UWEBFRONT_EMBED_WKWEBVIEW` (or the corresponding platform option) to resume automatic detection. +A missing engine only prints a status; the Life examples then use the default browser and CMake explains what to install. +Platforms without a registered native engine use the default browser as well. `-DWEBFRONT_AUTODETECT_NATIVE=OFF` +turns the detection off. CEF is never detected. + | Option | Default | Description | | --- | --- | --- | | `WEBFRONT_EMBED_WEBVIEW2` | OFF | Download the pinned WebView2 SDK and link its static loader (Windows only) | diff --git a/docs/PROJECT_STATUS.md b/docs/PROJECT_STATUS.md index 1f960b32..c2d1b983 100644 --- a/docs/PROJECT_STATUS.md +++ b/docs/PROJECT_STATUS.md @@ -253,7 +253,7 @@ Status snapshot: 2026-07-19. Optional mddlog integration note: 2026-10-02. Newco the Linux sanitizers, WebKitGTK and macOS/WKWebView checks. -## Historical browser-powered development (2026-10-20) +## Historical developer environment proposals (2026-10-20) - `NativeApp` can bootstrap a pinned developer environment with a small embedded loader. The downloadable terminal, npm library resolver, esbuild/WASM Worker and gzip/header generator do diff --git a/docs/adr/README.md b/docs/adr/README.md index bf846f66..70fad611 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -3,7 +3,7 @@ This directory describes WebFront’s architectural choices and the constraints to preserve when making changes or generating code. It contains **17 ADRs**, with unique numbers (16 accepted decisions and 1 proposal). The accepted baseline corresponds to commit `b031ab5` dated **2026-10-19**; -the browser-powered development proposals are dated **2026-10-20**, and the direct frontend access proposal **2026-10-24**. Each ADR is versioned +the developer environment proposals are dated **2026-10-20**, and the direct frontend access proposal **2026-10-24**. Each ADR is versioned according to the decision’s creation and its significant changes in the Git history. The ADRs themselves are written in French. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4c6b442d..a0182dad 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,45 @@ # Only two examples: the minimal application and the successive Game of Life stages. include(Frontends) +# The Life examples use the native window when its engine is built and otherwise fall back to the system browser, +# which needs no dependency: a missing engine is explained here, never an error. +webfront_native_frontend_option(WEBFRONT_LIFE_NATIVE_OPTION) +set(WEBFRONT_LIFE_NATIVE_WINDOW OFF) +if(WEBFRONT_LIFE_NATIVE_OPTION) + if(${WEBFRONT_LIFE_NATIVE_OPTION}) + set(WEBFRONT_LIFE_NATIVE_WINDOW ON) + endif() +endif() +if(NOT WEBFRONT_LIFE_NATIVE_WINDOW) + if(NOT WEBFRONT_LIFE_NATIVE_OPTION) + set(_life_install "no native engine is registered for ${CMAKE_SYSTEM_NAME}") + elseif(NOT WEBFRONT_AUTODETECT_NATIVE) + set(_life_install "enable it with -D${WEBFRONT_LIFE_NATIVE_OPTION}=ON (automatic detection is off)") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(_life_install "install the WebKitGTK 6.0 development package (libwebkitgtk-6.0-dev on Ubuntu/Debian, webkitgtk6.0-devel on Fedora; see docs/WEBKITGTK.md)") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(_life_install "use Clang on macOS 13.3 or later") + else() + set(_life_install "use an MSVC-compatible compiler") + endif() + if(WEBFRONT_LIFE_NATIVE_OPTION) + set(_life_advice "For a native window, ${_life_install}, then run cmake again.") + else() + set(_life_advice "${_life_install}; use the default browser on this platform.") + endif() + message(NOTICE + "Native window: no native engine will be built.\n" + " The Life examples will open the default browser instead (frontend DefaultBrowser).\n" + " ${_life_advice}\n" + " CEF (-DWEBFRONT_EMBED_CEF=ON) makes CEFFrontend available to your own applications; the examples do not select it.") +endif() +# Select the same frontend for the developer and embedded Life stages. +function(webfront_life_frontend target) + if(WEBFRONT_LIFE_NATIVE_WINDOW) + target_compile_definitions(${target} PRIVATE WEBFRONT_LIFE_NATIVE_WINDOW) + endif() +endfunction() + add_executable(HelloWorld hello-world/HelloWorld.cpp) target_link_libraries(HelloWorld PRIVATE WebFront WebFront_warnings WebFront_options) webfront_setup_frontends_for_target(HelloWorld) @@ -12,6 +51,7 @@ target_link_libraries(WebFrontLifeConsole PRIVATE WebFront_warnings WebFront_opt add_executable(WebFrontLifeDeveloper life/LifeDeveloper.cpp) target_link_libraries(WebFrontLifeDeveloper PRIVATE WebFront WebFront_warnings WebFront_options) webfront_setup_frontends_for_target(WebFrontLifeDeveloper) +webfront_life_frontend(WebFrontLifeDeveloper) set(WEBFRONT_LIFE_ASSETS "" CACHE FILEPATH "LifeUI.hpp generated by wf embed (enables the offline Life example)") if(WEBFRONT_LIFE_ASSETS) @@ -22,4 +62,5 @@ if(WEBFRONT_LIFE_ASSETS) target_link_libraries(WebFrontLifeEmbedded PRIVATE WebFront WebFront_warnings WebFront_options) target_compile_definitions(WebFrontLifeEmbedded PRIVATE WEBFRONT_LIFE_ASSETS_HEADER="${WEBFRONT_LIFE_ASSETS}") webfront_setup_frontends_for_target(WebFrontLifeEmbedded) + webfront_life_frontend(WebFrontLifeEmbedded) endif() diff --git a/examples/life/LifeDeveloper.cpp b/examples/life/LifeDeveloper.cpp index 2def185f..e229fffa 100644 --- a/examples/life/LifeDeveloper.cpp +++ b/examples/life/LifeDeveloper.cpp @@ -1,20 +1,28 @@ #include "Life.hpp" +#include "LifeFrontend.hpp" +#include "LifeDeveloperOptions.hpp" #include #include int main(int argc, char** argv) { - if (argc != 2 && argc != 4) { - std::cerr << "Usage: WebFrontLifeDeveloper [ ]\n"; + const auto options = webfront::demo::parseLifeDeveloperOptions(argc, argv); + if (!options) { + std::cerr << "Usage: WebFrontLifeDeveloper [ [ ]]\n" + "Without arguments the project is ./" + << webfront::demo::LifeDeveloperOptions::defaultProject << ", created when missing.\n"; return 2; } try { - webfront::NativeApp app{argv[1]}; + webfront::demo::prepareLifeProject(options->project); + if constexpr (!webfront::demo::lifeNativeWindow) + std::cerr << webfront::demo::browserNotice << '\n'; + webfront::demo::LifeApp app{options->project}; app.cppFunction("life.step", &webfront::demo::nextLife); - if (argc == 2) + if (!options->environment) app.bootstrap("developer"); else - app.bootstrap("developer", {.environment = argv[2], .integrity = argv[3]}); + app.bootstrap("developer", {.environment = *options->environment, .integrity = *options->integrity}); app.show(); } catch (const std::exception& error) { std::cerr << error.what() << '\n'; diff --git a/examples/life/LifeDeveloperOptions.hpp b/examples/life/LifeDeveloperOptions.hpp new file mode 100644 index 00000000..822a328e --- /dev/null +++ b/examples/life/LifeDeveloperOptions.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +namespace webfront::demo { + +/// Command line of WebFrontLifeDeveloper: `[ [ ]]`. +struct LifeDeveloperOptions { + static constexpr const char* defaultProject = "life-project"; + + std::filesystem::path project = defaultProject; + std::optional environment; + std::optional integrity; +}; + +/// Returns nullopt when the arguments do not follow the usage; no argument selects `life-project` in the +/// current directory and the pinned developer environment. +[[nodiscard]] inline std::optional parseLifeDeveloperOptions(int argc, const char* const* argv) { + if (argc != 1 && argc != 2 && argc != 4) + return std::nullopt; + LifeDeveloperOptions options; + if (argc >= 2) { + if (*argv[1] == '\0') + return std::nullopt; + options.project = argv[1]; + } + if (argc == 4) { + options.environment = argv[2]; + options.integrity = argv[3]; + } + return options; +} + +/// Creates the project directory when it is missing and leaves an existing one untouched. +/// Throws std::filesystem::filesystem_error when the path cannot be a directory. +inline void prepareLifeProject(const std::filesystem::path& project) { + std::filesystem::create_directories(project); +} + +} // namespace webfront::demo diff --git a/examples/life/LifeEmbedded.cpp b/examples/life/LifeEmbedded.cpp index 66c65cee..3d217d0b 100644 --- a/examples/life/LifeEmbedded.cpp +++ b/examples/life/LifeEmbedded.cpp @@ -1,12 +1,15 @@ #include #include WEBFRONT_LIFE_ASSETS_HEADER #include "Life.hpp" +#include "LifeFrontend.hpp" #include int main() { try { - webfront::NativeAppWithAssets app; + if constexpr (!webfront::demo::lifeNativeWindow) + std::cerr << webfront::demo::browserNotice << '\n'; + webfront::demo::LifeAppWithAssets app; app.cppFunction("life.step", &webfront::demo::nextLife); app.show(); } catch (const std::exception& error) { diff --git a/examples/life/LifeFrontend.hpp b/examples/life/LifeFrontend.hpp new file mode 100644 index 00000000..fe74e8a5 --- /dev/null +++ b/examples/life/LifeFrontend.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace webfront::demo { + +// examples/CMakeLists.txt defines WEBFRONT_LIFE_NATIVE_WINDOW when this platform's native engine is built. +// Otherwise the Life examples open the system browser, which needs no extra dependency. +#if defined(WEBFRONT_LIFE_NATIVE_WINDOW) +using LifeFrontend = frontend::NativeWebViewFrontend; +inline constexpr bool lifeNativeWindow = true; +#else +using LifeFrontend = frontend::DefaultBrowserFrontend; +inline constexpr bool lifeNativeWindow = false; +#endif + +using LifeApp = BasicDeveloperApp; + +template +using LifeAppWithAssets = BasicWF, http::DefaultBuffersPolicy, LifeFrontend>; + +inline constexpr const char* browserNotice = + "No native window engine was built: the default browser is opened instead. For a native window, install the " + "engine for your platform and run cmake again (see the README)."; + +} // namespace webfront::demo diff --git a/include/webfront/DeveloperApp.hpp b/include/webfront/DeveloperApp.hpp index a27af082..16d2d5dc 100644 --- a/include/webfront/DeveloperApp.hpp +++ b/include/webfront/DeveloperApp.hpp @@ -1,4 +1,4 @@ -/// @brief Opt-in browser-powered developer environment. Downloaded code has project/bridge authority. +/// @brief Opt-in developer environment (terminal and wf commands) running in the application window. Downloaded code has project/bridge authority. #pragma once #include "system/DeveloperFS.hpp" diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 90205a85..91257bb6 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -16,7 +16,7 @@ "js/developer/environment/packages.mjs": "37fe2a410e211264cfeaedbff3df50f7e62b02f8088130127d94f92081e2a5ad", "js/developer/environment/starter.mjs": "89ccab43be4455ed9598c54355b4bbe5adea1afd7a0ae5d755a14317e3ca39df", "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", - "js/developer/environment/runtime.mjs": "0396007b121905c59aeb84c896238750af19a3e38ea08c3ff6542705e5f4714d", + "js/developer/environment/runtime.mjs": "2273c4074d74a2976517208ac8eb9ce2560068fc62a4694876d1121b50a58536", "js/developer/environment/development.mjs": "dd07bc64e12c3392223f0e7aab0ae2f5223e093930bee8abe78a0cd3e2940d85", "js/developer/environment/testing.mjs": "326e003f114bdbad68fedbceaded30717b3fc15315e6d87fa747972b681e2dce", "js/developer/environment/terminal.mjs": "7ffcf7ac6ef63c35cdf5ef70284b384525b13ba18422af069289e53b6c4f6be1", @@ -37,7 +37,7 @@ "js/developer/environment/embed.mjs": "3e6bc10200939fa30d5f60a96f01eb33ddf3da87661390ad433a18366bf52547", "examples/life/ui/main.tsx": "7b1ff285d2a6b8f897ef12df872886e61ef4b24e2358a9423b76b38ab75c85d3", "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", - "js/developer/tools/distribution.json": "a40253717a5a0f2107ad9b96ada3d0487ee35b27a382e19b3b8a2d20388573af", + "js/developer/tools/distribution.json": "7029cf3e2e64e5ea44b595fddcc0151fca4cc210d2ef1258cee7bb8d75e7cd2f", "js/developer/tools/archive.mjs": "bfe9feeb5e4d4e1b7c44c4dec4dcbeab4ae59c2bf16a1d2b32cd6910a2b84e7b", "js/developer/tools/distribution.mjs": "1108b61bc659dd945ba1417aa84337bca03039842d342c95815b5463d87a136e", "js/developer/scripts/build.mjs": "df91efbc9bb19559c36440f0be7ec2b2af406209146a0d8eb88d688803a74c68", diff --git a/js/developer/environment/runtime.mjs b/js/developer/environment/runtime.mjs index aad7af1b..c2362574 100644 --- a/js/developer/environment/runtime.mjs +++ b/js/developer/environment/runtime.mjs @@ -488,7 +488,6 @@ export async function mount({bridge, config, terminal: element, preview, onExit, terminal.open(element); fit.fit(); const write = text => terminal.write(text); - write('WebFront browser-powered developer environment. Type help.\r\n'); // Keys typed while the commands and the history load are applied once the editor is ready. const early = []; const earlyInput = terminal.onData(data => early.push(data)); diff --git a/js/developer/tools/distribution.json b/js/developer/tools/distribution.json index 0f5fa7ba..48ac84ab 100644 --- a/js/developer/tools/distribution.json +++ b/js/developer/tools/distribution.json @@ -1,4 +1,4 @@ { - "version": "0.6.2", + "version": "0.6.3", "baseUrl": "https://ambroise-leclerc.github.io/WebFront/" } diff --git a/test/cmake/CheckFrontendSelection.cmake b/test/cmake/CheckFrontendSelection.cmake index 368e27ab..8f1bf702 100644 --- a/test/cmake/CheckFrontendSelection.cmake +++ b/test/cmake/CheckFrontendSelection.cmake @@ -78,8 +78,8 @@ if(CASE) elseif(VALUE STREQUAL "strict") webfront_register_frontend(TestBrowser ALWAYS_AVAILABLE POLICY strict) webfront_select_frontend(TEST_BROWSER TestBrowser "Test always-available browser" REQUIRE_AVAILABLE) - elseif(VALUE STREQUAL "XVFB_LINUX") - webfront_register_frontend(TestBrowser ALWAYS_AVAILABLE XVFB_LINUX) + elseif(VALUE STREQUAL "XVFB_LINUX" OR VALUE STREQUAL "NATIVE") + webfront_register_frontend(TestBrowser ALWAYS_AVAILABLE ${VALUE}) else() webfront_register_frontend(TestBrowser ALWAYS_AVAILABLE ${VALUE} ignored) endif() @@ -141,6 +141,20 @@ if(CASE) endif() webfront_register_frontend(TestEngine ${args}) endif() + elseif(CASE STREQUAL "autodetect") + # VALUE is the probe answer (ON/OFF). Empty option variables are undefined. + function(webfront_probe_native_frontend name out reason) + set(${out} "${VALUE}" PARENT_SCOPE) + set(${reason} "probe says ${VALUE}" PARENT_SCOPE) + endfunction() + webfront_autodetect_native_frontends() + foreach(option WEBFRONT_EMBED_WEBVIEW2 WEBFRONT_EMBED_WKWEBVIEW WEBFRONT_EMBED_WEBKITGTK WEBFRONT_EMBED_CEF) + if(DEFINED ${option}) + message("AUTO ${option}=${${option}}") + else() + message("AUTO ${option}=undefined") + endif() + endforeach() elseif(CASE STREQUAL "default") webfront_default_embedded_frontend(chosen FALLBACK CEF) message("CHOSEN=${chosen}") @@ -216,6 +230,37 @@ endforeach() set(CASE_NAME cached-selection) run_case("cached selector and explicit override" TRUE "CACHE_SELECTION=OK") + +# Native engines are detected only for this platform, and never override a decision of the user. +set(CASE_NAME autodetect) +set(CASE_CEF "") +set(CASE_WEBVIEW2 "") +set(CASE_WKWEBVIEW "") +set(CASE_WEBKITGTK "") +set(CASE_FLAGS "") +set(CASE_PLATFORM Linux) +set(CASE_VALUE ON) +run_case("Linux enables WebKitGTK when found" TRUE "AUTO WEBFRONT_EMBED_WEBVIEW2=undefined AUTO WEBFRONT_EMBED_WKWEBVIEW=undefined AUTO WEBFRONT_EMBED_WEBKITGTK=ON AUTO WEBFRONT_EMBED_CEF=undefined") +set(CASE_VALUE OFF) +run_case("Linux without WebKitGTK stays OFF and does not fail" TRUE "Native window: WebKitGTK unavailable [(]probe says OFF[)].*AUTO WEBFRONT_EMBED_WEBKITGTK=OFF") +set(CASE_VALUE ON) +set(CASE_PLATFORM Darwin) +run_case("macOS enables WKWebView" TRUE "AUTO WEBFRONT_EMBED_WEBVIEW2=undefined AUTO WEBFRONT_EMBED_WKWEBVIEW=ON AUTO WEBFRONT_EMBED_WEBKITGTK=undefined") +set(CASE_PLATFORM Windows) +run_case("Windows enables WebView2" TRUE "AUTO WEBFRONT_EMBED_WEBVIEW2=ON AUTO WEBFRONT_EMBED_WKWEBVIEW=undefined") +set(CASE_PLATFORM Linux) +set(CASE_WEBKITGTK OFF) +run_case("an explicit OFF is kept" TRUE "AUTO WEBFRONT_EMBED_WEBKITGTK=OFF") +set(CASE_WEBKITGTK ON) +set(CASE_VALUE OFF) +run_case("an explicit ON is kept" TRUE "AUTO WEBFRONT_EMBED_WEBKITGTK=ON") +set(CASE_WEBKITGTK "") +set(CASE_PLATFORM FreeBSD) +set(CASE_FLAGS "") +run_case("an unsupported platform enables nothing" TRUE "AUTO WEBFRONT_EMBED_WEBKITGTK=undefined") +set(CASE_PLATFORM Windows) +set(CASE_VALUE "") +set(CASE_FLAGS "") # Invalid registration metadata fails before add_test() or loading platform dependencies. set(CASE_NAME register) set(CASE_VALUE duplicate) @@ -251,7 +296,7 @@ set(CASE_VALUE valid) run_case("custom always-available browser" TRUE "TYPE=webfront::frontend::TestBrowserFrontend") set(CASE_VALUE strict) run_case("always-available rejects strict policy" FALSE "cannot use POLICY strict with ALWAYS_AVAILABLE") -foreach(CASE_VALUE DESCRIPTION PLATFORMS SUPPORT SETUP TEST_PLATFORMS TEST_SETUP TEST_NAME TEST_TIMEOUT XVFB_LINUX) +foreach(CASE_VALUE DESCRIPTION PLATFORMS SUPPORT SETUP TEST_PLATFORMS TEST_SETUP TEST_NAME TEST_TIMEOUT XVFB_LINUX NATIVE) run_case("browser rejects ${CASE_VALUE}" FALSE "Frontend 'TestBrowser' cannot use ${CASE_VALUE} without OPTION") endforeach() set(CASE_VALUE "") diff --git a/test/cmake/CheckNativeAutodetect.cmake b/test/cmake/CheckNativeAutodetect.cmake new file mode 100644 index 00000000..f8e2aee5 --- /dev/null +++ b/test/cmake/CheckNativeAutodetect.cmake @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.31) +if(NOT ROOT OR NOT WORK_DIR) + message(FATAL_ERROR "ROOT and WORK_DIR are required") +endif() +file(REMOVE_RECURSE "${WORK_DIR}") +function(configure name directory expected) + execute_process(COMMAND "${CMAKE_COMMAND}" -S "${ROOT}/test/cmake/native-autodetect" + -B "${WORK_DIR}/${directory}" "-DROOT=${ROOT}" ${ARGN} + RESULT_VARIABLE status OUTPUT_VARIABLE output ERROR_VARIABLE error) + if(NOT status EQUAL 0 OR NOT "${output}${error}" MATCHES "${expected}") + message(FATAL_ERROR "${name}: status ${status}\n${output}\n${error}") + endif() +endfunction() + +# All calls reuse real CMake caches, including -D overrides equal to the last detected value. +configure("initial automatic OFF" off "RESULT=OFF" -DPLATFORM=Linux -DPROBE=OFF) +configure("automatic OFF is probed again" off "RESULT=ON" -DPROBE=ON) +configure("explicit ON survives a missing dependency" off "RESULT=ON" + -DPROBE=OFF -DWEBFRONT_EMBED_WEBKITGTK:BOOL=ON) +configure("explicit ON stays explicit" off "RESULT=ON" -DPROBE=OFF) +configure("remove the override to resume detection" off "RESULT=OFF" -UWEBFRONT_EMBED_WEBKITGTK) +configure("explicit OFF survives a newly available dependency" off "RESULT=OFF" + -DPROBE=ON -DWEBFRONT_EMBED_WEBKITGTK:BOOL=OFF) +configure("explicit OFF stays explicit" off "RESULT=OFF" -DPROBE=ON) +configure("initial automatic ON" on "RESULT=ON" -DPLATFORM=Linux -DPROBE=ON) +configure("automatic ON is probed again" on "RESULT=OFF" -DPROBE=OFF) +configure("examples on an unsupported platform" unsupported "no native engine is registered for FreeBSD" + -DPLATFORM=FreeBSD -DTEST_EXAMPLES=ON) +message(STATUS "Native detection preserves explicit options across configurations") diff --git a/test/cmake/CheckNewcomerDocs.cmake b/test/cmake/CheckNewcomerDocs.cmake index 104deaf3..188c51bd 100644 --- a/test/cmake/CheckNewcomerDocs.cmake +++ b/test/cmake/CheckNewcomerDocs.cmake @@ -29,7 +29,13 @@ _read(wkwebview_guide docs/WKWEBVIEW.md) _read(developer_release include/webfront/system/DeveloperReleaseData.hpp) # The README starts the example on the environment pinned in the release data; only the guides of the maintainers and of # WKWebView show the explicit local archive, which must not silently use an unpublished default. -_require("${readme}" "./build-native/examples/WebFrontLifeDeveloper \"$PWD/life-project\"" "README default bootstrap") +_require("${readme}" "```bash\nexamples/WebFrontLifeDeveloper\n```" "README starts the example without argument") +_require("${readme}" "-DWEBFRONT_AUTODETECT_NATIVE=OFF" "README advanced native selection") +_require("${root}" "webfront_autodetect_native_frontends()" "native engine autodetection") +foreach(option WEBFRONT_EMBED_WEBVIEW2 WEBFRONT_EMBED_WKWEBVIEW WEBFRONT_EMBED_WEBKITGTK) + _require("${readme}" "-D${option}=ON|OFF" "README explicit engine choice") +endforeach() +_require("${life}" "parseLifeDeveloperOptions" "default project and explicit arguments") foreach(text developer_guide wkwebview_guide) _require("${${text}}" "/webfront/developer/preview/provision/environment.tgz \"$integrity\"" "${text} local bootstrap arguments") _require("${${text}}" "sed -n 's/^ \"integrity\": \"\\(.*\\)\",$/\\1/p' build-developer-environment/provision.json" "${text} trusted local integrity") @@ -45,7 +51,7 @@ _require("${root}" "add_subdirectory(examples)" "examples directory") _require("${root}" "option(ENABLE_TESTING \"Enable Test Builds\" OFF)" "tests opt-in") _require("${root}" "add_library(WebFront::WebFront ALIAS WebFront)" "consumer alias") _require("${readme}" "target_link_libraries(MyApp PRIVATE WebFront::WebFront)" "consumer instructions") -_require("${readme}" "cmake -S . -B build -DCMAKE_BUILD_TYPE=Release\ncmake --build build --parallel 2" "Life initial build") +_require("${readme}" "mkdir build\ncd build\ncmake ..\ncmake --build .\n" "Life standard build") foreach(line "app.cppFunction(\"life.step\", &webfront::demo::nextLife);" "app.bootstrap(\"developer\");" "app.show();") _require("${readme}" "${line}" "Life bootstrap snippet") _require("${life}" "${line}" "compiled Life bootstrap") @@ -53,8 +59,9 @@ endforeach() foreach(line "#include " "Grid nextLife(const Grid& cells)" "app.cppFunction(\"life.step\", &nextLife);") _require("${readme}" "${line}" "self-contained introductory Life application") endforeach() -_require("${readme}" "webfront::NativeAppWithAssets app;" "offline application snippet") -_require("${embedded}" "webfront::NativeAppWithAssets app;" "compiled offline application") +_require("${readme}" "webfront::demo::LifeApp app{\"life-project\"};" "developer application snippet") +_require("${readme}" "webfront::demo::LifeAppWithAssets app;" "offline application snippet") +_require("${embedded}" "webfront::demo::LifeAppWithAssets app;" "compiled offline application") foreach(target HelloWorld WebFrontLifeConsole WebFrontLifeDeveloper WebFrontLifeEmbedded) _require("${examples}" "add_executable(${target} " "compiled example stage") if(NOT target STREQUAL "HelloWorld") diff --git a/test/cmake/native-autodetect/CMakeLists.txt b/test/cmake/native-autodetect/CMakeLists.txt new file mode 100644 index 00000000..96016bf4 --- /dev/null +++ b/test/cmake/native-autodetect/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.31) +project(NativeAutodetect LANGUAGES CXX) + +include("${ROOT}/cmake/Frontends.cmake") +set(CMAKE_SYSTEM_NAME "${PLATFORM}") +function(webfront_probe_native_frontend name out reason) + set(${out} "${PROBE}" PARENT_SCOPE) + set(${reason} "controlled probe" PARENT_SCOPE) +endfunction() +webfront_autodetect_native_frontends() +webfront_declare_frontend_options() +message(STATUS "RESULT=${WEBFRONT_EMBED_WEBKITGTK}") + +if(TEST_EXAMPLES) + list(APPEND CMAKE_MODULE_PATH "${ROOT}/cmake") + foreach(target WebFront WebFront_warnings WebFront_options) + add_library(${target} INTERFACE) + endforeach() + function(webfront_setup_frontends_for_target target) + endfunction() + add_subdirectory("${ROOT}/examples" examples) + get_target_property(definitions WebFrontLifeDeveloper COMPILE_DEFINITIONS) + if("WEBFRONT_LIFE_NATIVE_WINDOW" IN_LIST definitions) + message(FATAL_ERROR "An unsupported platform must use the default browser") + endif() +endif() diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index fca43425..107b1e28 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -95,6 +95,11 @@ add_test(NAME NewcomerDocsMatchExamples add_test(NAME FrontendSelection COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} "-DTEST_GENERATOR=${CMAKE_GENERATOR}" -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckFrontendSelection.cmake) +add_test(NAME NativeAutodetectReconfiguration + COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} + -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/native-autodetect + -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckNativeAutodetect.cmake) +set_tests_properties(NativeAutodetectReconfiguration PROPERTIES TIMEOUT 60) # Exercise configuration-dependent CTest discovery and generator switches on single-config CI hosts. # The fixture configures no compiler and builds nothing; Ninja is optional for contributor builds. find_program(WEBFRONT_TEST_NINJA_EXECUTABLE ninja) diff --git a/test/unit/LifeTests.cpp b/test/unit/LifeTests.cpp index 4fe0cb8e..7760db83 100644 --- a/test/unit/LifeTests.cpp +++ b/test/unit/LifeTests.cpp @@ -1,6 +1,10 @@ #include "../../examples/life/Life.hpp" +#include "../../examples/life/LifeDeveloperOptions.hpp" +#include "TemporaryDirectory.hpp" #include +#include + using webfront::demo::LifeGrid; using webfront::demo::nextLife; @@ -49,3 +53,74 @@ SCENARIO("Life wraps both axes without treating adjacent rows as neighbors") { isolated.set(static_cast(i)); REQUIRE(nextLife(isolated).none()); } + +using webfront::demo::parseLifeDeveloperOptions; +using webfront::demo::prepareLifeProject; + +SCENARIO("WebFrontLifeDeveloper starts without arguments") { + GIVEN("an empty command line") { + const char* argv[] = {"WebFrontLifeDeveloper"}; + const auto options = parseLifeDeveloperOptions(1, argv); + THEN("the project is life-project and the pinned environment is used") { + REQUIRE(options); + REQUIRE(options->project == "life-project"); + REQUIRE_FALSE(options->environment); + REQUIRE_FALSE(options->integrity); + } + } + GIVEN("an explicit project") { + const char* argv[] = {"WebFrontLifeDeveloper", "other"}; + const auto options = parseLifeDeveloperOptions(2, argv); + THEN("it replaces the default and keeps the pinned environment") { + REQUIRE(options); + REQUIRE(options->project == "other"); + REQUIRE_FALSE(options->environment); + } + } + GIVEN("a project with an environment archive and its integrity") { + const char* argv[] = {"WebFrontLifeDeveloper", "other", "https://example.test/environment.tgz", "sha512-abc"}; + const auto options = parseLifeDeveloperOptions(4, argv); + THEN("both are passed on") { + REQUIRE(options); + REQUIRE(options->environment == "https://example.test/environment.tgz"); + REQUIRE(options->integrity == "sha512-abc"); + } + } + GIVEN("an incomplete or empty command line") { + const char* three[] = {"WebFrontLifeDeveloper", "other", "https://example.test/environment.tgz"}; + const char* empty[] = {"WebFrontLifeDeveloper", ""}; + const char* many[] = {"WebFrontLifeDeveloper", "a", "b", "c", "d"}; + THEN("it is rejected") { + REQUIRE_FALSE(parseLifeDeveloperOptions(3, three)); + REQUIRE_FALSE(parseLifeDeveloperOptions(2, empty)); + REQUIRE_FALSE(parseLifeDeveloperOptions(5, many)); + } + } +} + +SCENARIO("The default Life project is created once and then reused") { + webfront::test::TemporaryDirectory work; + const auto project = work.path() / "life-project"; + GIVEN("a missing project directory") { + prepareLifeProject(project); + THEN("it exists") { + REQUIRE(std::filesystem::is_directory(project)); + } + WHEN("the user has edited a file and the example starts again") { + std::ofstream{project / "webfront.project.json"} << "edited"; + prepareLifeProject(project); + THEN("the content is unchanged") { + std::ifstream in{project / "webfront.project.json"}; + std::string content; + std::getline(in, content); + REQUIRE(content == "edited"); + } + } + } + GIVEN("a path occupied by a regular file") { + std::ofstream{work.path() / "occupied"} << "x"; + THEN("preparation fails so that the example exits with an error") { + REQUIRE_THROWS_AS(prepareLifeProject(work.path() / "occupied"), std::filesystem::filesystem_error); + } + } +}