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

オープン 初心者向け
#32,905 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, wasm
領域
compilers

調査の方向性

インクルードは vlib/v/gen/c/cleanc.v で、sys/ptrace.h を囲む #if !defined(__sun) ガードの近くで出力されます。math をインポートするプログラムに対して v -cc emcc -os wasm32_emscripten で再現し、生成された 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分
マージ済み PR(30日)
636

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vlang/v のほかの issue

vlang/v の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。