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

Can't install on OS X with latest release #22

Closed
yminsky opened this issue Dec 6, 2017 · 15 comments
Closed

Can't install on OS X with latest release #22

yminsky opened this issue Dec 6, 2017 · 15 comments

Comments

@yminsky
Copy link

yminsky commented Dec 6, 2017

It's not obvious to me what the issue is here, but here's the error I get from opam. Does that mean that it can't find the C compiler? I'm a little confused.

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫
[ERROR] The compilation of re2 failed at "jbuilder build -p re2 -j 6".

#=== ERROR while installing re2.v0.9.1 ========================================#
# opam-version 1.2.2
# os           darwin
# command      jbuilder build -p re2 -j 6
# path         /Users/yminsky/.opam/4.06.0/build/re2.v0.9.1
# compiler     4.06.0
# exit-code    1
# env-file     /Users/yminsky/.opam/4.06.0/build/re2.v0.9.1/re2-88727-1872ec.env
# stdout-file  /Users/yminsky/.opam/4.06.0/build/re2.v0.9.1/re2-88727-1872ec.out
# stderr-file  /Users/yminsky/.opam/4.06.0/build/re2.v0.9.1/re2-88727-1872ec.err
### stderr ###
# Error: Program cc -O2 -pipe not found in PATH (context: default)
@xclerc
Copy link
Contributor

xclerc commented Dec 6, 2017

(For the record, I am not able to reproduce the problem on an old 10.11.x macOS.)

@Chris00
Copy link

Chris00 commented Dec 6, 2017

It look like it is trying to find the program cc -O2 -pipe — which of course fails. The full log would be useful to pinpoint the action that is being executed. PR ocaml/dune#336 may help to solve that. (Discussion with @rgrinberg)

@yminsky
Copy link
Author

yminsky commented Dec 6, 2017

@xclerc I'm running on a fully up-to-date mac, FWIW.

@rgrinberg, should I just wait for that feature to land, and then try again?

@Chris00
Copy link

Chris00 commented Dec 6, 2017

re2 may need to be adapted. Running in verbose mode and uploading the log here would help.

@xclerc
Copy link
Contributor

xclerc commented Dec 6, 2017

(Another data point: unable to reproduce on a 10.13.x macOS, with the latest Xcode 9.{0,2}.x)

@xclerc
Copy link
Contributor

xclerc commented Dec 7, 2017

@Chris00 while your explanation is more than plausible, when grepping the
latest jbuilder master, it seems that the only calls that could produce the message
are in bootstrap.ml and are related to ocamlc/ocamllex/ocamldep. (But I am
quite possibly not using the correct jbuilder version.)

@Chris00
Copy link

Chris00 commented Dec 7, 2017

@xclerc I agree — quickly looking at the sources of jbuilder, this seems to be the only place. However, bootstrap.ml is only used when compiling jbuilder itself, it should not play any role when compiling other libraries.

@xclerc
Copy link
Contributor

xclerc commented Dec 7, 2017

Indeed, and it just adds to my confusion...

@yminsky
Copy link
Author

yminsky commented Dec 8, 2017

Urk. Infuriating. I did an opam update, and now the problem is gone. So I don't know what happened, but I might as well close this one.

@yminsky yminsky closed this as completed Dec 8, 2017
@dcastrop
Copy link

I have the exact same issue on a fully up-to-date mac, when calling opam install re2.v0.9.1. Opam update did not solve the problem for me, so I had to switch to the ocaml version 4.05.0. I briefly tried to understand what was going on with 4.06.0, and it seems like an issue in jbuilder, but I didn't get too far. I write below a few comments, in case somebody wants to take a further look (question: is this really an issue in the jbuilder repo, or is this me misunderstanding something?).


  • The result of ocamlc -config with OCaml 4.05.0 contains no c_compiler field. However, using 4.06.0, it contains c_compiler: cc -O2 -pipe.

  • In the code of jbuilder:

    • Function Context.create returns a context with c_compiler set to one of the following: a) the value of that field of the output of ocamlc -config, if it exists; b) the first word of the field "bytecomp_c_compiler" (i.e. the substring until the first space), otherwise.
    • Function Gen_rules.gen calls SC.resolve_program on ctx.c_compiler. Function resolve_program treats its input as a path to a binary, and if it is not found, this results on a Run (Error e, _) action. For 4.06.0, the input to resolve_program is cc -O2 -pipe, which obviously fails (as @Chris00 said).
    • Compiling jbuilder with the patch below seems to fix the issue (at least for me), but I doubt it is the correct way (e.g. it ignores the flags in -O2 -pipe).
diff --git a/src/context.ml b/src/context.ml
index bc0383f..6cbf3a8 100644
--- a/src/context.ml
+++ b/src/context.ml
@@ -287,25 +287,26 @@ let create ~(kind : Kind.t) ~path ~base_env ~env_extra ~name ~merlin ~use_findli
     else
       env,env_extra
   in
+  let split_prog s =
+    let len = String.length s in
+    let rec loop i =
+      if i = len then
+        (s, "")
+      else
+        match s.[i] with
+        | ' ' | '\t' ->
+          (String.sub s ~pos:0 ~len:i,
+           String.sub s ~pos:i ~len:(len - i))
+        | _ -> loop (i + 1)
+    in
+    loop 0
+  in
   let c_compiler, ocamlc_cflags, ocamlopt_cflags =
     match get_opt "c_compiler" with
     | Some c_compiler -> (* >= 4.06 *)
+      let c_compiler, _ = split_prog c_compiler in
       (c_compiler, get "ocamlc_cflags", get "ocamlopt_cflags")
     | None ->
-      let split_prog s =
-        let len = String.length s in
-        let rec loop i =
-          if i = len then
-            (s, "")
-          else
-            match s.[i] with
-            | ' ' | '\t' ->
-              (String.sub s ~pos:0 ~len:i,
-               String.sub s ~pos:i ~len:(len - i))
-            | _ -> loop (i + 1)
-        in
-        loop 0
-      in
       let c_compiler, ocamlc_cflags = split_prog (get "bytecomp_c_compiler") in
       let _, ocamlopt_cflags = split_prog (get "native_c_compiler") in
       (c_compiler, ocamlc_cflags, ocamlopt_cflags)

@yminsky
Copy link
Author

yminsky commented Jan 5, 2018

This has reemerged for me now that I'm trying out 4.06 again. Rudi asked me for more debugging information, so here it is:

incr_dom $ ocamlc -config | grep ‘compiler:’
c_compiler: cc -O2 -pipe
bytecomp_c_compiler: cc -O2 -pipe -O2 -fno-strict-aliasing -fwrapv  -D_FILE_OFFSET_BITS=64 -D_REENTRANT
native_c_compiler: cc -O2 -pipe -O2 -fno-strict-aliasing -fwrapv -D_FILE_OFFSET_BITS=64 -D_REENTRANT

Given that this is apparently a jbuilder issue, I'll mint one, pointing to this issue.

@yminsky
Copy link
Author

yminsky commented Jan 5, 2018

See: ocaml/dune#392

@smolkaj
Copy link

smolkaj commented Jan 12, 2018

Same problem, also MacOS. Builds with OCaml 4.05, fails to build with OCaml 4.06.

@rgrinberg
Copy link

should be fixed in jbuilder#master.

@smolkaj
Copy link

smolkaj commented Jan 12, 2018

Yes, indeed. Thanks.

@hhugo hhugo closed this as completed Jan 23, 2018
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

7 participants