Skip to content

Commit 7661321

Browse files
committed
Fixes handling C compilation errors
1 parent c8b377e commit 7661321

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- By default do not log from tests.
1818
- `debug_log_from_routines` should only happen when `log_level > 1`.
1919
- Bugs in `Multicore_backend`: `await` was not checking queue emptiness, `worker`'s `Condition.broadcast` was non-atomically guarded (doesn't need to be), possible deadloop due to the lockfree queue -- now replaced with `saturn_lockfree`.
20+
- Reduced busy-waiting inside `c_compile_and_load`, propagating compilation errors now instead of infinite loop on error.
2021

2122
## [0.4.0] -- 2024-09-04
2223

arrayjit/lib/cc_backend.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,17 @@ let c_compile_and_load ~f_name =
108108
Printf.sprintf "%s %s -O%d -o %s --shared >> %s 2>&1" (compiler_command ()) f_name
109109
(optimization_level ()) libname log_fname
110110
in
111-
let _rc = Stdlib.Sys.command cmdline in
112-
(* FIXME: don't busy wait *)
113-
(* FIXME: detect and propagate compile errors, log compile warnings *)
114-
while not @@ (Stdlib.Sys.file_exists libname && Stdlib.Sys.file_exists log_fname) do
115-
()
111+
let rc = Stdlib.Sys.command cmdline in
112+
while rc = 0 && (not @@ (Stdlib.Sys.file_exists libname && Stdlib.Sys.file_exists log_fname)) do
113+
Unix.sleepf 0.001
116114
done;
115+
(if rc <> 0 then
116+
let errors =
117+
"Cc_backend.c_compile_and_load: compilation failed with errors:\n"
118+
^ Stdio.In_channel.read_all log_fname
119+
in
120+
Stdio.prerr_endline errors;
121+
invalid_arg errors);
117122
(* Note: RTLD_DEEPBIND not available on MacOS. *)
118123
let result = { lib = Dl.dlopen ~filename:libname ~flags:[ RTLD_NOW ]; libname } in
119124
Stdlib.Gc.finalise (fun lib -> Dl.dlclose ~handle:lib.lib) result;

0 commit comments

Comments
 (0)