Skip to content

Latest commit

 

History

History
157 lines (124 loc) · 9.13 KB

DISTRIBUTION.md

File metadata and controls

157 lines (124 loc) · 9.13 KB

Distributing an application

Four things help to ship a WebFront application (ADR-028): the installed library with its vcpkg port and Conan recipe, a CPack installer, a bill of materials and an optional verified updater. WebFront publishes no package, holds no key and runs no server: publishing, signing and serving updates are the application's.

Consuming WebFront as a package

cmake --install <build> --prefix <prefix> of a top-level WebFront build (WEBFRONT_INSTALL, on by default there) installs the headers, the pinned stdnet and stdexec (apart, in include/webfront-deps/), their licenses and the CMake files:

find_package(WebFront CONFIG REQUIRED)              # with a frontend: ... COMPONENTS WebKitGTK
add_executable(app main.cpp)
target_link_libraries(app PRIVATE WebFront::WebFront)

The configuration downloads nothing. It defines WebFront::WebFront, WebFront::Bdd and the public helpers (webfront_use_native_window, webfront_embed_directory, webfront_write_agent_guide, webfront_write_sbom, webfront_package, webfront_use_updater, webfront_use_distribution, webfront_generate_webkitgtk_profile, webfront_bdd_discover_tests). Differences from add_subdirectory or CPM:

  • no frontend is detected: ask for it with a component (WebKitGTK, WKWebView, WebView2) or -DWEBFRONT_EMBED_...=ON;
  • WebView2 also needs WEBFRONT_WEBVIEW2_SDK_DIR, an extracted Microsoft.Web.WebView2 NuGet package;
  • CEF, webfront_add_jasmine_test and the wf tools are not part of the package;
  • a target stdnet::stdnet or STDEXEC::stdexec that your project already defines is used instead of the bundled headers.

A WebFront installed with a compiler whose standard library has std::execution holds no stdexec, and is refused by a compiler without it.

vcpkg and Conan

Both recipes are in the repository and build the checkout they sit in. They are not published in the vcpkg or Conan registries. Their installation step downloads the pinned stdnet and stdexec archives and verifies their digests; afterwards your project configures with no network.

vcpkg install webfront --overlay-ports=<checkout>/cmake/packaging/vcpkg
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=<vcpkg>/scripts/buildsystems/vcpkg.cmake

conan create <checkout>/cmake/packaging/conan -s compiler.cppstd=23
# conanfile.txt: [requires] webfront/1.3.0, [generators] CMakeDeps CMakeToolchain
conan install . -s compiler.cppstd=23 --output-folder=build
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake

vcpkg's binary cache does not see changes of the checkout: use --binarysource=clear after changing WebFront.

To build WebFront itself without downloading, give the sources of the pinned dependencies (cmake/WebFrontDependencies.cmake): -DWEBFRONT_STDNET_SOURCE_DIR=... -DWEBFRONT_STDEXEC_SOURCE_DIR=....

Installers

webfront_package(app NAME "My App" VERSION 1.2.0 VENDOR "Me" CONTACT "me@example.org" IDENTIFIER org.example.app
    APPARMOR_ABI 4.0 LICENSE_FILE LICENSE
    SBOM SBOM_ARGUMENTS LOCK "${CMAKE_SOURCE_DIR}/webfront-packages.lock.json"
    SIGN_COMMAND codesign --force --sign "My identity")

Then cmake --build <build> --target package (or cpack in it) writes one installer of that application only:

System Format Installs Removal
Linux Debian package /usr/bin, a desktop entry, /usr/share/<name> (SBOM, FILES), /usr/share/doc/<name> (license) apt remove / dpkg --purge
macOS disk image (DragNDrop) the .app bundle, copied by the user deleting the bundle
Windows NSIS installer (NSIS 3 required to build it) Program Files, a start-menu entry its uninstaller, also in Settings
  • WebKitGTK. The application is built for distribution (the sandbox is required) and the package depends on libwebkitgtk-6.0-4. APPARMOR_ABI 4.0 adds the sandbox profile of the installed executable, loaded at installation, for Ubuntu 24.04 and later; without it, no profile is packaged. RPM and AppImage are not produced.
  • WebView2. The installer looks for the Evergreen runtime. When it is absent it runs WEBVIEW2_BOOTSTRAPPER, the MicrosoftEdgeWebview2Setup.exe you downloaded from Microsoft and ship under its terms; without one it only says so.
  • Signing. SIGN_COMMAND runs on the staged executable, or the macOS bundle, with its path appended: codesign, signtool sign /fd SHA256 ..., or your own tool, with your identity. A failure stops the packaging. Signing the installer itself, notarizing a disk image and signing a Debian repository are done afterwards with the platform's tools; without them, macOS Gatekeeper and Windows SmartScreen warn or refuse.
  • Libraries that the application needs and the system lacks are yours to install (FILES, DEPENDS). Link the MSVC runtime statically, as the Life package does, or ship its redistributable.

