cgen: `#include <sys/ptrace.h>` is emitted for wasm32_emscripten, so emcc builds that import math/os fail
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The include is emitted in vlib/v/gen/c/cleanc.v near the #if !defined(__sun) guard around sys/ptrace.h. Reproduce with v -cc emcc -os wasm32_emscripten on a program that imports math, then check whether the generated C still includes that header. Done when that build compiles and the Emscripten guard is covered by a check, while the wasm .wasm output issue (#32903) is tracked separately.
Written by the indexing model from the issue text.
Description
Describe the bug
Generated C always contains #include <sys/ptrace.h> on non-Windows targets except Solaris. Emscripten's sysroot has no sys/ptrace.h, so any -os wasm32_emscripten build that pulls in this preamble fails. Importing math or os is enough.
Reproduction Steps
a.v:
import math
fn main() {
println(int(math.sqrt(16.0)))
}
v -cc emcc -os wasm32_emscripten -o a.js a.v
Expected Behavior
The program compiles with emcc.
Current Behavior
src.c:1384:10: fatal error: 'sys/ptrace.h' file not found
1384 | #include <sys/ptrace.h>
1 error generated.
emcc: error: '.../clang -target wasm32-unknown-emscripten ...' failed (returned 1)
The same error appears with import os. A plain println('hi') program compiles because it does not get this include.
Possible Solution
vlib/v/gen/c/cleanc.v (around line 21272):
- g.writeln('#if !defined(__sun)')
+ g.writeln('#if !defined(__sun) && !defined(__EMSCRIPTEN__)')
g.writeln('#include <sys/ptrace.h>')
I tested this one-line change locally. It also needs the -sSINGLE_FILE=1 workaround for the missing .wasm output (#32903). With both, a 10k-agent float/array benchmark built with -cc emcc -prod -os wasm32_emscripten ran correctly in Node, with the same checksum as the native build.
V version
V 0.5.2 f16ac7a (master, 2026-11-25)
Environment details
- macOS 27.0 (26A428), arm64 (Apple M1 Max)
- Apple clang 21.0.0
- emcc 6.0.5 (Homebrew)
- Node.js 22.22.0
- Dominant language
- V
- Stars
- 38.1k
- Forks
- 2.3k
- Avg merge
- 22h 8m
- Merged PRs (30d)
- 636
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vlang/v
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
time: Duration.debug prints only a minus sign at min_i64Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
datatypes: RingBuffer retains references to popped elementsPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Deltakit/deltakit-compile#27 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
new issue
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
llvm/llvm-project#245835 ·
Maintainers usually reply within 1 day
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
triton-lang/triton#12945 ·
Maintainers usually reply within 1 day