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

Unable to install conf-gmp on Arch Linux with Homebrew #25257

Open
pm5 opened this issue Feb 15, 2024 · 3 comments
Open

Unable to install conf-gmp on Arch Linux with Homebrew #25257

pm5 opened this issue Feb 15, 2024 · 3 comments

Comments

@pm5
Copy link
Contributor

pm5 commented Feb 15, 2024

Hello. I have Homebrew installed on a custom location at /home/linuxbrew/.linuxbrew. When trying to install conf-gmp using gmp provided by Homebrew, I encoutered the folowing errors:

$ env CFLAGS="-I$(brew --prefix)/include" opam install conf-gmp
The following actions will be performed:
  ∗ install conf-gmp 4

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of conf-gmp.4 failed at "sh -exc cc -c $CFLAGS -I/usr/local/include test.c".

#=== ERROR while compiling conf-gmp.4 =========================================#
# context     2.1.5 | linux/x86_64 | ocaml-base-compiler.4.14.1 | https://opam.ocaml.org#a2d9de3b
# path        ~/.opam/stdlib/.opam-switch/build/conf-gmp.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exc cc -c $CFLAGS -I/usr/local/include test.c
# exit-code   1
# env-file    ~/.opam/log/conf-gmp-178822-403927.env
# output-file ~/.opam/log/conf-gmp-178822-403927.out
### output ###
# + cc -c -I/home/linuxbrew/.linuxbrew/include -I/usr/local/include test.c
# test.c:1:10: fatal error: gmp.h: No such file or directory
#     1 | #include <gmp.h>
#       |          ^~~~~~~
# compilation terminated.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build conf-gmp 4
└─ 
╶─ No changes have been performed

This looks suspiciously like #6958, except that I've already set the CFLAGS to where the header file should be and indeed was:

$ ls $(brew --prefix)/include/gmp.h
/home/linuxbrew/.linuxbrew/include/gmp.h

What's more baffling for me is that if I run the build command manually, it works. If I do:

$ opam source conf-gmp
$ cd conf-gmp.4/
$ export CFLAGS="-I$(brew --prefix)/include" 

then this works:

$ sh -exc "cc -c $CFLAGS -I/usr/local/include test.c"
+ cc -c -I/home/linuxbrew/.linuxbrew/include -I/usr/local/include test.c

but this doesn't:

$ opam pin add .
...
<> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved conf-gmp.4  (file:///run/media/deck/7964a95d-ebb5-4dc2-9346-f59577499d65/pm5/src/slacko/conf-gmp.4)
[ERROR] The compilation of conf-gmp.4 failed at "sh -exc cc -c $CFLAGS -I/usr/local/include test.c".

#=== ERROR while compiling conf-gmp.4 =========================================#
# context     2.1.5 | linux/x86_64 | ocaml-base-compiler.4.14.1 | pinned(file:///run/media/deck/7964a95d-ebb5-4dc2-9346-f59577499d65/pm5/src/slacko/conf-gmp.4)
# path        ~/.opam/stdlib/.opam-switch/build/conf-gmp.4
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exc cc -c $CFLAGS -I/usr/local/include test.c
# exit-code   1
# env-file    ~/.opam/log/conf-gmp-179328-e15062.env
# output-file ~/.opam/log/conf-gmp-179328-e15062.out
### output ###
# + cc -c -I/home/linuxbrew/.linuxbrew/include -I/usr/local/include test.c
# test.c:1:10: fatal error: gmp.h: No such file or directory
#     1 | #include <gmp.h>
#       |          ^~~~~~~
# compilation terminated.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build conf-gmp 4
└─ 
╶─ No changes have been performed
[NOTE] Pinning command successful, but your installed packages may be out of sync.

This there anything I missed or I can try?

@arbipher
Copy link
Collaborator

I tried doing some experiments but did not find the reason yet. It may not be totally useless so let me share it here.

I don't know a good way to set custom homebrew prefix for experimenting, given I just use the default prefix (and it costs too much to totally re-install it).

I have a brew installed gmp and I did

/usr/local/Cellar/gmp/6.3.0$ mv include include-hack

The header file in the prefix path is just a soft link /usr/local/includegmp.h -> /usr/local/Cellar/gmp/6.3.0/include/gmp.h.

Now both opam install conf-gmp and opam pin add . fail and complain on cannot find <gmp.h>. The default CFLAGS is empty.

Then after export CFLAGS=-I/usr/local/Cellar/gmp/6.3.0/include-hack, both opam install conf-gmp and opam pin add . work.

I cannot reproduce your problem but would you like to check if the custom prefix in your machine does soft-links to the correct gmp/include path?

You can also add export $CFLAGS in the build section in the local opam's file (after opam source conf-gmp) to see if the $CFLAGS is passed correctly when running opam pin add . -vv (not sure if -vv is necessary).

@pm5
Copy link
Contributor Author

pm5 commented Feb 25, 2024

Thanks for spending time with me on this. I checked the soft-link and it appears to be correct.

lrwxrwxrwx 1 deck deck 33 Feb 15 09:36 /home/linuxbrew/.linuxbrew/include/gmp.h -> ../Cellar/gmp/6.3.0/include/gmp.h

(Yes, I'm going through the trouble because I want to build OCaml programs on Steam Deck, whose SteamOS is Arch-based.)

I can also see the content of the header file with cat $(brew --prefix)/include/gmp.h.

Also tried adding the following as the first line in the build section of the local opam file:

["sh" "-exc" "export CFLAGS=/home/linuxbrew/.linuxbrew/include"]

but it didn't change the result. Plus, I think the compilation command (the line immediately before the failure on test.c) already says it got the CFLAGS argument, no?

# + cc -c -I/home/linuxbrew/.linuxbrew/include -I/usr/local/include test.c

@arbipher
Copy link
Collaborator

arbipher commented Feb 25, 2024

Maybe the reason is opam (sh -exc) cannot keep the environment across the actions inside the build.
Exported environment variables can only live with one shell process if I remember correctly.

If you add the debug commands in it

build: [
  ["sh" "-exc" "export FOO=/home/linuxbrew/.linuxbrew/include"]
  ["sh" "-exc" "echo $FOO"]
  ...

the log (opam install . --verbose) will have

+ /home/me/.opam/opam-init/hooks/sandbox.sh "build" "sh" "-exc" "export FOO=/home/linuxbrew/.linuxbrew/include" (CWD=/home/me/.opam/5.1.1/.opam-switch/build/conf-gmp.4)
- + export FOO=/home/linuxbrew/.linuxbrew/include
+ /home/me/.opam/opam-init/hooks/sandbox.sh "build" "sh" "-exc" "echo $FOO" (CWD=/home/me/.opam/5.1.1/.opam-switch/build/conf-gmp.4)
- + echo

This can also explain why your experiment works because a child process (sh -exc) can inherit environment variables from the parent shells.

$ export CFLAGS="-I$(brew --prefix)/include" 
sh -exc "cc -c $CFLAGS -I/usr/local/include test.c"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants