Skip to content

fix(cli): locate runtime include dir on npm install (#134)#145

Merged
thiagoralves merged 1 commit into
developmentfrom
fix/134-runtime-include-path
Jun 1, 2026
Merged

fix(cli): locate runtime include dir on npm install (#134)#145
thiagoralves merged 1 commit into
developmentfrom
fix/134-runtime-include-path

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

Summary

Fixes #134 — on a global/npm install, --build and --test aborted with Could not locate runtime include directory, forcing users to pass --cxx-flags "-I<pkg>/src/runtime/include" by hand. The headers are shipped; the locator just missed them by one directory level.

Root cause

The package ships the runtime at <pkg>/src/runtime/include (the files entry "src/runtime/"), but the CLI runs from <pkg>/dist/node. findRuntimeIncludeDir only tried:

<dir>/runtime/include            // dist/node/runtime/include   — absent
<dir>/../src/runtime/include     // dist/src/runtime/include     — absent (off by one)

Reaching the shipped headers needs two levels up: ../../src/runtime/include<pkg>/src/runtime/include. Auto-discovery only worked when run from the project root (where the cwd-relative candidate happens to hit) — never the case on a global install, where cwd is the user's project. The libs locator just below already does the right thing with ../../libs.

Fix

Add the two-level package-relative candidate to both the import.meta (ESM — npm install) and __dirname (CJS bundle / pkg binary) blocks. From dist/node it resolves to <pkg>/src/runtime/include; from the src/node dev layout it resolves to the same src/runtime/include, so one candidate covers both.

Verification

  • Reproduced: findRuntimeIncludeDir('') from a foreign cwd returned null before the fix.
  • After: it resolves to the shipped src/runtime/include, and strucpp p.st -o p.cpp --build run from /tmp compiles and produces a working binary end-to-end.
  • Strengthened the previously-lenient build-utils test (it mocked cwd to /tmp but only asserted "doesn't throw") into a real CLI: --build/--test cannot auto-locate runtime include dir on npm install (off-by-one path) #134 regression that requires the package-relative lookup to resolve src/runtime/include, plus a -I cxx-flags fallback case.
  • Full suite green (1999 passed), typecheck + format clean.

🤖 Generated with Claude Code

`--build`/`--test` aborted with "Could not locate runtime include
directory" on a global/npm install, even though the headers ship in the
package. The package places the runtime at <pkg>/src/runtime/include but
the CLI runs from <pkg>/dist/node, so reaching it needs two levels up
(../../src/runtime/include). findRuntimeIncludeDir only climbed one
(../src/runtime/include → <pkg>/dist/src, absent), so auto-discovery
landed one directory short. It only worked when run from the project
root, where the cwd-relative candidate happened to hit — which is never
the case on a global install (cwd is the user's project).

Add the two-level package-relative candidate to both the import.meta and
__dirname blocks, mirroring the libs locator just below (which already
uses ../../libs). Verified end-to-end: `--build` from a foreign cwd now
locates the headers and produces a working binary.

Strengthen the previously-lenient build-utils test (it mocked cwd to
/tmp but only asserted "doesn't throw") into a real #134 regression that
requires the package-relative lookup to resolve src/runtime/include, plus
a -I cxx-flags fallback case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thiagoralves thiagoralves merged commit 0a727a2 into development Jun 1, 2026
@thiagoralves thiagoralves deleted the fix/134-runtime-include-path branch June 1, 2026 12:35
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.

CLI: --build/--test cannot auto-locate runtime include dir on npm install (off-by-one path)

1 participant