mirage / ocaml-github

GitHub APIv3 OCaml bindings
ISC License
100 stars 61 forks source link

Build on error on Mac M1 with OCaml 5.0 #269

Closed jserot closed 1 year ago

jserot commented 1 year ago
$ opam install github-unix.4.4.1
The following actions will be performed:
  ∗ install github-unix 4.4.1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
⬇ retrieved github-unix.4.4.1  (cached)
[ERROR] The compilation of github-unix.4.4.1 failed at "dune build -p github-unix -j 4 @install".

#=== ERROR while compiling github-unix.4.4.1 ==================================#
# context     2.1.4 | macos/x86_64 | ocaml-base-compiler.5.0.0 | https://opam.ocaml.org/#8c1bb918
# path        ~/.opam/5.0.0/.opam-switch/build/github-unix.4.4.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p github-unix -j 4 @install
# exit-code   1
# env-file    ~/.opam/log/github-unix-66297-f2e52b.env
# output-file ~/.opam/log/github-unix-66297-f2e52b.out
### output ###
# Undefined symbols for architecture x86_64:
# [...]
#       _client_verify_callback in libssl_stubs.a(ssl_stubs.o)
#       _ocaml_ssl_get_issuer in libssl_stubs.a(ssl_stubs.o)
#   "_X509_get_subject_name", referenced from:
#       _client_verify_callback in libssl_stubs.a(ssl_stubs.o)
#       _ocaml_ssl_get_subject in libssl_stubs.a(ssl_stubs.o)
#   "_X509_verify_cert_error_string", referenced from:
#       _ocaml_ssl_get_verify_error_string in libssl_stubs.a(ssl_stubs.o)
# ld: symbol(s) not found for architecture x86_64
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
# File "caml_startup", line 1:
# Error: Error during linking (exit code 1)

Mac OS 12.6 OCaml 5.0 Opam 2.1.4

I had a similar error when trying to build cohttp-lwt-unix.5.0.0 but solved it by installing cohttp-lwt-unix.6.0.0alpha0 instead.

I'm puzzled by the reference to x86_64 arch name.

tmcgilchrist commented 1 year ago

Is it possible the OCaml toolchain is compiled for x86 and using Rosetta? Both of these messages suggest something unusual is going on ld: symbol(s) not found for architecture x86_64 and 2.1.4 | macos/x86_64 | ocaml-base-compiler.5.0.0

I don't have an M1 machine available but we do macOS M1 builds as part of CI -> https://ci.ocamllabs.io/github/mirage/ocaml-github/commit/91edfae6f63d9990e030013b0397012b8cbc6843/variant/macos-homebrew-5.0.0_arm64_opam-2.1

jserot commented 1 year ago

Right guess, thanks ;):

file `which ocamlc`
/Users/.../opam/5.0.0/bin/ocamlc: Mach-O 64-bit executable x86_64

I remember having installed the OpenSSL system package using arch arm64 brew install. This could explain the problem.

Seems i have two solutions:

tmcgilchrist commented 1 year ago

The OCaml toolchain on M1(ARM64) macOS is very usable. I would recommend that option over using Rosetta emulation.

jserot commented 1 year ago

Ok, thanks ! Btw, do you know if its possible to have both versions of the toolchain (ARM64 and x86_64) in distinct opam switches ?

jserot commented 1 year ago

https://discuss.ocaml.org/t/switching-between-arm64-and-x86-64-architectures-for-opam-on-mac-m1/11750