1616import sys
1717import subprocess
1818import shutil
19+ import platform
1920from pathlib import Path
2021
22+ # Automatically detect WASM environment and skip all C compilation
23+ IS_WASM = sys .platform in ('emscripten' , 'wasm32' )
24+ if IS_WASM :
25+ os .environ ['OMNIPKG_SKIP_C_EXT' ] = '1'
26+
2127SKIP_C_EXTENSIONS = os .environ .get ('OMNIPKG_SKIP_C_EXT' , '0' ) == '1'
2228
2329# ── Dispatcher binary install (shared by both install and develop commands) ──
@@ -43,21 +49,22 @@ def _install_dispatcher_binary(install_dir=None):
4349 install_dir = Path (sys .executable ).parent # $VENV/bin
4450
4551 binary_out = Path (install_dir ) / "_omnipkg_dispatch_bin"
46-
47- # 1. FIX: Create the wheel's scripts directory so GCC doesn't crash
4852 binary_out .parent .mkdir (parents = True , exist_ok = True )
4953
54+ cmd = ["gcc" , "-O2" ]
55+ if sys .platform == "darwin" :
56+ archflags = os .environ .get ("ARCHFLAGS" , "" )
57+ if archflags :
58+ cmd .extend (archflags .split ())
59+ elif platform .machine () == "arm64" :
60+ cmd .extend (["-arch" , "x86_64" , "-arch" , "arm64" ])
61+ cmd .extend (["-o" , str (binary_out ), str (c_source )])
62+
5063 try :
51- result = subprocess .run (
52- ["gcc" , "-O2" , "-o" , str (binary_out ), str (c_source )],
53- capture_output = True , text = True
54- )
64+ result = subprocess .run (cmd , capture_output = True , text = True )
5565 if result .returncode != 0 :
5666 print (f" [dispatcher] Compilation failed, using Python dispatcher:" )
57- subprocess .run (["gcc" , "-v" , "-O2" , "-o" , str (binary_out ), str (c_source )],
58- capture_output = False ,
59- text = True
60- )
67+ subprocess .run (cmd + ["-v" ], capture_output = False , text = True )
6168 return
6269
6370 import time
0 commit comments