diff --git a/docs/guides/linux-native-headless-sdk.md b/docs/guides/linux-native-headless-sdk.md index 5f0ab3b25..fceec3dfa 100644 --- a/docs/guides/linux-native-headless-sdk.md +++ b/docs/guides/linux-native-headless-sdk.md @@ -1,8 +1,10 @@ # Linux native headless SDK profile -The Linux x86_64 SDK is a Native-only producer profile. It installs `WebScene::Core`, `NativeWeb`, `SharedCSS`, `Compiler`, and optionally `WebGPU`. It does not build or package V8, the Runtime component, application scripts or runtime-loaded application HTML. The SDK compiler links the full HTML/CSS/selector parser archive as a build-time tool. `WebScene::SharedCSS` links a separate CSS/selector-only archive whose checked symbol surface contains no runtime HTML entry points or `html5ever` implementation. The compiler/ABI pin is LLVM 22.1.1 with libc++. See `src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake` and the checksum-pinned installer in `eng/sdk/install-linux-llvm.py`. +The Linux x86_64 SDK is Native-only by default. It installs `WebScene::Core`, `NativeWeb`, `SharedCSS`, `Compiler`, and optionally `WebGPU` without V8 or runtime-loaded application HTML. Set `WEBSCENE_SDK_RUNTIME=ON` only for an installed full-V8 Runtime package; that opt-in profile adds `WebScene::Runtime`, ICU/snapshot data, media, WebSocket, crypto, and the pinned Dawn/ANGLE closure. The SDK compiler links the full HTML/CSS/selector parser archive as a build-time tool. `WebScene::SharedCSS` links a separate CSS/selector-only archive whose checked symbol surface contains no runtime HTML entry points or `html5ever` implementation. The compiler/ABI pin is LLVM 22.1.1 with libc++. See `src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake` and the checksum-pinned installer in `eng/sdk/install-linux-llvm.py`. -HTML/templates are still compiled to C++20 at build time. Applications explicitly select `CSS_BACKEND shared`; native CSS parsing is allowed. The Linux package exports relocatable imported targets and a platform marker so a macOS binary SDK cannot accidentally be consumed on Linux. Requesting unavailable Runtime components fails rather than substituting another host. +HTML/templates are still compiled to C++20 at build time in the default profile. Applications explicitly select `CSS_BACKEND shared`; native CSS parsing is allowed. The Linux package exports relocatable imported targets and a platform marker so a macOS binary SDK cannot accidentally be consumed on Linux. Requesting an unavailable Runtime component fails rather than substituting another host. + +Large established JavaScript products use the opt-in Runtime profile. Code OSS is the reference case: keep the upstream workbench and Node service unchanged, consume the installed AppScene/WebScene Runtime through the SDK/CLI, and **do not port** VS Code application logic to C++ merely to use the native host. ## Offscreen WebGPU diff --git a/docs/validation/linux-installed-runtime-sdk-810-809-687.md b/docs/validation/linux-installed-runtime-sdk-810-809-687.md new file mode 100644 index 000000000..20dba4a1f --- /dev/null +++ b/docs/validation/linux-installed-runtime-sdk-810-809-687.md @@ -0,0 +1,23 @@ +# Installed Linux Runtime SDK (#810) + +The Linux SDK keeps its existing Native-only default. Opting into +`WEBSCENE_SDK_RUNTIME=ON` now selects the static full-V8 engine and installs a +relocatable `WebScene::Runtime` closure: media, WebSocket, HTML parser, V8, +Mbed TLS crypto, Dawn, ANGLE, OpenSSL/Zlib system dependencies, ICU data, and +the bootstrap snapshot and metadata. The installed config checks every +runtime data file before exporting the target and still reports Runtime as a +missing component when the producer option is off. + +The Runtime contains no application module and adds no Electron, Chromium, +CEF, WebView, browser process, or Code OSS source change. Runtime selection is +a configure/install concern and adds zero per-frame CSS cascade, layout, +visual-tree, scene, or scheduling work. Demand-driven behavior remains owned +by the engine and AppScene platform host gates. + +`scripts/test_linux_runtime_sdk_source.py` records the option/default, +installed closure, fail-closed component, ordered link dependency, and Code +OSS no-port documentation contracts. The focused installed-consumer, +relocation, ABI/export, package logical/allocated size, entry-count, +duplicate, dependency, cache cleanup, unchanged Code OSS, VM, memory, +lifecycle, idle CPU/frame, and performance gates are **authored, not +executed** under the current fast-merge direction. diff --git a/eng/sdk/verify-linux-runtime-package.py b/eng/sdk/verify-linux-runtime-package.py new file mode 100755 index 000000000..1c7bbaf60 --- /dev/null +++ b/eng/sdk/verify-linux-runtime-package.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +"""Fail closed when an installed Linux Runtime SDK exceeds package budgets.""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path + + +DEFAULT_LOGICAL_BYTES = 1_200_000_000 +DEFAULT_ALLOCATED_BYTES = 1_350_000_000 +DEFAULT_ENTRY_COUNT = 20_000 +LARGE_FILE_BYTES = 1_048_576 +REQUIRED = ( + "lib/libwebscene_native_engine.a", + "lib/libwebscene_media.a", + "lib/libixwebsocket.a", + "lib/libmbedcrypto.a", + "lib/libv8_monolith.a", + "lib/libwebgpu_dawn.so", + "lib/libEGL.so", + "lib/libGLESv2.so", + "share/webscene/runtime/icudtl.dat", + "share/webscene/runtime/webscene_bootstrap_snapshot.bin", + "share/webscene/runtime/webscene_bootstrap_snapshot.meta", + "share/licenses/WebScene/V8-LICENSE", + "share/licenses/WebScene/MbedTLS-LICENSE", + "share/licenses/WebScene/IXWebSocket-LICENSE", +) +FORBIDDEN_SUFFIXES = (".o", ".obj", ".map", ".pdb", ".dSYM") + + +def digest(path: Path) -> str: + value = hashlib.sha256() + with path.open("rb") as stream: + for block in iter(lambda: stream.read(1024 * 1024), b""): + value.update(block) + return value.hexdigest() + + +def audit(root: Path, logical_budget: int, allocated_budget: int, + entry_budget: int) -> dict[str, object]: + missing = [name for name in REQUIRED if not (root / name).is_file()] + if missing: + raise RuntimeError("missing Linux Runtime SDK entries: " + ", ".join(missing)) + + entries = sorted(path for path in root.rglob("*") if not path.is_dir()) + forbidden = [str(path.relative_to(root)) for path in entries + if path.name.endswith(FORBIDDEN_SUFFIXES)] + if forbidden: + raise RuntimeError("developer artifacts entered Runtime SDK: " + ", ".join(forbidden)) + + regular = [path for path in entries if path.is_file() and not path.is_symlink()] + logical = sum(path.stat().st_size for path in regular) + allocated = sum(path.stat().st_blocks * 512 for path in regular) + if len(entries) > entry_budget: + raise RuntimeError(f"entry budget exceeded: {len(entries)} > {entry_budget}") + if logical > logical_budget: + raise RuntimeError(f"logical byte budget exceeded: {logical} > {logical_budget}") + if allocated > allocated_budget: + raise RuntimeError( + f"allocated byte budget exceeded: {allocated} > {allocated_budget}" + ) + + by_digest: dict[str, list[str]] = {} + for path in regular: + if path.stat().st_size < LARGE_FILE_BYTES: + continue + by_digest.setdefault(digest(path), []).append(str(path.relative_to(root))) + duplicates = [paths for paths in by_digest.values() if len(paths) > 1] + if duplicates: + raise RuntimeError( + "duplicate large payloads entered Runtime SDK: " + json.dumps(duplicates) + ) + + return { + "schema": "webscene-linux-runtime-package-v1", + "entryCount": len(entries), + "logicalBytes": logical, + "allocatedBytes": allocated, + "budgets": { + "entryCount": entry_budget, + "logicalBytes": logical_budget, + "allocatedBytes": allocated_budget, + }, + "largePayloadCount": len(by_digest), + "duplicateLargePayloads": [], + } + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("sdk", type=Path) + parser.add_argument("--logical-bytes", type=int, default=DEFAULT_LOGICAL_BYTES) + parser.add_argument("--allocated-bytes", type=int, default=DEFAULT_ALLOCATED_BYTES) + parser.add_argument("--entries", type=int, default=DEFAULT_ENTRY_COUNT) + parser.add_argument("--output", type=Path) + args = parser.parse_args() + root = args.sdk.resolve() + if not root.is_dir(): + parser.error(f"SDK root is not a directory: {root}") + result = audit(root, args.logical_bytes, args.allocated_bytes, args.entries) + encoded = json.dumps(result, indent=2, sort_keys=True) + "\n" + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(encoded) + print(encoded, end="") + + +if __name__ == "__main__": + main() diff --git a/scripts/test_linux_runtime_sdk_source.py b/scripts/test_linux_runtime_sdk_source.py new file mode 100755 index 000000000..7a5bf189c --- /dev/null +++ b/scripts/test_linux_runtime_sdk_source.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +"""Source contract for the opt-in installed Linux Runtime SDK.""" + +from pathlib import Path +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +PRODUCER = ( + ROOT / "src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake" +).read_text() +CONFIG = ( + ROOT / "src/WebScene.Sdk/cmake/WebSceneLinuxConfig.cmake" +).read_text() +GUIDE = (ROOT / "docs/guides/linux-native-headless-sdk.md").read_text() +PACKAGE_AUDIT = ( + ROOT / "eng/sdk/verify-linux-runtime-package.py" +).read_text() + + +class LinuxRuntimeSdkSourceContract(unittest.TestCase): + def test_runtime_is_explicit_and_default_native_profile_is_preserved(self): + self.assertIn( + 'option(WEBSCENE_SDK_RUNTIME "Include the optional JavaScript Runtime component" OFF)', + PRODUCER, + ) + self.assertIn("if(WEBSCENE_SDK_RUNTIME)", PRODUCER) + self.assertIn("WebScene_SDK_RUNTIME ${WEBSCENE_SDK_RUNTIME}", PRODUCER) + + def test_installs_complete_runtime_link_and_data_closure(self): + for value in ( + "webscene_native_engine", + "webscene_media", + "ixwebsocket", + "mbedcrypto", + "libv8_monolith.a", + "icudtl.dat", + "webscene_bootstrap_snapshot.bin", + "webscene_bootstrap_snapshot.meta", + "libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}", + "libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}", + ): + self.assertIn(value, PRODUCER) + + def test_consumer_fails_closed_and_exports_ordered_runtime_closure(self): + self.assertIn("if(WebScene_SDK_RUNTIME)", CONFIG) + self.assertIn("Incomplete Linux Runtime SDK", CONFIG) + self.assertIn("_ws_linux_static(Runtime libwebscene_native_engine.a)", CONFIG) + runtime_link = CONFIG.index( + "WebScene::Runtime PROPERTY INTERFACE_LINK_LIBRARIES" + ) + for dependency in ( + "WebScene::_Media", + "WebScene::_WebSocket", + "WebScene::_Parser", + "WebScene::_V8", + "WebScene::_Crypto", + "WebScene::WebGPU", + "WebScene::_AngleEGL", + "WebScene::_AngleGLESv2", + "OpenSSL::SSL", + "ZLIB::ZLIB", + ): + self.assertIn(dependency, CONFIG[runtime_link:]) + + def test_guide_keeps_code_oss_on_unchanged_runtime_path(self): + self.assertIn("Code OSS", GUIDE) + self.assertIn("Do not port", GUIDE) + self.assertIn("WEBSCENE_SDK_RUNTIME=ON", GUIDE) + + def test_package_gate_budgets_disk_and_duplicate_payloads(self): + for contract in ( + "DEFAULT_LOGICAL_BYTES", + "DEFAULT_ALLOCATED_BYTES", + "DEFAULT_ENTRY_COUNT", + "FORBIDDEN_SUFFIXES", + "duplicate large payloads", + "st_blocks * 512", + "webscene-linux-runtime-package-v1", + ): + self.assertIn(contract, PACKAGE_AUDIT) + self.assertIn("verify-linux-runtime-package.py", PRODUCER) + + +if __name__ == "__main__": + unittest.main() diff --git a/src/WebScene.Sdk/cmake/WebSceneLinuxConfig.cmake b/src/WebScene.Sdk/cmake/WebSceneLinuxConfig.cmake index b75689bc8..9f63f4dbf 100644 --- a/src/WebScene.Sdk/cmake/WebSceneLinuxConfig.cmake +++ b/src/WebScene.Sdk/cmake/WebSceneLinuxConfig.cmake @@ -9,6 +9,10 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR NOT CMAKE_CXX_COMPILER_VERSION message(FATAL_ERROR "This SDK requires LLVM 22.1.1/libc++; use WebSceneToolchain.cmake") endif() find_dependency(Threads) +if(WebScene_SDK_RUNTIME) + find_dependency(OpenSSL) + find_dependency(ZLIB) +endif() get_filename_component(WebScene_SDK_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) function(_ws_linux_static name file) if(NOT EXISTS "${WebScene_SDK_ROOT}/lib/${file}") @@ -22,6 +26,14 @@ function(_ws_linux_static name file) INTERFACE_COMPILE_OPTIONS "-stdlib=libc++" INTERFACE_LINK_OPTIONS "-stdlib=libc++") endfunction() +function(_ws_linux_shared name file) + if(NOT EXISTS "${WebScene_SDK_ROOT}/lib/${file}") + message(FATAL_ERROR "Incomplete Linux SDK: missing ${file}") + endif() + add_library(WebScene::${name} SHARED IMPORTED GLOBAL) + set_target_properties(WebScene::${name} PROPERTIES + IMPORTED_LOCATION "${WebScene_SDK_ROOT}/lib/${file}") +endfunction() if(NOT TARGET WebScene::Core) _ws_linux_static(Core libwebscene_core.a) _ws_linux_static(NativeWeb libwebscene_native_web.a) @@ -43,6 +55,28 @@ if(NOT TARGET WebScene::Core) INTERFACE_INCLUDE_DIRECTORIES "${WebScene_SDK_ROOT}/include/graphics" INTERFACE_COMPILE_DEFINITIONS "WEBSCENE_DAWN_LINUX_EXTERNAL_FACTORY_VERSION=1;WEBSCENE_DAWN_NATIVE_DEVICE_ABI_VERSION=1;WEBSCENE_DAWN_NATIVE_DEVICE_ABI_VERSION_V2=2;WEBSCENE_DAWN_NATIVE_DEVICE_ABI_VERSION_V3=3") endif() + if(WebScene_SDK_RUNTIME) + foreach(_ws_runtime_data IN ITEMS + icudtl.dat webscene_bootstrap_snapshot.bin + webscene_bootstrap_snapshot.meta) + if(NOT EXISTS + "${WebScene_SDK_ROOT}/share/webscene/runtime/${_ws_runtime_data}") + message(FATAL_ERROR + "Incomplete Linux Runtime SDK: missing ${_ws_runtime_data}") + endif() + endforeach() + _ws_linux_static(_Media libwebscene_media.a) + _ws_linux_static(_WebSocket libixwebsocket.a) + _ws_linux_static(_V8 libv8_monolith.a) + _ws_linux_static(_Crypto libmbedcrypto.a) + _ws_linux_shared(_AngleEGL "libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}") + _ws_linux_shared(_AngleGLESv2 "libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}") + _ws_linux_static(Runtime libwebscene_native_engine.a) + set_property(TARGET WebScene::Runtime PROPERTY INTERFACE_LINK_LIBRARIES + "WebScene::Core;WebScene::_Media;WebScene::_WebSocket;WebScene::_Parser;WebScene::_V8;WebScene::_Crypto;WebScene::WebGPU;WebScene::_AngleEGL;WebScene::_AngleGLESv2;OpenSSL::SSL;OpenSSL::Crypto;ZLIB::ZLIB;Threads::Threads;${CMAKE_DL_LIBS};rt") + set(WebScene_RUNTIME_DIRECTORY + "${WebScene_SDK_ROOT}/share/webscene/runtime") + endif() add_executable(WebScene::Compiler IMPORTED GLOBAL) set_property(TARGET WebScene::Compiler PROPERTY IMPORTED_LOCATION "${WebScene_SDK_ROOT}/bin/webscene-uic") endif() @@ -56,7 +90,8 @@ foreach(component IN LISTS WebScene_FIND_COMPONENTS) set(WebScene_${component}_FOUND FALSE) if(WebScene_FIND_REQUIRED_${component}) set(WebScene_FOUND FALSE) - string(APPEND WebScene_NOT_FOUND_MESSAGE "Component ${component} is not installed in this native-only Linux SDK. ") + string(APPEND WebScene_NOT_FOUND_MESSAGE + "Component ${component} is not installed in this Linux SDK profile. ") endif() endif() endforeach() diff --git a/src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake b/src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake index 3a3816b49..cfbd03754 100644 --- a/src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake +++ b/src/WebScene.Sdk/cmake/WebSceneLinuxSDK.cmake @@ -1,4 +1,5 @@ -# Native-only Linux producer. The existing macOS Runtime profile is unchanged. +# Linux producer. Runtime remains opt-in so the native-only package and its +# dependency closure stay unchanged for existing consumers. if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") message(FATAL_ERROR "The Linux SDK profile currently targets x86_64") endif() @@ -10,8 +11,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(WEBSCENE_SDK_WEBGPU "Include pinned Dawn/Vulkan native authoring support" ON) option(WEBSCENE_SDK_RUNTIME "Include the optional JavaScript Runtime component" OFF) -if(WEBSCENE_SDK_RUNTIME) - message(FATAL_ERROR "This Linux SDK profile is Native-only; Runtime/hybrid is not qualified") +if(WEBSCENE_SDK_RUNTIME AND NOT WEBSCENE_SDK_WEBGPU) + message(FATAL_ERROR + "The Linux Runtime profile requires WEBSCENE_SDK_WEBGPU=ON") endif() set(BUILD_TESTING OFF CACHE BOOL "Validate through installed SDK consumers" FORCE) set(WEBSCENE_NATIVE_WEB_SDK_BUILD ON) @@ -53,8 +55,51 @@ if(WEBSCENE_SDK_WEBGPU) install(FILES "${WEBSCENE_GRAPHICS_SDK_ROOT}/dawn/webscene-graphics-package.json" "${WEBSCENE_ROOT}/eng/graphics/dependencies.lock.json" DESTINATION share/webscene/dependencies) endif() +if(WEBSCENE_SDK_RUNTIME) + set(WEBSCENE_NATIVE_ENGINE_STATIC ON CACHE BOOL "" FORCE) + set(WEBSCENE_NATIVE_ENGINE_ENABLE_V8 ON CACHE BOOL "" FORCE) + set(WEBSCENE_NATIVE_ENGINE_ENABLE_GRAPHICS ON CACHE BOOL "" FORCE) + set(WEBSCENE_COMPILED_APPLICATION_MODULE "" CACHE FILEPATH + "SDK Runtime never contains application code" FORCE) + add_subdirectory( + "${WEBSCENE_ROOT}/experiments/WebScene.NativeEngine.Probe" runtime) + add_library(WebScene::Runtime ALIAS webscene_native_engine) + + install(TARGETS webscene_native_engine webscene_media ixwebsocket + mbedcrypto ARCHIVE DESTINATION lib) + install(FILES + "${WEBSCENE_V8_OUTPUT_ROOT}/obj/libv8_monolith.a" + DESTINATION lib) + install(FILES + "${WEBSCENE_V8_OUTPUT_ROOT}/icudtl.dat" + "${CMAKE_CURRENT_BINARY_DIR}/runtime/webscene_bootstrap_snapshot.bin" + "${CMAKE_CURRENT_BINARY_DIR}/runtime/webscene_bootstrap_snapshot.meta" + DESTINATION share/webscene/runtime) + install(FILES + "${WEBSCENE_GRAPHICS_SDK_ROOT}/${WEBSCENE_GRAPHICS_ANGLE_VARIANT}/lib/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}" + "${WEBSCENE_GRAPHICS_SDK_ROOT}/${WEBSCENE_GRAPHICS_ANGLE_VARIANT}/lib/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}" + DESTINATION lib) + install(FILES + "${WEBSCENE_V8_ROOT}/LICENSE" + DESTINATION share/licenses/WebScene RENAME V8-LICENSE) + install(FILES + "${CMAKE_BINARY_DIR}/webscene-miniaudio-LICENSE" + DESTINATION share/licenses/WebScene) + install(FILES + "${CMAKE_BINARY_DIR}/_deps/webscene_ixwebsocket-src/LICENSE.txt" + DESTINATION share/licenses/WebScene RENAME IXWebSocket-LICENSE) + install(FILES + "${CMAKE_BINARY_DIR}/_deps/webscene_mbedtls-src/LICENSE" + DESTINATION share/licenses/WebScene RENAME MbedTLS-LICENSE) + install(DIRECTORY + "${WEBSCENE_GRAPHICS_SDK_ROOT}/${WEBSCENE_GRAPHICS_ANGLE_VARIANT}/licenses/" + DESTINATION share/licenses/WebScene/ANGLE) + install(PROGRAMS + "${WEBSCENE_ROOT}/eng/sdk/verify-linux-runtime-package.py" + DESTINATION share/webscene/tools) +endif() file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/WebSceneLinuxProfile.cmake" - "set(WebScene_SDK_PLATFORM Linux)\nset(WebScene_SDK_PROCESSOR x86_64)\nset(WebScene_SDK_WEBGPU ${WEBSCENE_SDK_WEBGPU})\nset(WebScene_SDK_RUNTIME OFF)\n") + "set(WebScene_SDK_PLATFORM Linux)\nset(WebScene_SDK_PROCESSOR x86_64)\nset(WebScene_SDK_WEBGPU ${WEBSCENE_SDK_WEBGPU})\nset(WebScene_SDK_RUNTIME ${WEBSCENE_SDK_RUNTIME})\n") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/WebSceneLinuxProfile.cmake" DESTINATION lib/cmake/WebScene) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" DESTINATION lib/cmake/WebScene) include(CMakePackageConfigHelpers)