kandu / ocaml-fswatch

4 stars 3 forks source link

cannot install on the macos with homebrew installed fswatch #3

Closed dannypsnl closed 11 months ago

dannypsnl commented 11 months ago

Homebrew installed fswatch located at /opt/homebrew/Cellar/fswatch/1.17.1/include/libfswatch/c

$ opam install fswatch
The following actions will be performed:
  ∗ install conf-fswatch 11-0.1.0 [required by fswatch]
  ∗ install fswatch      11-0.1.1
===== ∗ 2 =====
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
⬇ retrieved fswatch.11-0.1.1  (cached)
[ERROR] The compilation of conf-fswatch.11-0.1.0 failed at "sh -exec cc -I/usr/local/include/libfswatch/c -I/usr/include/libfswatch/c $CFLAGS test.c -lfswatch".

#=== ERROR while compiling conf-fswatch.11-0.1.0 ==============================#
# context     2.1.5 | macos/arm64 | ocaml-base-compiler.5.0.0 | https://opam.ocaml.org#1451371a
# path        ~/.opam/5.0.0/.opam-switch/build/conf-fswatch.11-0.1.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exec cc -I/usr/local/include/libfswatch/c -I/usr/include/libfswatch/c $CFLAGS test.c -lfswatch
# exit-code   1
# env-file    ~/.opam/log/conf-fswatch-30090-5a7b88.env
# output-file ~/.opam/log/conf-fswatch-30090-5a7b88.out
### output ###
# + cc -I/usr/local/include/libfswatch/c -I/usr/include/libfswatch/c test.c -lfswatch
# test.c:1:10: fatal error: 'libfswatch.h' file not found
# #include <libfswatch.h>
#          ^~~~~~~~~~~~~~
# 1 error generated.

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
┌─ The following actions failed
│ λ build conf-fswatch 11-0.1.0
└─ 
╶─ No changes have been performed
kandu commented 11 months ago

Thanks for reporting this issue.

I guess this is a silicon Mac. I don't have a silicon Mac, so please do me a favor.

Are there two directories named include and lib under the /opt/homebrew directory? And in these two directories, are there symbolic links linking to the cellared library bundle which is under the /opt/homebrew/Cellar directory?

If that's the case, we can write a conditional clause in the opam file to fix this issue.

(if you can list the contents of include and library directories of fswatch under the /opt/homebrew/include/ and /opt/homebrew/lib directories in a tree-like format, that will be really helpful. brew install tree this tool will do the job)

dannypsnl commented 11 months ago

Yes, there has /opt/homebrew/include/libfswatch/ and /opt/homebrew/lib/libfswatch.dylib.

The two directories you want to too huge to print out, I think the fact that there has soft links is enough than.

kandu commented 11 months ago

Then this is the silicon branch which adds silicon homebrew support. But it is NOT a proven version, so it will on its own branch for a while. You may check it out and use opam pin to manually install and test it.

dannypsnl commented 11 months ago

I guess you didn't push your code, the HEAD of silicon still master's HEAD.

kandu commented 11 months ago

Ah, silly me.

dannypsnl commented 11 months ago

Your patch can work with LIBRARY_PATH=/opt/homebrew/lib opam pin add ., do you know any way to setup library? Users still need to configure some to install it.

kandu commented 11 months ago

You mean, homebrew hasn't setup environment for opam even if you install opam with brew install opam?

dannypsnl commented 11 months ago

No, it won't.

kandu commented 11 months ago

Well, there are three options

  1. Report an issue to homebrew team. They've already published a script called shellenv.sh to setup basic environment variable for shells. They may add an additional script, called shellenv_dev.sh to setup development environment. This script is not globally or permanently pre-loaded so it won't conflict with system libraries.
  2. Add these environment variables to the config file of the currently using shell. Users choose where to find the libraries, which library is of high priority.
  3. Hard code these environment variable to the project file of ocaml-fswatch

IMHO, 1 or 2 is preferred. Suggestions are welcome.

dannypsnl commented 11 months ago
$ brew shellenv
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
kandu commented 11 months ago

A new commit in the silicon branch now uses conditional compilation to generate cflags and lib-flags in pre-compile time. The opam file now uses a separate set of build commands specifically for "arch=arm64 & distribution=homebrew" so Silicon mac is distinguished from Intel mac. Hope it works.

dannypsnl commented 11 months ago

I tried, but I made a little change, pkg-config didn't work as expected

From 23621eea941837e318896bbeaa8790e3c625f2e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=AEm=20Ts=C3=BA-thu=C3=A0n?= <dannypsnl@gmail.com>
Date: Tue, 26 Sep 2023 19:33:37 +0800
Subject: [PATCH 1/1] fix in m1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Lîm Tsú-thuàn <dannypsnl@gmail.com>
---
 fswatch.opam | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/fswatch.opam b/fswatch.opam
index 7f3b1e1..831371b 100644
--- a/fswatch.opam
+++ b/fswatch.opam
@@ -9,13 +9,8 @@ build: [
   ["sh" "-exec" "echo \\(-I/usr/local/include/libfswatch/c -I/usr/include/libfswatch/c\\) > fswatch/src/inc_cflags"] { !(os-distribution = "homebrew" & arch = "arm64") }
   ["sh" "-exec" "echo -lfswatch > fswatch/src/inc_libs"] { !(os-distribution = "homebrew" & arch = "arm64") }

-  ["sh" "-exec" "echo \\( > fswatch/src/inc_cflags"] { os-distribution = "homebrew" & arch = "arm64" }
-  ["sh" "-exec" "echo \\( > fswatch/src/inc_libs"] { os-distribution = "homebrew" & arch = "arm64" }
-
-  ["pkg-config" "--cflags" ">>" "fswatch/src/inc_cflags"] { os-distribution = "homebrew" & arch = "arm64" }
-  ["pkg-config" "--libs" ">>" "fswatch/src/inc_libs"] { os-distribution = "homebrew" & arch = "arm64" }
-  ["sh" "-exec" "echo \\) >> fswatch/src/inc_cflags"] { os-distribution = "homebrew" & arch = "arm64" }
-  ["sh" "-exec" "echo \\) >> fswatch/src/inc_libs"] { os-distribution = "homebrew" & arch = "arm64" }
+  ["sh" "-exec" "echo \\(-I/opt/homebrew/include/libfswatch/c\\) > fswatch/src/inc_cflags"] { os-distribution = "homebrew" & arch = "arm64" }
+  ["sh" "-exec" "echo \\(-L/opt/homebrew/lib -lfswatch\\) > fswatch/src/inc_libs"] { os-distribution = "homebrew" & arch = "arm64" }

   ["dune" "build" "-p" name "-j" jobs]
 ]
-- 
2.42.0

The patch here will work on Silicon environment.

kandu commented 11 months ago

Ah, Thanks. Issue resolved :)

kandu commented 11 months ago

Update in the main branch. This issue is closed since it's resolved.