Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
71bee79
feat(web): build the core to wasm behind a web host
SectionTN Nov 14, 2026
c74509b
feat(web): build every grammar as a side module
SectionTN Nov 14, 2026
b976732
feat(web): add the core facade and run the shared vectors on it
SectionTN Nov 14, 2026
582cd94
feat(web): add the web command that copies the core and languages
SectionTN Nov 14, 2026
325ccbd
feat(web): build custom languages for the web with the tree-sitter cli
SectionTN Nov 14, 2026
b792c55
feat(web): add the browser entry, the language loader and the page pump
SectionTN Nov 14, 2026
bef65cd
feat(web): draw a read-only editor from the core
SectionTN Nov 14, 2026
853ab94
fix(web): fire onReady when the first draw comes before React commits
SectionTN Nov 14, 2026
227ba1b
feat(example): run the example on web
SectionTN Nov 14, 2026
726dd21
ci: build and test the web target
SectionTN Nov 14, 2026
0046885
fix(web): load languages that inject each other at the same time
SectionTN Nov 14, 2026
5c1562e
fix(web): apply ref writes made before the core loads
SectionTN Nov 14, 2026
db981cf
fix(web): free a closed editor's engine and wrap left of the scrollbar
SectionTN Nov 14, 2026
8d44e52
ci: install emsdk outside the checkout
SectionTN Nov 14, 2026
98c0764
fix(web): keep a custom language when its web build cannot run
SectionTN Nov 14, 2026
e20eb43
fix(web): read a leading U+FEFF and a split surrogate pair as stored
SectionTN Nov 14, 2026
939b7a1
fix(web): retry the core and grammars after a network error
SectionTN Nov 14, 2026
9ad518c
fix(web): measure wrapped lines at their width and reveal the caret's…
SectionTN Nov 14, 2026
a2be250
fix(web): refuse a grammar named codepad in the web command
SectionTN Nov 14, 2026
789aaae
test(web): serve the browser tests on loopback inside the repository
SectionTN Nov 14, 2026
ba0c518
test(web): check the bold theme test draws the line it checks for ove…
SectionTN Nov 14, 2026
fe2562b
fix(web): retry a grammar whose download was cut off
SectionTN Nov 14, 2026
4405e00
test(web): serve only the harness folders by their real path
SectionTN Nov 14, 2026
c6c447b
test(swift): close threaded test engines where their posts run
SectionTN Nov 14, 2026
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
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,43 @@ jobs:

- name: Check the example's custom language package
run: |
node lib/cli/bin.js language tests/fixtures/kv_lite --out example/modules/codepad-lang-kv_lite
node lib/cli/bin.js language tests/fixtures/kv_lite --out example/modules/codepad-lang-kv_lite --no-web
git status --porcelain -- example/modules
test -z "$(git status --porcelain -- example/modules)"

test-web:
runs-on: ubuntu-24.04

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup
uses: ./.github/actions/setup

- name: Setup Emscripten
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
with:
version: 7.0.0

- name: Build the web core and grammars
run: |
yarn build:web
cpp/web/build.sh --test
yarn build:web-grammars

- name: Build package
run: yarn prepare

- name: Run the web unit tests
run: yarn jest src/web

- name: Install the browsers
run: npx playwright install --with-deps chromium webkit

- name: Run the browser tests
run: yarn test:web

build-android:
runs-on: ubuntu-24.04

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ jobs:
- name: Build package
run: yarn prepare

- name: Setup Emscripten
uses: mymindstorm/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
with:
version: 7.0.0

# The core ships lib/web and every language package ships web/<grammar>.wasm.
- name: Build the web core and grammars
run: |
yarn build:web
yarn build:web-grammars

# Trusted publishing stages each package; the versions go live once approved on npmjs.com, the core first.
# A re-run skips only the live versions, so approve or reject the staged ones before it.
- name: Stage the core, then the language packages
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ languages/.cache/
# Swift package build
.build/
.swiftpm/

