Skip to content

Commit bf76eca

Browse files
committed
chore: merge Lake into src/lake
2 parents 9a3657d + f46c792 commit bf76eca

File tree

239 files changed

+10595
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+10595
-0
lines changed

src/lake/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

src/lake/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sh text eol=lf

src/lake/.github/workflows/ci.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
skip_check:
7+
name: Skip Check
8+
continue-on-error: true
9+
runs-on: ubuntu-latest
10+
outputs:
11+
should_skip: ${{ steps.skip_check.outputs.should_skip }}
12+
steps:
13+
- id: skip_check
14+
uses: fkirc/skip-duplicate-actions@v4
15+
with:
16+
concurrent_skipping: 'same_content_newer'
17+
paths_ignore: '["README.md", "LICENSE"]'
18+
19+
build:
20+
needs: skip_check
21+
name: ${{ matrix.name || 'Build' }}
22+
if: ${{ needs.skip_check.outputs.should_skip != 'true' }}
23+
runs-on: ${{ matrix.os }}
24+
defaults:
25+
run:
26+
shell: ${{ matrix.shell || 'sh' }}
27+
strategy:
28+
matrix:
29+
include:
30+
- name: Ubuntu
31+
os: ubuntu-latest
32+
- name: MacOS
33+
os: macos-latest
34+
- name: Windows
35+
os: windows-latest
36+
shell: msys2 {0}
37+
# complete all jobs
38+
fail-fast: false
39+
steps:
40+
- name: Install MSYS2 (Windows)
41+
if: matrix.os == 'windows-latest'
42+
uses: msys2/setup-msys2@v2
43+
with:
44+
path-type: inherit
45+
install: curl unzip make diffutils mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp
46+
- name: Install Elan
47+
shell: bash -euo pipefail {0}
48+
run: |
49+
curl -sSfL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | sh -s -- -y --default-toolchain none
50+
echo "$HOME/.elan/bin" >> $GITHUB_PATH
51+
- name: Checkout
52+
uses: actions/checkout@v2
53+
- name: Check Lean
54+
run: lean --version
55+
- name: Build & Time
56+
run: ./time.sh -j4
57+
- name: Upload Build
58+
continue-on-error: true
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: ${{ matrix.os }}
62+
path: build
63+
- name: Check Lake
64+
run: make check-lake
65+
- name: Test Lake
66+
run: make test-ci
67+
- name: Time Bootstrap
68+
run: make time-bootstrap
69+
- name: Check Bootstrap
70+
run: make check-bootstrap
71+
- name: Test Bootstrapped Lake
72+
run: make test-bootstrapped -j4

src/lake/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build
2+
produced.out
3+
result*
4+
# Do not commit the flake lockfile to avoid having to maintain it
5+
flake.lock

src/lake/LICENSE

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Apache License 2.0 (Apache)
2+
Apache License
3+
Version 2.0, January 2004
4+
http://www.apache.org/licenses/
5+
6+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7+
8+
1. Definitions.
9+
10+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
11+
12+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
13+
14+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15+
16+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
17+
18+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
19+
20+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
21+
22+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
23+
24+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
25+
26+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
27+
28+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
29+
30+
2. Grant of Copyright License.
31+
32+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
33+
34+
3. Grant of Patent License.
35+
36+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
37+
38+
4. Redistribution.
39+
40+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41+
42+
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
43+
44+
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
45+
46+
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
47+
48+
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
49+
50+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
51+
52+
5. Submission of Contributions.
53+
54+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
55+
56+
6. Trademarks.
57+
58+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
59+
60+
7. Disclaimer of Warranty.
61+
62+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
63+
64+
8. Limitation of Liability.
65+
66+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
67+
68+
9. Accepting Warranty or Additional Liability.
69+
70+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

src/lake/Lake.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/-
2+
Copyright (c) 2021 Mac Malone. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Mac Malone
5+
-/
6+
import Lake.Build
7+
import Lake.Config
8+
import Lake.DSL
9+
import Lake.Version
10+
import Lake.CLI.Actions

src/lake/Lake/Build.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/-
2+
Copyright (c) 2021 Mac Malone. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Mac Malone
5+
-/
6+
import Lake.Build.Monad
7+
import Lake.Build.Actions
8+
import Lake.Build.Index
9+
import Lake.Build.Module
10+
import Lake.Build.Package
11+
import Lake.Build.Library
12+
import Lake.Build.Imports

