cgen: `#include <sys/ptrace.h>` is emitted for wasm32_emscripten, so emcc builds that import math/os fail
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
该 include 在 vlib/v/gen/c/cleanc.v 中、sys/ptrace.h 外围的 #if !defined(__sun) 保护附近生成。使用 v -cc emcc -os wasm32_emscripten 在导入 math 的程序上复现,然后检查生成的 C 代码是否仍然包含该头文件。当该构建能够编译,且 Emscripten 保护由检查覆盖时即完成,而 .wasm 输出问题 (#32903) 单独跟踪。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- V
- 星标
- 38.1k
- 派生
- 2.3k
- 平均合并
- 22 小时 8 分钟
- 30 天内合并 PR
- 636
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vlang/v 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
time: Duration.debug prints only a minus sign at min_i64可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
datatypes: RingBuffer retains references to popped elements可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
Deltakit/deltakit-compile#27 ·
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
new issue
难度 2/5 1-3 小时 新手友好度 62/100
llvm/llvm-project#245835 ·
维护者通常 1 天内回复
-
enhancement needs triage
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
triton-lang/triton#12945 ·
维护者通常 1 天内回复