Zulip Chat Archive

Stream: lean4

Topic: building a single file in mathlib


Johan Commelin (Feb 13 2024 at 14:46):

I was trying to do an automated git bisect on mathlib. But I realize that in Lean 4 I no longer know how to build a single Lean file. Can someone please educate me?

Damiano Testa (Feb 13 2024 at 14:50):

lake env lean [file]
## or
lake build [file]

one of the two takes a path, the other the same format as import -- can't remember which one. Should be done from the root dir, I think.

Johan Commelin (Feb 13 2024 at 14:51):

Thanks

Damiano Testa (Feb 13 2024 at 14:51):

I think that build will build the o/ileans, the other will not.

Johan Commelin (Feb 13 2024 at 14:54):

The first seems to do what I want (-;

Sebastian Ullrich (Feb 13 2024 at 14:56):

These are not the same! Only the latter command will rebuild dependencies and save .oleans

Johan Commelin (Feb 13 2024 at 14:56):

I want to count heartbeats for some decl. So I don't think rebuilding is necessary, right?

Johan Commelin (Feb 13 2024 at 14:56):

I'm grabbing oleans from the cache

Sebastian Ullrich (Feb 13 2024 at 14:57):

Then it's fine

Julian Berman (Feb 13 2024 at 15:16):

Maybe this is a separate question, but neither of the two work for a case where you have a directory not listed as a package in the lakefile -- is there a way to do that perchance? The use case is I have some directory inside my local mathlib repo where I have random self contained files I've played with that depend on Mathlib. It'd be convenient if there was a way to say "build Scratch/foo.lean", which doesn't work as-is because Scratch obviously isn't in Mathlib's lakefile as a package. But lake / lean must have all it needs to do that, because opening/editing files in there works fine and builds what's needed at edit-time, so I mostly haven't bothered and rely on this being built in the editor -- is there some CLI way to do it?

Matthew Ballard (Feb 13 2024 at 15:59):

It might also be ergonomic to use

time -v lake env lean --profile X/Y/Z.lean

if you don't want to jump into the editor ever.

Johan Commelin (Feb 13 2024 at 16:05):

During the bisect, I just edited the file at the start, and git was smart enough to keep the edit in place all the way till the end of the bisect. So I didn't have to edit much either. But I'll keep this in mind.

David Loeffler (Feb 14 2024 at 06:56):

While we're on the topic of building single files:

IMHO, the fact that lake build expects input in the same format as import, delimited with ., makes it un-ergonomic to build single files from the command line – it defeats the shell tab completion for filenames. This is a regression from lean 3, where lean --makehappily accepted a file path. Can I take the opportunity to request support for tab-completion in lake build?

Johan Commelin (Feb 14 2024 at 06:57):

cc @Mac Malone

Mac Malone (Feb 14 2024 at 07:02):

lean4#2756

Damiano Testa (Feb 14 2024 at 08:10):

For a temporary fix, take a look at

https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/fastest.20way.20to.20copy.20module.20name.20of.20the.20current.20file.3F/near/401710404

(I'm on mobile, I hope the link works!)

Kevin Buzzard (Feb 14 2024 at 08:17):

Regarding @Julian Berman 's situation (also a regression from lean 3), I fixed this locally by moving my scratch directory into the Mathlib directory (which makes it slightly harder to find, but at least I can now compile on command line)

Julian Berman (Feb 14 2024 at 18:22):

Bleh yeah reasonable, I guess I could do that too, it's just slightly easier to commit accidentally, but I'll gitignore.

Kevin Buzzard (Feb 14 2024 at 20:04):

I edit my .git/info/exclude rather than goofing around with mathlib's .gitignore


Last updated: May 02 2025 at 03:31 UTC