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

Some simplifications and improvements to the configure script #132

Merged
merged 3 commits into from
Jul 18, 2023

Conversation

xavierleroy
Copy link
Contributor

  • Remove host detection and config.guess script. We no longer need it to select between assembly files.
  • Use pkg-config to find GMP. This works better on Mac with Homebrew, for example. Fall back to the old method if pkg-config is not available or doesn't know about GMP.

@xavierleroy
Copy link
Contributor Author

Also, I wonder about MPIR support. This library seems to be abandoned, e.g. http://mpir.org is down and can only be found on archive.org. Likewise, there are few packages for MPIR around (none in Debian and Ubuntu, for example), and some are marked obsolete (Homebrew).

@xavierleroy xavierleroy force-pushed the configure-revised branch 2 times, most recently from e1e80bb to a967e22 Compare March 13, 2023 18:48
@antoinemine
Copy link
Collaborator

The rationale for MPIR was the better support for Microsoft's compilers on Windows. I understand that there is still some activity on a Windows-specific fork of MPIR https://github.com/wbhart/mpir (github are the new web pages !)

@ddeclerck
Copy link

Hi,

Could I suggest making the configure script more cross-compilation-friendly ? (i.e. using ocamlfind to look for ocaml* binaries and allow specifying a C toolchain prefix, to be used when calling pkg-config)

@antoinemine
Copy link
Collaborator

Could I suggest making the configure script more cross-compilation-friendly ? (i.e. using ocamlfind to look for ocaml* binaries and allow specifying a C toolchain prefix, to be used when calling pkg-config)

I think this should belong to a different issue.

Would switching to dune (#73) help ?

@ddeclerck
Copy link

Would switching to dune (#73) help ?

That would work too, indeed.

@xavierleroy
Copy link
Contributor Author

(i.e. using ocamlfind to look for ocaml* binaries and allow specifying a C toolchain prefix, to be used when calling pkg-config)

I have no experience with cross-compiling OCaml libraries. Can you point me at examples of OCaml packages that use the cross-compilation tricks you mention?

@xavierleroy
Copy link
Contributor Author

I understand that there is still some activity on a Windows-specific fork of MPIR https://github.com/wbhart/mpir

Last commit in 2020. Last (and first) release in 2017. I'm not reassured.

@ddeclerck
Copy link

(i.e. using ocamlfind to look for ocaml* binaries and allow specifying a C toolchain prefix, to be used when calling pkg-config)

I have no experience with cross-compiling OCaml libraries. Can you point me at examples of OCaml packages that use the cross-compilation tricks you mention?

There are a few packages from opam-cross-windows that perform some of these tricks (though none of them do precisely what we want here) :
https://github.com/ocaml-cross/opam-cross-windows/blob/main/packages/ocurl-windows/ocurl-windows.0.9.2/opam
https://github.com/ocaml-cross/opam-cross-windows/blob/main/packages/camlzip-windows/camlzip-windows.1.07/files/patches/cross-compilation.patch
https://github.com/ocaml-cross/opam-cross-windows/blob/main/packages/ctypes-windows/ctypes-windows.0.17.1/opam

However it should be sufficient to change the first lines of your configure script as follows:

ocaml='ocamlfind ocaml'
ocamlc='ocamlfind ocamlc'
ocamlopt='ocamlfind ocamlopt'
ocamlmklib='ocamlfind ocamlmklib'
ocamldep='ocamlfind ocamldep'
ocamldoc='ocamlfind ocamldoc'

And prepend a variable named PREFIX (or anything you like) to each occurrence of pkg-config :

    if ${PREFIX}pkg-config gmp 2>/dev/null; then
        echo 'package gmp: found'
        gmp='OK'
        cclib="$cclib $(${PREFIX}pkg-config --libs gmp)"
        ccinc="$ccinc $(${PREFIX}pkg-config --cflags gmp)"
        ccdef="-DHAS_GMP $ccdef"

ocamlfind uses the OCAMLFIND_TOOLCHAIN environment variable to look for the proper ocaml* binaries. As for the PREFIX variable, it is meant to be fed to the configure script by an opam file modified for cross-compilation (and should be left blank otherwise). Here, we could add zarith to the opam-cross-windows repository simply by tweaking its build command in the opam file as follows:

build: [
  [ "sh" "-exc" "OCAMLFIND_TOOLCHAIN=windows PREFIX=%{conf-gcc-windows:prefix}% ./configure" ]
]

We no longer need it to select between assembly files.
This works better on Mac with Homebrew, for example.
Fall back to the old method if pkg-config is not available or doesn't work.
Namely:
- Whether GMP was found from pkg-config
- Which C includes were selected (in summary of configuration)
@xavierleroy
Copy link
Contributor Author

This PR hasn't been reviewed, but I think it's good stuff and I'm going to merge it nonetheless.

The discussion side-stepped in two directions:
1- Support for MPIR: OK, let's keep it unchanged, even though the MPIR project looks completely dead.
2- Support for cross-compilation: a PR along the lines mentioned by @ddeclerck would be welcome, but it's a separate topic.

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

Successfully merging this pull request may close these issues.

3 participants