# Grammar side modules for the web, built before publishing
languages/*/web/
example/modules/*/web/
5 changes: 5 additions & 0 deletions cpp/core/include/codepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
extern "C" {
#endif

#ifdef __EMSCRIPTEN__
// The web build calls the core from JS, so every entry point is exported.
#define CP_API __attribute__((used, visibility("default")))
#else
// Empty on purpose: only bindings linked into the same library call the core, so nothing is exported.
#define CP_API
#endif

typedef uint16_t cp_unit;

Expand Down
1 change: 1 addition & 0 deletions cpp/core/src/language.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "language.hpp"

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>

Expand Down
79 changes: 79 additions & 0 deletions cpp/web/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Builds the CodePad core for the browser with Emscripten.
# cpp/web/build.sh lib/web/codepad.{js,wasm} and lib/web/grammar-imports.json
# cpp/web/build.sh --test build/web-test/codepad.{js,wasm} with the test hooks
# cpp/web/build.sh --grammar <src> <out> one grammar side module from <src>/parser.c and scanner.c
set -euo pipefail

EMSCRIPTEN_VERSION=7.0.0
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
WEB=$ROOT/cpp/web
TS=$ROOT/cpp/tree-sitter/lib
PC=$ROOT/cpp/pcre2/src
CORE=$ROOT/cpp/core
OPT=-O2

if ! command -v emcc >/dev/null; then
echo "emcc not found: install Emscripten $EMSCRIPTEN_VERSION" >&2
exit 1
fi
found=$(emcc --version | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ "$found" != "$EMSCRIPTEN_VERSION" ]; then
echo "Emscripten $EMSCRIPTEN_VERSION is required, found $found" >&2
exit 1
fi

if [ "${1:-}" = --grammar ]; then
src=$2
out=$3
srcs=("$src/parser.c")
[ -f "$src/scanner.c" ] && srcs+=("$src/scanner.c")
mkdir -p "$(dirname "$out")"
emcc $OPT -fPIC -sSIDE_MODULE=1 -std=c11 -w -I"$src" "${srcs[@]}" -o "$out"
exit 0
fi

OUT=$ROOT/lib/web
OBJ=$ROOT/build/web/obj
CORE_DEFS=
if [ "${1:-}" = --test ]; then
OUT=$ROOT/build/web-test
OBJ=$ROOT/build/web-test/obj
CORE_DEFS=-DCODEPAD_TEST_HOOKS
fi
rm -rf "$OBJ"
mkdir -p "$OBJ" "$OUT"

compile() {
local src=$1
local obj
obj=$OBJ/$(basename "$(dirname "$src")")_$(basename "$src").o
case $src in
*/lib.c)
emcc -c $OPT -fPIC -std=c11 -D_POSIX_C_SOURCE=200809L -fvisibility=hidden -DTREE_SITTER_HIDE_SYMBOLS -w \
-I"$TS/include" -I"$TS/src" "$src" -o "$obj" ;;
"$PC"/*)
emcc -c $OPT -fPIC -std=c11 -fvisibility=hidden -DPCRE2_CODE_UNIT_WIDTH=16 -DHAVE_CONFIG_H -w -I"$PC" \
"$src" -o "$obj" ;;
*)
em++ -c $OPT -fPIC -std=c++20 -fvisibility=hidden -DTREE_SITTER_HIDE_SYMBOLS -DPCRE2_CODE_UNIT_WIDTH=16 \
$CORE_DEFS -I"$ROOT/cpp" -I"$TS/include" -I"$TS/src" -I"$CORE/include" -I"$PC" "$src" -o "$obj" ;;
esac
}
export -f compile
export OBJ OPT TS PC CORE ROOT CORE_DEFS

{ echo "$TS/src/lib.c"; ls "$PC"/*.c; ls "$CORE"/src/*.cpp; echo "$WEB/host.cpp"; } |
xargs -P 8 -I{} bash -c 'compile "$1"' _ {}

exports=$(sed 's/^/_/' "$WEB/exports.txt" | paste -sd, -)
em++ $OPT -sMAIN_MODULE=2 -sALLOW_MEMORY_GROWTH=1 -sFORCE_FILESYSTEM=1 -sMODULARIZE=1 \
-sEXPORT_NAME=createCodepadCore -sENVIRONMENT=web,node \
-sEXPORTED_FUNCTIONS="$exports" \
-sEXPORTED_RUNTIME_METHODS=FS,HEAPU8,HEAPU16,HEAP32,UTF8ToString,stringToNewUTF8 \
"$OBJ"/*.o -o "$OUT/codepad.js"

if [ "$OUT" = "$ROOT/lib/web" ]; then
sed 's/.*/"&"/' "$WEB/exports.txt" | paste -sd, - | sed 's/.*/[&]/' >"$OUT/grammar-imports.json"
fi
ls -l "$OUT/codepad.js" "$OUT/codepad.wasm"
35 changes: 35 additions & 0 deletions cpp/web/exports.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
malloc
free
calloc
realloc
iswspace
iswalnum
iswalpha
iswdigit
iswxdigit
iswupper
iswlower
iswpunct
towupper
towlower
strcmp
strncmp
strncpy
strlen
memcmp
memcpy
memset
memmove
__assert_fail
abort
isalnum
isalpha
isdigit
isspace
tolower
toupper
strchr
bsearch
fwrite
exit
stderr
Loading
Loading