Skip to content

Commit

Permalink
Try to get stdlib to not depend on coqc using (env (binaries))
Browse files Browse the repository at this point in the history
Doesn't work properly.

NB: if there's a coqc in PATH it appears to work, but if there's not
it will say
~~~
Couldn't find Coq standard library, and theory is not using (stdlib no)
~~~
  • Loading branch information
SkySkimmer committed Dec 11, 2024
1 parent 69da2d8 commit a3a342e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stdlib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; NB rocq dep will declare the dependency on the worker
(env
(_
(binaries
(tools/rocqc.exe as coqc)
(tools/rocqdep.exe as coqdep))))
22 changes: 22 additions & 0 deletions stdlib/tools/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(library
(name rocq_info)
(modules rocq_info))

(executable
(name rocqc)
(modules rocqc)
(libraries rocq_info unix))

(executable
(name rocqdep)
(modules rocqdep)
(libraries rocq_info unix))

(executable
(name mkinfo)
(modules mkinfo))

(rule
(targets rocq_info.ml)
(deps %{bin:rocq})
(action (with-stdout-to %{targets} (run ./mkinfo.exe %{deps}))))
4 changes: 4 additions & 0 deletions stdlib/tools/mkinfo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let () =
let hash = Digest.file Sys.argv.(1) in
Printf.printf "let path = %S\n" Sys.argv.(1);
Printf.printf "let hash = %S\n%!" (Digest.to_hex hash)
2 changes: 2 additions & 0 deletions stdlib/tools/rocq_info.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val path : string
val hash : string
27 changes: 27 additions & 0 deletions stdlib/tools/rocqc.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let () =
match Sys.argv.(1) with
| exception Invalid_argument _ -> ()
| "-debug-shim" ->
Printf.eprintf "expected rocq hash = %s\n%!" Rocq_info.hash
| _ -> ()

let exec_or_create_process prog argv =
if Sys.os_type <> "Win32" then
Unix.execv prog argv
else
let pid = Unix.create_process prog argv Unix.stdin Unix.stdout Unix.stderr in
if pid = 0 then begin
Printf.eprintf "coqc shim: create_process failed\n%!";
exit 127
end;
let _, status = Unix.waitpid [] pid in
match status with
| WEXITED n | WSIGNALED n -> exit n
| WSTOPPED _ ->
(* is there anything sensible to do with WSTOPPED? can it even happen on windows? *)
assert false

let () =
exec_or_create_process Rocq_info.path
(Array.append [|Rocq_info.path;"compile"|]
(Array.sub Sys.argv 1 (Array.length Sys.argv - 1)))
27 changes: 27 additions & 0 deletions stdlib/tools/rocqdep.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let () =
match Sys.argv.(1) with
| exception Invalid_argument _ -> ()
| "-debug-shim" ->
Printf.eprintf "expected rocq hash = %s\n%!" Rocq_info.hash
| _ -> ()

let exec_or_create_process prog argv =
if Sys.os_type <> "Win32" then
Unix.execv prog argv
else
let pid = Unix.create_process prog argv Unix.stdin Unix.stdout Unix.stderr in
if pid = 0 then begin
Printf.eprintf "coqc shim: create_process failed\n%!";
exit 127
end;
let _, status = Unix.waitpid [] pid in
match status with
| WEXITED n | WSIGNALED n -> exit n
| WSTOPPED _ ->
(* is there anything sensible to do with WSTOPPED? can it even happen on windows? *)
assert false

let () =
exec_or_create_process Rocq_info.path
(Array.append [|Rocq_info.path;"dep"|]
(Array.sub Sys.argv 1 (Array.length Sys.argv - 1)))

0 comments on commit a3a342e

Please sign in to comment.