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

Aperta Adatta ai principianti
#32,905 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, wasm
Ambito
compilers

Direzione di ricerca

L'inclusione viene emessa in vlib/v/gen/c/cleanc.v vicino alla guardia #if !defined(__sun) attorno a sys/ptrace.h. Riproduci con v -cc emcc -os wasm32_emscripten su un programma che importa math, poi verifica se il C generato include ancora quell'header. È completato quando la build compila e la guardia di Emscripten è coperta da un controllo, mentre il problema dell'output .wasm (#32903) viene tracciato separatamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
V
Stelle
38.1k
Fork
2.3k
Merge medio
22h 8m
PR unite (30g)
636

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vlang/v

Tutte le issue di vlang/v

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.