Skip to content

feat: fix build with latest llama.cpp, security-upgrade deps, improve DX#200

Open
aviallon wants to merge 8 commits intongxson:masterfrom
aviallon:feat/fix-build-with-latest-llama.cpp
Open

feat: fix build with latest llama.cpp, security-upgrade deps, improve DX#200
aviallon wants to merge 8 commits intongxson:masterfrom
aviallon:feat/fix-build-with-latest-llama.cpp

Conversation

@aviallon
Copy link

@aviallon aviallon commented Jan 15, 2026

@ngxson Here are my modifications to be able to build wllama with the latest's llama.cpp's code (including my recent PRs).

Summary by CodeRabbit

  • Chores
    • Established comprehensive Docker-based testing infrastructure with WASM testing capabilities
    • Enhanced support for ARM64 processors with architecture-aware build configuration
    • Added configurable build options for CPU repack optimizations and WASM memory settings
    • Improved test scripting framework for development and CI/CD workflows

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

The changes add comprehensive test infrastructure for Docker and WebAssembly, configure new build options (GGML CPU repack and WASM memory64), update Docker Compose services, and mark auto-generated files. Build scripts are enhanced with strict error handling, ARM64 architecture detection, and EMSDK version updates.

Changes

Cohort / File(s) Summary
Configuration & Build
.gitattributes, src/workers-code/.gitattributes, .gitignore, CMakeLists.txt, package.json
Mark generated source files as linguist-generated; ignore screenshot artifacts; add GGML_CPU_REPACK and LLAMA_WASM_MEM64 build options; introduce test:docker and test:wasm npm scripts
Build & Test Scripts
scripts/build_wasm.sh, scripts/test_in_docker.sh, scripts/test_wasm.sh
Enable strict error handling in build script; bump EMSDK tag to 4.0.23; enhance ARM64 processor detection and Docker platform configuration; add two new test orchestration scripts for Docker and WASM testing
Docker Compose Configuration
scripts/docker-compose.yml
Add wllama-test service with Playwright runner; add llamacpp-wasm-tests service with inline Dockerfile and test setup; refactor llamacpp-wasm-builder with SHARED_EMCC_CFLAGS array, EMSCRIPTEN_SYSTEM_PROCESSOR setting, and improved multi-thread build sequence
Code Changes
cpp/wllama.cpp
Widen memory calculation types from unsigned int to uintptr_t in wllama_debug() function

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰✨ New docker homes and wasm spins,
With test scripts swift where the flow begins,
ARM64 hops and memory recast,
Build options bright—a testing blast!
Hopping through CI, our code runs fast! 🏃‍♂️

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the three main objectives: fixing build compatibility with latest llama.cpp, upgrading dependencies for security, and improving developer experience (DX) through test infrastructure and configuration changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/build_wasm.sh (1)

10-11: $GID may be unset on some systems.

On macOS and certain Linux distributions, the $GID environment variable is not set by default (unlike $UID). This could result in D_GID being empty, potentially causing issues in the Docker Compose configuration.

Suggested fix
 export D_UID=$UID
-export D_GID=$GID
+export D_GID=${GID:-$(id -g)}
🤖 Fix all issues with AI agents
In `@scripts/test_in_docker.sh`:
- Around line 3-4: Assign TEST_ARGS using "$*" instead of "$@" to preserve a
single concatenated string of all arguments, and set SCRIPT_DIR from the first
element of the BASH_SOURCE array by using ${BASH_SOURCE[0]}; ensure both
assignments are quoted to handle spaces (i.e., set TEST_ARGS to "$*" and
SCRIPT_DIR to "$(dirname -- "${BASH_SOURCE[0]}")" so argument boundaries and
BASH_SOURCE indexing are handled correctly).

In `@scripts/test_wasm.sh`:
- Around line 10-11: The script exports D_UID and D_GID using $UID and $GID but
$GID is not a standard shell variable and may be empty; change the D_GID export
to derive the current group ID reliably (e.g., export D_GID="$(id -g)" or
fallback to "$(getent passwd "$USER" | cut -d: -f4)" if needed) while keeping
the D_UID export as is (export D_UID="$UID" or use id -u for consistency), so
D_GID is always set before being used.
🧹 Nitpick comments (1)
scripts/test_wasm.sh (1)

7-8: Consider quoting the variable for robustness.

If the script path contains spaces, the cd command will fail.

Proposed fix
 CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