src/lake/Lake/Build/Actions.lean

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/-
2+
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Gabriel Ebner, Sebastian Ullrich, Mac Malone
5+
-/
6+
import Lake.Util.Proc
7+
import Lake.Util.NativeLib
8+
import Lake.Build.Context
9+
10+
namespace Lake
11+
open System
12+
13+
def createParentDirs (path : FilePath) : IO Unit := do
14+
if let some dir := path.parent then IO.FS.createDirAll dir
15+
16+
def compileLeanModule (name : String) (leanFile : FilePath)
17+
(oleanFile? ileanFile? cFile? : Option FilePath)
18+
(leanPath : SearchPath := []) (rootDir : FilePath := ".")
19+
(dynlibs : Array FilePath := #[]) (dynlibPath : SearchPath := {})
20+
(leanArgs : Array String := #[]) (lean : FilePath := "lean")
21+
: BuildM Unit := do
22+
logStep s!"Building {name}"
23+
let mut args := leanArgs ++
24+
#[leanFile.toString, "-R", rootDir.toString]
25+
if let some oleanFile := oleanFile? then
26+
createParentDirs oleanFile
27+
args := args ++ #["-o", oleanFile.toString]
28+
if let some ileanFile := ileanFile? then
29+
createParentDirs ileanFile
30+
args := args ++ #["-i", ileanFile.toString]
31+
if let some cFile := cFile? then
32+
createParentDirs cFile
33+
args := args ++ #["-c", cFile.toString]
34+
for dynlib in dynlibs do
35+
args := args.push s!"--load-dynlib={dynlib}"
36+
proc {
37+
args
38+
cmd := lean.toString
39+
env := #[
40+
("LEAN_PATH", leanPath.toString),
41+
(sharedLibPathEnvVar, (← getSearchPath sharedLibPathEnvVar) ++ dynlibPath |>.toString)
42+
]
43+
}
44+
45+
def compileO (name : String) (oFile srcFile : FilePath)
46+
(moreArgs : Array String := #[]) (compiler : FilePath := "cc") : BuildM Unit := do
47+
logStep s!"Compiling {name}"
48+
createParentDirs oFile
49+
proc {
50+
cmd := compiler.toString
51+
args := #["-c", "-o", oFile.toString, srcFile.toString] ++ moreArgs
52+
}
53+
54+
def compileStaticLib (name : String) (libFile : FilePath)
55+
(oFiles : Array FilePath) (ar : FilePath := "ar") : BuildM Unit := do
56+
logStep s!"Creating {name}"
57+
createParentDirs libFile
58+
proc {
59+
cmd := ar.toString
60+
args := #["rcs", libFile.toString] ++ oFiles.map toString
61+
}
62+
63+
def compileSharedLib (name : String) (libFile : FilePath)
64+
(linkArgs : Array String) (linker : FilePath := "cc") : BuildM Unit := do
65+
logStep s!"Linking {name}"
66+
createParentDirs libFile
67+
proc {
68+
cmd := linker.toString
69+
args := #["-shared", "-o", libFile.toString] ++ linkArgs
70+
}
71+
72+
def compileExe (name : String) (binFile : FilePath) (linkFiles : Array FilePath)
73+
(linkArgs : Array String := #[]) (linker : FilePath := "cc") : BuildM Unit := do
74+
logStep s!"Linking {name}"
75+
createParentDirs binFile
76+
proc {
77+
cmd := linker.toString
78+
args := #["-o", binFile.toString] ++ linkFiles.map toString ++ linkArgs
79+
}
80+
81+
/-- Download a file using `curl`, clobbering any existing file. -/
82+
def download (name : String) (url : String) (file : FilePath) : LogIO PUnit := do
83+
logInfo s!"Downloading {name}"
84+
if (← file.pathExists) then
85+
IO.FS.removeFile file
86+
else
87+
createParentDirs file
88+
let args :=
89+
if (← getIsVerbose) then #[] else #["-s"]
90+
proc (quiet := true) {
91+
cmd := "curl"
92+
args := args ++ #["-f", "-o", file.toString, "-L", url]
93+
}
94+
95+
/-- Unpack an archive `file` using `tar` into the directory `dir`. -/
96+
def untar (name : String) (file : FilePath) (dir : FilePath) (gzip := true) : LogIO PUnit := do
97+
logInfo s!"Unpacking {name}"
98+
let mut opts := "-x"
99+
if (← getIsVerbose) then
100+
opts := opts.push 'v'
101+
if gzip then
102+
opts := opts.push 'z'
103+
proc {
104+
cmd := "tar",
105+
args := #[opts, "-f", file.toString, "-C", dir.toString]
106+
}
107+
108+
/-- Pack a directory `dir` using `tar` into the archive `file`. -/
109+
def tar (name : String) (dir : FilePath) (file : FilePath)
110+
(gzip := true) (excludePaths : Array FilePath := #[]) : LogIO PUnit := do
111+
logInfo s!"Packing {name}"
112+
createParentDirs file
113+
let mut args := #["-c"]
114+
if gzip then
115+
args := args.push "-z"
116+
if (← getIsVerbose) then
117+
args := args.push "-v"
118+
for path in excludePaths do
119+
args := args.push s!"--exclude={path}"
120+
proc {
121+
cmd := "tar"
122+
args := args ++ #["-f", file.toString, "-C", dir.toString, "."]
123+
}

0 commit comments

Comments
 (0)