Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,53 @@ npm run build-ws # 5-10 minutes
npm run lint # 2-3 minutes
```

## CMake Configuration

### **CRITICAL**: ALWAYS Use VS Code CMake Extension

**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.

**REQUIRED WORKFLOW** when modifying C++ code or vcpkg packages (patches, portfile.cmake):

1. **Remove vcpkg cache**: `rm -rf vcpkg/buildtrees/<package>`
2. **Use VS Code Command Palette** (Ctrl/Cmd+Shift+P):
- **`CMake: Configure`** - Reconfigures CMake and reinstalls vcpkg packages with new patches
- **`CMake: Build`** - Builds the configured targets
- **`CMake: Clean Rebuild`** - Cleans and rebuilds everything

**WHY THIS IS REQUIRED**:
- Sets up Emscripten SDK environment variables correctly
- Configures vcpkg toolchain properly
- Handles WASM-specific build flags
- Provides IntelliSense and debugging integration

**DO NOT use manual cmake commands like:**
- ❌ `cmake --preset vcpkg-emscripten-*` (will fail with "emcc compiler not found")
- ❌ `cmake --build build --target <target>` (won't work without proper environment)
- ❌ `ninja <target>` (missing environment and configuration)

**EXCEPTION**: `npm run build-cpp` scripts are pre-configured with the correct environment and are safe to use for full builds.

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

This repo uses Emscripten Embind to expose C++ APIs to JavaScript/TypeScript.

Reference: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html

### Guidelines
- Prefer Embind over ad-hoc JS glue when exposing C++ to JS.
- Avoid throwing across the WASM boundary; catch exceptions in C++ and translate into explicit error results.
- Be explicit about ownership/lifetime:
- If you return raw pointers (often created with `new`) via Embind, JS must eventually free them (e.g. via the generated `.delete()` method or `Module.destroy(obj)` depending on how the wrapper is used).
- If practical, bind smart pointers (e.g. `std::unique_ptr` / `std::shared_ptr`) to make ownership explicit.
- For JS values, prefer `emscripten::val` and convert at the boundary (e.g. arrays -> `val.isArray()` + `val["length"]`). Validate types and reject non-finite numbers.
- Keep interop-friendly result types: materialize streaming results where needed for JS access patterns.

### Common Patterns Used Here
- `EMSCRIPTEN_BINDINGS(...)` with `emscripten::class_<T>` and `.function(...)`.
- `allow_raw_pointers()` is used for functions that accept/return pointer types.
- Provide small helper conversions (JS `val` -> C++ types) and centralize error messages for predictable JS behavior.

## Working Without Full Build

### What Works with npm ci + npm run lint Only
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ types/
/wasi-sdk*
/wit-bindgen
/vcpkg
__screenshots__/
.coveralls.yml
*.tsbuildinfo

Expand Down
37 changes: 1 addition & 36 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
{
"cmake.cmakePath": "${workspaceFolder}/scripts/cmake.sh",
"vitest.maximumConfigs": 20,
"vitest.configSearchPatternExclude": "{emsdk/**,node_modules/**}",

// AI Assistant Configuration
"github.copilot.enable": {
"*": true,
"markdown": true,
"typescript": true,
"javascript": true
},

// File associations for better AI context
"files.associations": {
"*.idl": "webidl",
"*.wasm": "wasm",
".copilot-*": "markdown"
},

// Exclude build artifacts from AI context
"files.exclude": {
"**/build/**": true,
"**/dist/**": true,
"**/node_modules/**": true,
"**/emsdk/**": true,
"**/vcpkg/**": true,
"**/.nyc_output/**": true
},

// Include important files for AI context
"search.exclude": {
"**/node_modules": true,
"**/emsdk": true,
"**/vcpkg": true,
"**/build": true,
"**/dist": false,
"**/.copilot-*": false
}
"vitest.configSearchPatternExclude": "{emsdk/**,node_modules/**}"
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
endif ()

add_subdirectory(packages/base91/src-cpp)
add_subdirectory(packages/duckdb/src-cpp)
add_subdirectory(packages/expat/src-cpp)
add_subdirectory(packages/graphviz/src-cpp)
add_subdirectory(packages/llama/src-cpp)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

This repository contains a collection of useful c++ libraries compiled to WASM for (re)use in Node JS, Web Browsers and JavaScript Libraries:
- [base91](https://base91.sourceforge.net/) - v0.6.0
- [duckdb](https://github.com/duckdb/duckdb) - v1.4.0
- [duckdb](https://github.com/duckdb/duckdb) - v1.4.3
- [expat](https://libexpat.github.io/) - v2.7.1
- [graphviz](https://www.graphviz.org/) - 14.1.0
- [llama.cpp](https://github.com/ggerganov/llama.cpp) - b3718
Expand Down
Loading
Loading