Skip to content

Commit e1d11f5

Browse files
committed
feat: refactor build and build duckdb from source files
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 29e7f3e commit e1d11f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+6266
-2150
lines changed

.github/copilot-instructions.md

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This is a WebAssembly (WASM) monorepo providing JavaScript/TypeScript bindings f
2424
npm ci
2525

2626
# 2. Install build dependencies (20-30 minutes - NEVER CANCEL)
27-
# Includes: emsdk install (~5 min), vcpkg install (~15-20 min), playwright (~5-10 min)
27+
# Includes: emsdk install (~5 min), vcpkg install (~15-20 min), playwright (~5-10 min), bundler test deps
2828
npm run install-build-deps
2929

3030
# 3. Build C++ to WASM (30-45 minutes - NEVER CANCEL)
@@ -34,7 +34,7 @@ npm run build-cpp
3434
# 4. Build TypeScript packages (5-10 minutes)
3535
npm run build-ws
3636

37-
# 5. Full build command (45+ minutes total - NEVER CANCEL)
37+
# 5. Full build command equivalent to build-cpp + build-ws (45+ minutes total - NEVER CANCEL)
3838
# Equivalent to: build-cpp && build-ws
3939
npm run build
4040
```
@@ -49,6 +49,20 @@ From actual runs in clean environment:
4949
- `npm run build-cpp`: 30-60 minutes (C++ compilation to WASM)
5050
- `npm run test`: 15-30 minutes (includes browser and node tests)
5151

52+
## CMake / C++ (WASM) Build
53+
54+
Prefer the npm scripts. They source `./emsdk/emsdk_env.sh` and use the repo's CMake preset(s):
55+
56+
```bash
57+
npm run build-cpp
58+
```
59+
60+
For fast iteration:
61+
62+
```bash
63+
npm run build-cpp-watch
64+
```
65+
5266
### Quick Development (TypeScript Only)
5367
```bash
5468
# For TypeScript-only changes when WASM files exist
@@ -57,32 +71,15 @@ npm run build-ws # 5-10 minutes
5771
npm run lint # 2-3 minutes
5872
```
5973

60-
## CMake Configuration
61-
62-
### **CRITICAL**: ALWAYS Use VS Code CMake Extension
63-
64-
**YOU MUST use the VS Code CMake extension for ALL CMake operations.** Manual cmake commands will fail because they don't properly set up the Emscripten environment.
74+
### Manual CMake (only when needed)
6575

66-
**REQUIRED WORKFLOW** when modifying C++ code or vcpkg packages (patches, portfile.cmake):
76+
Manual CMake is supported, but you must source Emscripten first:
6777

68-
1. **Remove vcpkg cache**: `rm -rf vcpkg/buildtrees/<package>`
69-
2. **Use VS Code Command Palette** (Ctrl/Cmd+Shift+P):
70-
- **`CMake: Configure`** - Reconfigures CMake and reinstalls vcpkg packages with new patches
71-
- **`CMake: Build`** - Builds the configured targets
72-
- **`CMake: Clean Rebuild`** - Cleans and rebuilds everything
73-
74-
**WHY THIS IS REQUIRED**:
75-
- Sets up Emscripten SDK environment variables correctly
76-
- Configures vcpkg toolchain properly
77-
- Handles WASM-specific build flags
78-
- Provides IntelliSense and debugging integration
79-
80-
**DO NOT use manual cmake commands like:**
81-
-`cmake --preset vcpkg-emscripten-*` (will fail with "emcc compiler not found")
82-
-`cmake --build build --target <target>` (won't work without proper environment)
83-
-`ninja <target>` (missing environment and configuration)
84-
85-
**EXCEPTION**: `npm run build-cpp` scripts are pre-configured with the correct environment and are safe to use for full builds.
78+
```bash
79+
source ./emsdk/emsdk_env.sh
80+
cmake -S . -B ./build --preset vcpkg-emscripten-MinSizeRel
81+
cmake --build ./build --parallel
82+
```
8683

8784
## Embind (C++ <-> JS Interop)
8885

@@ -132,18 +129,6 @@ Reference: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/emb
132129
✘ [ERROR] Could not resolve "../../../build/packages/graphviz/src-cpp/graphvizlib.wasm"
133130
```
134131

135-
### DuckDB Exception
136-
The DuckDB package is special:
137-
```bash
138-
cd packages/duckdb
139-
npm run pack-duckdb # Uses pre-built WASM from @duckdb/duckdb-wasm
140-
npm run build # Can complete without C++ compilation
141-
```
142-
This works because DuckDB uses pre-compiled WASM binaries rather than building from C++ source.
143-
```
144-
ERROR: Could not resolve "../../../build/packages/graphviz/src-cpp/graphvizlib.wasm"
145-
```
146-
147132
## Testing
148133

149134
### Prerequisites
@@ -202,9 +187,10 @@ npm test
202187
### 3. End-to-End Validation
203188
```bash
204189
# Test the examples in the root directory
205-
node -e "
206-
const { Graphviz } = require('./packages/graphviz/dist/index.js');
207-
Graphviz.load().then(g => console.log(g.version()));
190+
node --input-type=module -e "
191+
import { Graphviz } from './packages/graphviz/dist/index.js';
192+
const g = await Graphviz.load();
193+
console.log(g.version());
208194
"
209195
```
210196

