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

Use leanc written in Lean for testing & distribution #687

Merged
merged 2 commits into from
Sep 25, 2021

Conversation

Kha
Copy link
Member

@Kha Kha commented Sep 24, 2021

Building is still handled by a (minimal) Bash script for bootstrapping purposes

@Kha Kha force-pushed the lean-leanc branch 2 times, most recently from 6855d0a to 3475698 Compare September 24, 2021 15:05
building is still handled by a (minimal) Bash script for bootstrapping purposes
@@ -325,7 +325,7 @@ endif()
# are already loaded) and probably fail unless we set up LD_LIBRARY_PATH.
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# import library created by the `leanshared` target
set(LEANC_SHARED_LINKER_FLAGS "${LEANC_SHARED_LINKER_FLAGS} $bindir/libleanshared.dll.a")
set(LEANC_SHARED_LINKER_FLAGS "${LEANC_SHARED_LINKER_FLAGS} -lleanshared")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why cant this library dependency be a cmake target DEPENDS ? is it because "leanshared" is not a cmake "add_library" somewhere? If so, why isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is baked into leanc, i.e. user programs are linked with it as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way the title of this PR confuses me, "testing & distribution", isn't stdlib.make a central part of the regular build too? What does "distribution" mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distribution means what we ship to users, i.e. the release tarballs created by cpack

if args.isEmpty then
IO.println "Lean C compiler

A simple wrapper around a C compiler. Defaults to `@LEANC_CC@`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, are you moving bash shell scripts to lean? That's awesome, and will make one day building on windows easier right? Do we still need nix if we use Lean like this? Is this what Lake is ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never needed Nix :) . It's always been an alternative setup. But this + #659 + #683 will mean that we have a self-contained build system (for Lean packages, not Lean itself) without any GNU dependencies, yes.

$LEAN_CC "${cflags[@]}" "${args[@]}" "${ldflags_ext[@]}" "${ldflags[@]}" -Wno-unused-command-line-argument
# used only for building Lean itself
root=$(dirname $0)
${LEAN_CC:-@CMAKE_C_COMPILER@} "-I$root/include" @LEANC_EXTRA_FLAGS@ "$@" "-L$root/lib/lean" "${LEANC_GMP:--lgmp}" @LEAN_EXTRA_LINKER_FLAGS@ -Wno-unused-command-line-argument
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really still need this leanc.sh then? Can't we just move this line into the place that calls it? I think that's only stdlib.make.in right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, yes. It wouldn't exactly be pretty, and it makes it easier to communicate the flags to Nix.

@Kha Kha merged commit e692725 into leanprover:master Sep 25, 2021
@tydeu
Copy link
Member

tydeu commented Sep 25, 2021

@Kha looking at the simplicity of leanc makes me wonder whether it should instead just be part of Lake? That is, I could just add a lake cc/lake ld commands that does the same thing as leanc and no longer need to call out to an external leanc process when building Lean modules.

In order to keep things in sync, the built-in settings for leanc (i.e., LEAN_CC, LEANC_EXTRA_FLAGS, etc.) could be in a Lean.C (or Leanc) module shipped with Lean. That way they could easily change as Lean changes without often having to simultaneously update Lake.

Also, it seems to me like --print-cflags and --print-ldflags could be merged into the lean itself.

@Kha
Copy link
Member Author

Kha commented Sep 25, 2021

I considered it, but I didn't really see the point. Unless process creation on Windows is that slow.

@Kha Kha deleted the lean-leanc branch September 25, 2021 21:42
@tydeu
Copy link
Member

tydeu commented Sep 25, 2021

@Kha In my view, such a solutions provides the following benefits:

  • It allows the leanc wrapper options (e.g., -shared) to be properly typed terms rather than strings (e.g., in Lake)
  • The default options would be know at a Lean level, rather than being built into the executable
  • Allows easier separation of the C compiler and linker in Lake (allowing end users to potentially configure both separately)
    • Useful if people write different backends (i.e., emitting LLVM bytecode/assembly rather than C)
  • Removes the need for a separate leanc executable (once Lake is packaged with Lean)

@Kha
Copy link
Member Author

Kha commented Oct 2, 2021

We can reevaluate the design when lake is the default

@tydeu
Copy link
Member

tydeu commented Oct 2, 2021

@Kha Fair enough. However, I did come up with one more reason in the meantime. I'll put it here so I don't forget it.

One of the changes on my list is to make the compiler a target as well. This will make its hash part of the trace of targets which use it. Thus, they will be automatically rebuilt when the compiler binary changes. However, the hash of the current leanc would not change when the wrapped compiler changes versions. Even then, lake could still be smart and special case on leanc and use the hash of wrapped compiler as well. However, I think at that point, the overhead would likely be greater than just merging leanc into lake.

Just something to keep in mind for the future.

@Kha
Copy link
Member Author

Kha commented Oct 2, 2021

Ok, makes sense

ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this pull request Dec 2, 2022
This makes the `a b c` in `cases' foo with a b c` get hovers and syntax highlighting for the variables that were introduced.
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