ocaml-obuild / obuild

simple package build system for ocaml
BSD 2-Clause "Simplified" License
55 stars 20 forks source link

obuild doesn't compile with ocaml-5 #186

Closed UnixJunkie closed 1 year ago

UnixJunkie commented 1 year ago

I don't need it, this is just FYI.

reubenrowe commented 1 year ago

It looks like the latest commit 5845999 fixes this? Will a new version of obuild with this fix be published to OPAM, please?

I have a project relying on the opam published version of Jean-Christophe Filliâtre's hashset package, which uses obuild to compile. So it would be preferable to have the published obuild package building with OCaml >= 5.x

Thanks!

UnixJunkie commented 1 year ago

Maybe, you could also pass hashset to dune and be safe for the long term.

jeromemaloberti commented 1 year ago

I can create a new version easily, but I don't know how to update the opam package. I need to check that.

reubenrowe commented 1 year ago

@UnixJunkie yes, I will submit a pull request for porting hashset to dune. @jeromemaloberti I think it would still be good to have the OPAM version of obuild up to date.

jeromemaloberti commented 1 year ago

I created the tag and updated the repo. But I'm struggling with the update of opam-repo.

reubenrowe commented 1 year ago

Do you want some input on this? If you give more details, maybe I can help out?

jeromemaloberti commented 1 year ago

I never updated it, so it is new. But I'm confused because:

jeromemaloberti commented 1 year ago

https://github.com/ocaml/opam-repository/pull/24722 Wait and see.

reubenrowe commented 1 year ago

You updated as I was writing this ... but for reference:

The problem might be because the opam file is specifying opam version 1.2, and opam-publish states that you need to be using OPAM version >=2.0.

You may also need to extend the opam file (e.g. adding the package version number there).

jeromemaloberti commented 1 year ago

I updated the opam file https://github.com/ocaml-obuild/obuild/blob/master/opam But I forgot to commit it. I didn't put the package version number, though.

jeromemaloberti commented 1 year ago

I added the package version and the project name. But I had to commit it before opam decided to compile and install it. So, it seems to only consider files in git ??

reubenrowe commented 1 year ago

Yes, well OPAM pulls the code from the repository you specify, so if the changes are not there then they are not visible.

You need to check the results of the CI tests.

jeromemaloberti commented 1 year ago

I fixed them and pushed to opam-repo.

jeromemaloberti commented 1 year ago

Lint complained about "version" and "project", but not on my computer.

jeromemaloberti commented 1 year ago

If I put unix in depends, it fails to compile on 4.x ... I guess I need to put a condition ... But which one ?

jeromemaloberti commented 1 year ago

@reubenrowe I'm stuck, if I put "unix" in depends, 4.x skips the build because it is unknown. But if I put "base-unix", 5.x complains that unix is missing.

reubenrowe commented 1 year ago

@jeromemaloberti OK, I will spend some time later today trying to figure this out on my own local copy of obuild

jeromemaloberti commented 1 year ago

Thank you. I added depopts: ["unix" {"ocaml" >= "5.0.0"}] which seems to help a bit, but some platform (arm, ppc and bsd ?) are still failing ...

reubenrowe commented 1 year ago

OK, so I think the problem might be that obuild actually depends on ocamfind to build itself, and this isn't reflected in the opam file. I guess some of the test environments used in the CI pipeline must have ocamlfind installed by default, while others don't; and it is the ones that don't have it pre-installed that are failing.

You don't need any depopts: [...] in the opam file, but you do need depends: [ "ocaml" "ocamlfind" {build} ].

jeromemaloberti commented 1 year ago

obuild doesn't need ocamlfind, but it needs the META files. It is also possible that the resolution of dependencies changed between 4 and 5, and the option "+unix" is resolved differently now. I pushed a change, and waiting for the result.

reubenrowe commented 1 year ago

It does depend on ocamlfind! At least in the sense that it tries to use it.

https://github.com/ocaml-obuild/obuild/blob/master/obuild/findlibConf.ml#L37

This is ultimately the cause of the build going wrong for OCaml versions 5.x.

The failure is after the obuild.bootstrap executable has been built by the bootstrap script (which succeeds), and it then tries to run it with the configure command.

https://github.com/ocaml-obuild/obuild/blob/master/bootstrap#L103

This reads the obuild.obuild configuration file, which lists the unix library as a dependency in several places. Part of the configuration is to find the location of this library.

Before OCaml 5.x, the unix.cm* files were in the root directory of the standard library path, and so the library was picked up automatically (by the Analyze.initializeSystemStdlib function) and stored in the Metacache.pkgs_cache hashtable.

From OCaml 5.1, the location of this library has been moved to a subdirectory, and so it is not added to the packages cache automatically. Then, ocambuild falls back on trying to call ocamlfind to look up the location of the library. Thus, without ocamlfind, the tool will fail to find the library.

So, one solution is to add ocamlfind as dependency. We can see now that this has now solved the problems in the OPAM CI pipeline.

Another solution is to modify Analyze.initializeSystemStdlib function so that it recurses into subdirectories looking for libraries.

jeromemaloberti commented 1 year ago

Thank you. That's clear now. It has been merged, so I will close the issue. Thank you very much for your help with opam.