@@ -214,15 +200,10 @@ Graphviz.load().then(g => console.log(g.version()));
214200
- **Network restrictions**: Downloads may fail in restricted environments
215201
- **Docker alternative**: Use `npm run build-docker` if local builds fail
216202
- **SSL certificate issues**: May block package downloads
217-
- **Node.js version**: Requires Node.js 20+ for optimal compatibility
203+
- **Node.js version**: CI runs Node.js 22 and 24 (primary support); docs deploy currently uses Node.js 20
218204

219205
### Package-Specific Notes
220206

221-
#### DuckDB Package
222-
- **Special build process**: Uses pre-built WASM from @duckdb/duckdb-wasm
223-
- **Can build without C++ compilation**: Run `npm run pack-duckdb` instead
224-
- **Build command**: Uses `pack-duckdb-eh` scripts to generate WASM files
225-
226207
#### Other Packages (base91, expat, graphviz, llama, zstd)
227208
- **Require C++ compilation**: Must run `npm run build-cpp` first
228209
- **WASM dependencies**: TypeScript builds fail without WASM files
@@ -281,7 +262,7 @@ npm run build-docs # Build VitePress documentation
281262
### Advanced Build Options
282263
```bash
283264
npm run build-cpp-watch # Watch C++ files for changes
284-
npm run build-ts-watch # Watch TypeScript files
265+
npm run build-watch # Watch TypeScript files
285266
npm run build-dev # Development builds
286267
```
287268

.github/instructions/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Instructions Summary
2-
*AI Assistant instructions for hpcc-systems/hpcc-js-wasm - Updated July 2025*
2+
*AI Assistant instructions for hpcc-systems/hpcc-js-wasm - Updated December 2025*
33

44
This directory contains comprehensive instructions for AI assistants working with the HPCC-JS-WASM repository.
55

@@ -29,6 +29,7 @@ This directory contains comprehensive instructions for AI assistants working wit
2929
- **TypeScript First**: Many operations can be done with TypeScript-only builds
3030
- **Test Expectations**: Fresh clone tests will fail without WASM builds (expected)
3131
- **Safe Operations**: Documentation changes, TypeScript modifications don't need full build
32+
- **Node.js**: CI runs Node.js 22 and 24; docs deploy currently uses Node.js 20
3233

3334
## Most Common Scenarios
3435

@@ -42,7 +43,7 @@ npm run build-ws # May fail without WASM, but can still work on TS
4243
### Full Development Setup
4344
```bash
4445
npm ci
45-
npm run install-build-deps # Requires system tools
46+
npm run install-build-deps # Installs emsdk, vcpkg, playwright, bundler test deps
4647
npm run build-cpp # Compiles C++ to WASM
4748
npm run build-ws # Builds TypeScript
4849
npm run test # Full test suite

.github/instructions/main.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copilot Instructions for HPCC-JS-WASM
2-
*Last updated: July 2025 | For AI assistants working with hpcc-systems/hpcc-js-wasm*
2+
*Last updated: December 2025 | For AI assistants working with hpcc-systems/hpcc-js-wasm*
33

44
This document provides guidance for AI assistants working with the HPCC-JS-WASM repository.
55

@@ -56,7 +56,7 @@ packages/[name]/
5656
npm ci
5757

5858
# Install build dependencies (requires system tools)
59-
npm run install-build-deps # Installs emsdk, vcpkg, playwright
59+
npm run install-build-deps # Installs emsdk, vcpkg, playwright, bundler test deps
6060

6161
# Build C++ to WASM (requires emscripten)
6262
npm run build-cpp
@@ -65,6 +65,10 @@ npm run build-cpp
6565
npm run build-ws
6666
```
6767

68+
Notes:
69+
- CI runs Node.js 22 and 24; docs deploy currently uses Node.js 20.
70+
- Browser tests typically require `npx playwright install --with-deps` on Ubuntu.
71+
6872
### Quick Development (TypeScript only)
6973
```bash
7074
# Install dependencies

.github/instructions/troubleshooting.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ cd packages/base91 # Smallest package
244244
npm run build
245245

246246
# 3. Check WASM loading
247-
node -e "
248-
const fs = require('fs');
247+
node --input-type=module -e "
248+
import fs from 'node:fs';
249249
const wasm = fs.readFileSync('build/packages/base91/src-cpp/base91lib.wasm');
250250
console.log('WASM size:', wasm.length);
251251
"
@@ -277,7 +277,7 @@ time npm run build-cpp
277277
time npm run build-ws
278278

279279
# Use watch modes for development
280-
npm run build-ts-watch &
280+
npm run build-watch &
281281
npm run build-cpp-watch &
282282
```
283283

@@ -374,7 +374,7 @@ git reset --hard HEAD
374374