The CI packages the embedded Game of Life this way on the three systems, installs it, runs --check and removes it (test/cmake/CheckLifeInstaller.cmake). It does not open the installed application's window.

Verified updates

<webfront/components/update/Updater.hpp> is optional and outside the core (ADR-010). It replaces one executable file with a candidate whose signature matches the application's public key:

webfront_use_updater(app)   # CNG on Windows, Security.framework on macOS, OpenSSL's libcrypto 3 elsewhere
using namespace webfront::update;
Updater updater{executablePath()};
updater.recover();                                    // first thing at start-up
// ... download the new executable and its signature, by your own means ...
updater.apply(candidate, signature, PublicKey::fromPem(myPublicKey));  // then restart
// ... in the new version, once it works:
updater.confirm();

The signature is ECDSA P-256 with SHA-256 in DER, which the three systems verify natively; WebFront implements no cryptography. Create the key and sign a release with OpenSSL, and keep the private key off the build and update servers:

openssl ecparam -name prime256v1 -genkey -noout -out update-key.pem
openssl ec -in update-key.pem -pubout -out update-key.pub    # embed this one
openssl dgst -sha256 -sign update-key.pem -out app.sig app
  • The candidate is copied beside the executable and the copy is verified: a refused signature changes nothing.
  • The former executable stays beside it until confirm(). rollback() restores it; recover() restores it too after three starts without confirmation (recover(n) changes the number), or after an interrupted update that left no executable.
  • Linux and macOS swap with one atomic rename. Windows is not atomic: a running image cannot be replaced, so it is renamed away and the new file renamed in place. A power cut between the two leaves no executable under its name; recover() restores it, but must then be run by what starts the application (a launcher, a service or the installer).
  • The signature says who produced the file, not that it is newer: compare versions, from data you trust, before apply().
  • It replaces one file. It does not update a macOS bundle (replacing its executable breaks the bundle's signature), an application installed where it cannot write (/usr/bin, Program Files without elevation), or resources beside it.
  • One updater at a time works on an executable.

Bill of materials

webfront_write_sbom(
    OUTPUT  "${CMAKE_BINARY_DIR}/myapp.spdx.json"
    NAME    myapp
    VERSION 1.2.0
    LICENSE MIT
    LOCK    "${CMAKE_SOURCE_DIR}/webfront-packages.lock.json"
    PACKAGE extra 2.0 https://example.org/extra
    SYSTEM  libfoo 3.1
    LICENSES extra BSD-3-Clause)

It writes SPDX 2.3 JSON at configure time (and again at the next build when the lock or a Git revision of those sources changes), listing:

  • WebFront, stdnet and, when it is used, stdexec, at the commit of the sources the build uses (NOASSERTION for a copy without Git history; an installed package records the revisions it was built from). A STDEXEC::stdexec of your own is not listed: add it with PACKAGE;
  • every package of the wf lock, with its version, integrity and the license of its manifest. A lock also holds development tools whose code is not in the shipped bundle: the list is an upper bound of the JavaScript you ship;
  • the C++ standard library of the compiler, and OpenSSL when webfront_use_updater() was called before;
  • the web engines of the enabled frontends (WebKitGTK with the version of the build machine, the WebView2 SDK and runtime, macOS's WebKit, CEF), or those given with ENGINES (NONE for none);
  • your PACKAGE and SYSTEM entries.

Licenses are those the sources declare, or yours (LICENSE, LICENSES); the others are NOASSERTION, and nothing is concluded. It is not a scan of the binary and not a statement of compliance. Set SOURCE_DATE_EPOCH for the same bytes from the same inputs.

Elsewhere