cgen: `#include <sys/ptrace.h>` is emitted for wasm32_emscripten, so emcc builds that import math/os fail

未关闭 适合新手
#32,905 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, wasm
领域
compilers

调研方向

该 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

vlang/v 的其他 Issue

查看 vlang/v 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。