375375
### During Development
376376
1. **Test incrementally**: Build and test after each change
377-
2. **Watch for errors**: Use watch modes (`npm run build-ts-watch`)
377+
2. **Watch for errors**: Use watch modes (`npm run build-watch`)
378378
3. **Monitor memory**: Keep an eye on process memory usage
379379

380380
### Before Committing

.github/instructions/workflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ For comprehensive development including C++ changes:
6464
npm ci
6565

6666
# 2. Install build tools (requires system dependencies)
67-
npm run install-build-deps
67+
npm run install-build-deps # Installs emsdk, vcpkg, playwright, bundler test deps
6868

6969
# 3. Build C++ to WASM
7070
npm run build-cpp

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
uses: peaceiris/actions-gh-pages@v3
5454
with:
5555
github_token: ${{ secrets.GITHUB_TOKEN }}
56-
publish_dir: ./docs/.vitepress/dist
56+
publish_dir: ./.vitepress/dist
5757
force_orphan: true
5858
# cname: example.com # if wanna deploy to custom domain
5959
env:

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ build/
88
coverage/
99
dist/
1010
dist-test/
11-
/docs/.vitepress/cache
12-
/docs/.vitepress/dist
11+
/.vitepress/cache
12+
/.vitepress/dist
1313
/docs/base91
1414
/docs/duckdb
1515
/docs/expat
1616
/docs/graphviz
17+
/docs/llama
1718
/docs/zstd
19+
/docs/packages
1820
/docs/README.md
1921
/emsdk*
2022
/lib-*
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
export default {
1+
import { resolve } from 'path';
2+
import { defineConfig } from 'vite'
3+
4+
export default defineConfig({
25
title: '@hpcc-js/wasm',
36
description: 'HPCC Systems Wasm Libraries',
47
base: '/hpcc-js-wasm/',
5-
srcExclude: ['**/tests/**'],
8+
srcExclude: ['build/', 'cmake/', 'docker/', 'emsdk/', 'vcpkg/', 'vcpkg-overlays/', '**/tests/**'],
9+
ignoreDeadLinks: true,
610

711
themeConfig: {
812
repo: "hpcc-systems/hpcc-js-wasm",
9-
docsDir: "docs",
13+
docsDir: ".",
1014
docsBranch: "trunk",
1115
editLink: {
1216
pattern: 'https://github.com/hpcc-systems/hpcc-js-wasm/edit/trunk/docs/:path',
@@ -15,32 +19,32 @@ export default {
1519
lastUpdated: "Last Updated",
1620

1721
nav: [
18-
{ text: 'Guide', link: '/getting-started' },
22+
{ text: 'Guide', link: './docs/getting-started' },
1923
{ text: 'GitHub', link: 'https://github.com/hpcc-systems/hpcc-js-wasm' },
2024
{ text: 'Changelog', link: 'https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/CHANGELOG.md' },
2125
],
2226
sidebar: [
2327
{
2428
text: 'General',
2529
items: [
26-
{ text: 'Getting Started', link: '/getting-started' },
30+
{ text: 'Getting Started', link: '/docs/getting-started' },
2731
]
2832
},
2933
{
3034
text: 'WASM CLI',
3135
items: [
32-
{ text: 'Graphviz', link: '/graphviz-cli' },
36+
{ text: 'Graphviz', link: '/docs/graphviz-cli' },
3337
]
3438
},
3539
{
3640
text: 'WASM API',
3741
items: [
38-
{ text: 'Base91', link: '/base91/src/base91/classes/Base91' },
39-
{ text: 'DuckDB', link: '/duckdb/src/duckdb/classes/DuckDB' },
40-
{ text: 'Expat', link: '/expat/src/expat/classes/Expat' },
41-
{ text: 'Graphviz', link: '/graphviz/src/graphviz/classes/Graphviz' },
42-
{ text: 'Llama', link: '/llama/src/llama/classes/Llama' },
43-
{ text: 'Zstd', link: '/zstd/src/zstd/classes/Zstd' },
42+
{ text: 'Base91', link: '/packages/base91/README' },
43+
{ text: 'DuckDB', link: '/packages/duckdb/README' },
44+
{ text: 'Expat', link: '/packages/expat/README' },
45+
{ text: 'Graphviz', link: '/packages/graphviz/README' },
46+
{ text: 'Llama', link: '/packages/llama/README' },
47+
{ text: 'Zstd', link: '/packages/zstd/README' },
4448
]
4549
}
4650

@@ -50,4 +54,4 @@ export default {
5054
copyright: 'Copyright © 2019-present hpccsystems.com'
5155
}
5256
}
53-
}
57+
});

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
},
1515
{
1616
"type": "npm",
17-
"label": "build-ts-watch",
18-
"script": "build-ts-watch",
17+
"label": "build-watch",
18+
"script": "build-watch",
1919
"problemMatcher": [
2020
"$tsc-watch"
2121
],
@@ -72,7 +72,7 @@
7272
"label": "build",
7373
"dependsOn": [
7474
"build-types-watch",
75-
"build-ts-watch",
75+
"build-watch",
7676
"build-cpp-watch"
7777
],
7878
"group": {

0 commit comments

Comments
 (0)