-cd $CURRENT_PATH
+cd "$CURRENT_PATH"
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8778d7b and 59c30f3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .gitattributes
  • .gitignore
  • CMakeLists.txt
  • cpp/wllama.cpp
  • package.json
  • scripts/build_wasm.sh
  • scripts/docker-compose.yml
  • scripts/test_in_docker.sh
  • scripts/test_wasm.sh
  • src/workers-code/.gitattributes
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-04-18T08:24:14.434Z
Learnt from: ngxson
Repo: ngxson/wllama PR: 0
File: :0-0
Timestamp: 2025-04-18T08:24:14.434Z
Learning: The file `generate_wasm_from_cdn.ts` in the wllama project is a generated script that gets stored on CDN, making it impossible to use `require('../package.json')` to dynamically access version information. This is why version references in this file need to be manually updated when the package version changes.

Applied to files:

  • scripts/test_wasm.sh
  • package.json
  • scripts/docker-compose.yml
  • scripts/build_wasm.sh
📚 Learning: 2025-12-29T03:44:02.649Z
Learnt from: reeselevine
Repo: ngxson/wllama PR: 198
File: src/workers-code/llama-cpp.js:269-279
Timestamp: 2025-12-29T03:44:02.649Z
Learning: In wllama's src/workers-code/llama-cpp.js, the isAsync parameter in callWrapper should only be true for functions included in JSPI_EXPORTS build configuration (wllama_start and wllama_action). Other functions like wllama_exit, wllama_debug, and wllama_malloc should use isAsync=false even though the callWrapper returns an async function, because they don't perform async operations at the C/WASM level.

Applied to files:

  • cpp/wllama.cpp
  • scripts/docker-compose.yml
🪛 Shellcheck (0.11.0)
scripts/test_in_docker.sh

[warning] 3-3: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

(SC2124)


[warning] 4-4: Expanding an array without an index only gives the first element.

(SC2128)

🔇 Additional comments (11)
.gitignore (1)

17-17: LGTM!

Appropriate addition to ignore Playwright-generated screenshot artifacts from the new test infrastructure.

src/workers-code/.gitattributes (1)

1-1: LGTM!

Marking generated.ts as linguist-generated is good practice to exclude it from language statistics and collapse diffs in PRs.

.gitattributes (1)

1-2: LGTM!

Marking the multi-thread and single-thread directories as linguist-generated improves the review experience by collapsing generated WASM build outputs in diffs.

cpp/wllama.cpp (1)

173-175: Good type correction for pointer arithmetic.

Using uintptr_t instead of unsigned int is the correct approach for storing pointer values from sbrk(0) and heap sizes. This ensures portability and avoids potential truncation issues on platforms with larger address spaces, aligning with the PR's build compatibility improvements.

scripts/build_wasm.sh (2)

3-3: Good DX improvements.

  • Enabling set -e ensures the script fails fast on errors.
  • ARM64 detection with platform and image tag adjustments is well-implemented.
  • The --abort-on-container-exit and --no-log-prefix flags improve build reliability and output readability.

Also applies to: 13-19


5-5: EMSDK Docker image version 4.0.23 is available on Docker Hub.

Both the standard tag (4.0.23) and ARM64 variant (4.0.23-arm64) are confirmed to exist on Docker Hub. No issues with the version bump.

CMakeLists.txt (1)

4-5: LGTM - Build configuration options are correctly declared.

The new cache options properly configure the llama.cpp build. One minor observation: the description for LLAMA_WASM_MEM64 says "disable MEMORY64" but it's actually a toggle (ON enables, OFF disables). Consider rewording to "enable MEMORY64 for wasm" for consistency with GGML_CPU_REPACK's phrasing.

package.json (1)

27-29: LGTM!

The new test script entries properly reference the shell scripts added in this PR, providing convenient npm commands for Docker-based and WASM testing workflows.

scripts/docker-compose.yml (3)

2-29: Security-sensitive container configuration for testing.

The wllama-test service uses highly permissive settings (privileged: true, network_mode: host, pid: host, ipc: host). While these may be necessary for Playwright's browser automation to work correctly, be aware this essentially removes container isolation.

Ensure this configuration is only used in trusted CI environments and never in production contexts.


30-77: LGTM - Well-structured WASM test service.

The llamacpp-wasm-tests service properly configures the WASM build environment with appropriate cmake flags and runs the ctest suite. The configuration aligns with the builder service pattern and correctly disables LLAMA_WASM_MEM64 as intended by this PR.


