Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocamlfind doesn't work for wasicaml #67

Open
gerdstolpmann opened this issue Sep 1, 2023 · 0 comments
Open

ocamlfind doesn't work for wasicaml #67

gerdstolpmann opened this issue Sep 1, 2023 · 0 comments

Comments

@gerdstolpmann
Copy link
Contributor

gerdstolpmann commented Sep 1, 2023

three problems:

  1. wasicaml has a bug and cannot run executables by non-absolute path (-> solve there, fix: find commands in PATH when the commands were built with wasicaml remixlabs/wasicaml#58)
/Users/gerd/biz/figly/protoquery/wasicaml/bin/ocamlfind ocamlmklib
ocamlfind: Package `threads' not found

This is due to a bug in findlib: frontend.ml, line 923, change this to:

  let type_of_threads =
    try package_property [] "threads" "type_of_threads"
    with No_such_package _ -> "ignore"
  1. wasicaml doesn't support Unix.spawn, but you can use Sys.command. Alternate run_command implementation:
let run_command ?filter verbose cmd args =
  let printable_cmd =
    cmd ^ " " ^ String.concat " " (List.map escape_if_needed args) in
  ( match verbose with
      | Normal ->
          ()
      | Verbose ->
          print_endline ("+ " ^ printable_cmd);
          if filter <> None then
            print_string
              ("  (output of this command is filtered by ocamlfind)\n")
      | Only_show ->
          print_endline printable_cmd
  );
  flush stdout;

  if verbose <> Only_show then (
    let temp_file_opt =
      match filter with
        | None -> None
        | Some _ ->
            Some(Filename.temp_file "ocamlfind" ".out") in
    let cmd1 =
      match temp_file_opt with
        | None -> cmd
        | Some f -> cmd ^ " > " ^ Filename.quote f in
    let code =
      Sys.command cmd1 in
    if code <> 0 then (
      if verbose = Verbose then
        print_string (cmd ^ " returned with exit code " ^ string_of_int code ^ "\n");
      exit code
    );

    ( match filter, temp_file_opt with
        | Some filter_fun, Some temp_file ->
            let ch = open_in temp_file in
            ( try
                while true do
                  let line = input_line ch in
                  match filter_fun line with
                      None -> ()       (* Suppress line *)
                    | Some line' -> print_endline line'
                done;
                assert false
              with
                  End_of_file ->
                  close_in ch;
                  flush stdout
            )
        | _ -> ()
    )
  )
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant