Run emcc compile with verbose output to capture clang command. Runs emcc normally but with EMCC_VERBOSE=1 and EM_FORCE_RESPONSE_FILES=0 so the full clang subprocess command is printed to stderr. We parse it and save a template for future fast compiles via _fast_compile(). Returns t
(
emcc_args: list[str],
wrapper_path: Path,
object_path: Path,
build_dir: Path,
)
| 1067 | |
| 1068 | |
| 1069 | def _intercept_emcc_compile( |
| 1070 | emcc_args: list[str], |
| 1071 | wrapper_path: Path, |
| 1072 | object_path: Path, |
| 1073 | build_dir: Path, |
| 1074 | ) -> int: |
| 1075 | """Run emcc compile with verbose output to capture clang command. |
| 1076 | |
| 1077 | Runs emcc normally but with EMCC_VERBOSE=1 and EM_FORCE_RESPONSE_FILES=0 |
| 1078 | so the full clang subprocess command is printed to stderr. We parse it |
| 1079 | and save a template for future fast compiles via _fast_compile(). |
| 1080 | |
| 1081 | Returns the emcc exit code. |
| 1082 | """ |
| 1083 | from ci.wasm_tools import get_emcc |
| 1084 | |
| 1085 | emcc = get_emcc() |
| 1086 | |
| 1087 | env = os.environ.copy() |
| 1088 | env["EMCC_VERBOSE"] = "1" |
| 1089 | env["EM_FORCE_RESPONSE_FILES"] = "0" |
| 1090 | |
| 1091 | result = subprocess.run( |
| 1092 | [emcc] + emcc_args, |
| 1093 | cwd=str(PROJECT_ROOT), |
| 1094 | stderr=subprocess.PIPE, |
| 1095 | text=True, |
| 1096 | env=env, |
| 1097 | ) |
| 1098 | |
| 1099 | if result.returncode != 0: |
| 1100 | if result.stderr: |
| 1101 | print(result.stderr, file=sys.stderr, end="") |
| 1102 | return result.returncode |
| 1103 | |
| 1104 | # Parse and cache the clang command for future fast compiles |
| 1105 | clang_cmd = _parse_clang_from_verbose(result.stderr) |
| 1106 | if clang_cmd is None: |
| 1107 | return 0 # compile succeeded, just can't cache |
| 1108 | |
| 1109 | wrapper_str = str(wrapper_path) |
| 1110 | object_str = str(object_path) |
| 1111 | template: list[str] = [] |
| 1112 | for arg in clang_cmd: |
| 1113 | arg = arg.replace(wrapper_str, "{input_cpp}") |
| 1114 | arg = arg.replace(object_str, "{output_o}") |
| 1115 | template.append(arg) |
| 1116 | |
| 1117 | cache_file = build_dir / "clang_compile_args.json" |
| 1118 | cache_file.write_text(json.dumps(template), encoding="utf-8") |
| 1119 | |
| 1120 | # Save the key so _fast_compile can detect flag changes |
| 1121 | cache_key_file = build_dir / "clang_compile_args.key" |
| 1122 | cache_key_file.write_text(_compile_cache_key(emcc_args), encoding="utf-8") |
| 1123 | |
| 1124 | return 0 |
| 1125 | |
| 1126 |
no test coverage detected