101-122: LGTM - Build configuration improvements.

The refactoring to use bash arrays for SHARED_EMCC_CFLAGS improves readability. The addition of -DEMSCRIPTEN_SYSTEM_PROCESSOR=wasm ensures correct build paths as mentioned in the PR objectives.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +3 to +4
export TEST_ARGS="$@"
SCRIPT_DIR=$(dirname -- "$BASH_SOURCE")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix shell variable handling issues.

Two shellcheck warnings apply here:

  1. Line 3: $@ is an array; assigning to a string with "$@" may not preserve argument boundaries correctly. Use "$*" if you want a single concatenated string.

  2. Line 4: $BASH_SOURCE is an array; use ${BASH_SOURCE[0]} to explicitly get the first element.

Proposed fix
-export TEST_ARGS="$@"
-SCRIPT_DIR=$(dirname -- "$BASH_SOURCE")
+export TEST_ARGS="$*"
+SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export TEST_ARGS="$@"
SCRIPT_DIR=$(dirname -- "$BASH_SOURCE")
export TEST_ARGS="$*"
SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}")
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 3-3: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

(SC2124)


[warning] 4-4: Expanding an array without an index only gives the first element.

(SC2128)

🤖 Prompt for AI Agents
In `@scripts/test_in_docker.sh` around lines 3 - 4, Assign TEST_ARGS using "$*"
instead of "$@" to preserve a single concatenated string of all arguments, and
set SCRIPT_DIR from the first element of the BASH_SOURCE array by using
${BASH_SOURCE[0]}; ensure both assignments are quoted to handle spaces (i.e.,
set TEST_ARGS to "$*" and SCRIPT_DIR to "$(dirname -- "${BASH_SOURCE[0]}")" so
argument boundaries and BASH_SOURCE indexing are handled correctly).

Comment on lines +10 to +11
export D_UID=$UID
export D_GID=$GID
Copy link

@coderabbitai coderabbitai bot Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

$GID is not a standard shell variable and may be unset.

Unlike $UID which is a Bash built-in, $GID is not guaranteed to exist. On many systems, this will result in D_GID being empty, potentially causing permission issues in the container.

Proposed fix
 export D_UID=$UID
-export D_GID=$GID
+export D_GID=$(id -g)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export D_UID=$UID
export D_GID=$GID
export D_UID=$UID
export D_GID=$(id -g)
🤖 Prompt for AI Agents
In `@scripts/test_wasm.sh` around lines 10 - 11, The script exports D_UID and
D_GID using $UID and $GID but $GID is not a standard shell variable and may be
empty; change the D_GID export to derive the current group ID reliably (e.g.,
export D_GID="$(id -g)" or fallback to "$(getent passwd "$USER" | cut -d: -f4)"
if needed) while keeping the D_UID export as is (export D_UID="$UID" or use id
-u for consistency), so D_GID is always set before being used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, indeed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aviallon, thank you for confirming! Let me know if you need any assistance with the fix. 🐰

┏━━━━━━━━━━━━━━━┓
┃ (\_/) ✓ ┃
┃ (•‿•) ┃
┃ />📝 ┃
┗━━━━━━━━━━━━━━━┛

@ngxson
Copy link
Owner

ngxson commented Jan 16, 2026

Nice, thanks! I'll try to merge this after #201 to avoid any potential conflicts

@actuallymentor
Copy link

Hey @aviallon! I landed here because I was trying to find out if wllama has the memory64 browser spec implemented. Do I understand correctly that in this PR you've disabled those build flags because the library doesn't support it yet?

@ngxson I see no references to memory64 in this repo, is it on your roadmap? It bumps the max memory available from 4 GiB to 16 GiB (at a performance penalty) which would allow for a crazy jump in model sizes that could run in browsers.

Thanks for you work both! If I can support in the implementation hit me up.

@aviallon
Copy link
Author

Hey @aviallon! I landed here because I was trying to find out if wllama has the memory64 browser spec implemented. Do I understand correctly that in this PR you've disabled those build flags because the library doesn't support it yet?

@ngxson I see no references to memory64 in this repo, is it on your roadmap? It bumps the max memory available from 4 GiB to 16 GiB (at a performance penalty) which would allow for a crazy jump in model sizes that could run in browsers.

Thanks for you work both! If I can support in the implementation hit me up.

Yes, I disabled memory64 because it caused immediate runtime issues, and I was not competent enough to fix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants