lo Runtime Documentation

repository·main·Indexed 18 days ago

https://github.com/just-js/lo

Node.js bindings for the lo runtime, a system requiring C++ toolchains and dependencies like libcurl, openssl, and zlib. The documentation covers building various runtime versions (core, base, full, and zero) across Linux, macOS, and Windows, as well as API references for DNS resolution, HTML template compilation (Tokenizer and Parser), event loop management via the Loop class, and PostgreSQL socket connectivity.

Tokens
14.9K
Snippets
54
Records
63
Agent score
63%

What's inside lo

  1. Install dependencies on Linux

    main

    The default build of the lo runtime links to system libssl and zlib, but uses a custom version of libcurl to optimize startup time. You must install the development headers for these libraries using your package manager.

    sudo apt install -y libcurl4-openssl-dev libssl-dev zlib1g-dev
  2. Setup and build lo on Windows

    main

    Building on Windows requires Chocolatey, Visual Studio with C++ workloads, and make. You must use an 'x64 Native Tools' command prompt to run the build commands.

    # Install Chocolatey (Run as Administrator)
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
    # Install make and git via choco
    choco install make
    choco install git
    # Run in 'x64 Native Tools' command prompt
    make cleanall lo.exe test
  3. Build lo on Linux

    main

    Use make to build the runtime. You can specify the architecture or the compiler used.

    # Default build (x64)
    make lo
    
    # arm64 architecture
    make ARCH=arm64 lo
    
    # Using clang instead of gcc
    make CC="clang" CXX="clang++" lo
    
    # Building from a specific branch or tag
    export LO_HOME=$(pwd)
    LO_VERSION=main make lo
    CC="ccache gcc" CXX="ccache g++" LO_VERSION=main ./lo build runtime runtime/lo
    
    # Fast rebuilds using ccache and mold
    mold -run make C="ccache gcc" CC="ccache g++" lo
  4. Build the base runtime for build scripts

    main

    The base runtime is the initial runtime built to enable the construction of other runtimes. It packages the core, curl, and inflate bindings required by build scripts. Build it using:

    lo build runtime runtime/base
  5. Prerequisites for building lo

    main

    Before building the lo runtime, ensure your system has the following tools installed:

    Linux/macOS:

    • gcc/g++ or clang/clang++
    • make
    • curl
    • gunzip

    Windows:

    • Chocolatey
    • Visual Studio (with "Desktop Development with C++" workload)
    • make and git (via Chocolatey)
  6. Bump the V8 version

    main

    To update the V8 version used by lo, you must manually change the version in the Makefile and then perform a clean build.

    make cleanall
    ## change v8 version in makefile
    make lo
  7. Install dependencies and build on macOS

    main

    The lo runtime depends on libcurl (available by default) and openssl. You must install openssl via Homebrew. If your libraries are in a non-standard location, use the LIB_DIRS argument.

    # Install openssl
    brew install openssl@3
    
    # Build for x64
    make cleanall lo
    
    # Build for arm64
    make ARCH=arm64 cleanall lo
    
    # Build with custom library directories
    make LIB_DIRS=/opt/somewhere_else/lib ARCH=arm64 lo
  8. Understand the `Query` class and its `generate()` method

    main

    The Query class is responsible for generating highly optimized JavaScript code to parse the binary or text results returned by PostgreSQL.

    When query.generate() is called, it dynamically constructs a Function that uses the parser's state (like dv for DataView and buf for the buffer) to extract fields based on their OIDs (INT4OID, VARCHAROID) and formats (Binary vs Text). This avoids the overhead of generic parsing logic during high-frequency query execution.