Zulip Chat Archive

Stream: lean4

Topic: Forcing Lake to build lib


Patrick Massot (Aug 09 2022 at 13:04):

How do I tell Lake to build all lean files it can find in some directory in the project, even when it thinks those files are not used? The reason why Lake mistakenly thinks those files are useless is because they are imported dynamically using importModules.

Henrik Böving (Aug 09 2022 at 13:37):

You can remove the build directory which will force a full rebuild of the top.level

Patrick Massot (Aug 09 2022 at 13:38):

That won't do anything since Lake thinks those files are useless.

Patrick Massot (Aug 09 2022 at 13:39):

Those files are not statically imported by any other file in the project.

Arthur Paulino (Aug 09 2022 at 14:00):

We've done it here: https://github.com/yatima-inc/yatima-lang
The pieces of the puzzle are:

  • A Yatima.lean file containing all Lean files inside the Yatima directory
  • A Lake script that creates that file automatically
  • A Yatima lib that allows you to call lake build Yatima

Arthur Paulino (Aug 09 2022 at 14:02):

If you want to go further, you can integrate it in a CI workflow:
https://github.com/yatima-inc/yatima-lang/blob/main/.github/workflows/ci.yml#L21-L24

The import_all? script checks if the Yatima.lean file indeed contains everything it should contain. If it fails, then it recommends the user to run lake run import_all

Siddhartha Gadgil (Aug 09 2022 at 14:07):

What I do is go into the correct subdirectory of lean_pkg and then build. But I believe e.g. lake build math3port works too with newer lakes (i.e., with the name used in require).

Patrick Massot (Aug 09 2022 at 14:12):

It looks like Arthur's trick could be used, but I was hoping for something much simpler. I don't understand Siddartha's suggestion.

Arthur Paulino (Aug 09 2022 at 14:46):

I'd love being able to say lake build-dir Yatima or something like that. It would also avoid the need for maintaining the Mathlib.lean file in the Mathlib4 repo

Siddhartha Gadgil (Aug 09 2022 at 15:17):

As an example if I am using mathlib in a meta way (as I do), in linux I do

cd lean_packages/mathlib
lake build
cd ../..

Siddhartha Gadgil (Aug 09 2022 at 15:17):

Have done this quite a bit and it works.

Patrick Massot (Aug 09 2022 at 15:17):

But mathlib itself does explicitly list its imports, so this isn't my situation at all.

Siddhartha Gadgil (Aug 09 2022 at 15:18):

More recent lakes also should allow simply:

lake build mathlib

Siddhartha Gadgil (Aug 09 2022 at 15:19):

In my example I have

importModules [{module := `Mathlib}

Patrick Massot (Aug 09 2022 at 15:19):

But mathlib itself is a Lean library which lists all its files.

Siddhartha Gadgil (Aug 09 2022 at 15:20):

I see. In my situation I had lean packages with their own lakefiles, which I used to build.

Siddhartha Gadgil (Aug 09 2022 at 15:21):

Do you mean that you have your own module? In that case one can import it in another build target and build that.

Siddhartha Gadgil (Aug 09 2022 at 15:22):

A cruder way, which I used in the past, was to temporarily import the file. I had to then remove import to avoid collisions. But that was before lake had multiple targets.

Siddhartha Gadgil (Aug 09 2022 at 15:23):

If I understand correctly, an option may be to have a file metaimports.lean which just imports stuff you would call with importModule and is a lake target. Then lake metaimports will build them all.

Siddhartha Gadgil (Aug 09 2022 at 15:26):

I see that I have converged to a manual version of Arthur's solution. So I have added no value (except to say I found no better way).

Patrick Massot (Aug 09 2022 at 15:31):

Maybe I'm not clear at all. Let's try with reproducible instructions. Do

lake +leanprover/lean4:nightly-2022-08-09 new exemple && cd exemple && mkdir Foo && echo "def x := 3" > Foo/foo.lean

Then run lake build. Then build/lib folder won't contain a compiled version of Foo/foo.lean. I want to know how to modify my lakefile to tell lake to compile every file contained in Foo and put the result in build/lib/Foo, and I don't ever want to write by hand the list of files contained in Foo since a computer should be smart enough to list files in a folder (I'm not even asking for a recursive listing).

Arthur Paulino (Aug 09 2022 at 15:38):

AFAIK it's not possible yet. Hence my wishlisted lake build-dir Foo command above.

Lake's current build capabilities are based on targets, not directories

Patrick Massot (Aug 09 2022 at 15:39):

I guess this is all consistent with the difference between imperative programming and functional programming: you can't give orders to lake.

Mac (Aug 09 2022 at 16:06):

Arthur Paulino said:

AFAIK it's not possible yet.

Lake's current build capabilities are based on targets, not directories

This has been possible for a long time and was a feature requested then by Mario. This is what the globs option of a Lean Library is for.

Mac (Aug 09 2022 at 16:07):

If you want to build a specifically module in the library's source directory (e.g., Foo) just add it to the globs. If you want to build the module and all submodules in the the source directory (e.g., Yatima) you can add .andSubmodules `Yatima to the list.

Siddhartha Gadgil (Aug 10 2022 at 02:03):

Mac said:

Arthur Paulino said:

AFAIK it's not possible yet.

Lake's current build capabilities are based on targets, not directories

This has been possible for a long time and was a feature requested then by Mario. This is what the globs option of a Lean Library is for.

Maybe the documentation could be tweaked. I read the README and did not find this feature as I did not understand what a glob was (and so decided something not applicable to me).


Last updated: Dec 20 2023 at 11:08 UTC