test: add simple extension example
This commit is contained in:
parent
0d288b9bd3
commit
54bdf64d25
8 changed files with 51 additions and 0 deletions
1
examples/ext/.gitignore
vendored
Normal file
1
examples/ext/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
2
examples/ext/README.md
Normal file
2
examples/ext/README.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This example was adapted from Xubai Wong's [`simpleAdd`](https://github.com/xubaiw/lean-lake-build-script-demo/tree/758373277cb8615f9b9cb43025fa7d59d6b0badb/simpleAdd) Lake demo.
|
||||
Done with [permission](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/leanpkg.2B.2B.20idea.20.5BRFC.5D/near/246711345) from the author.
|
||||
1
examples/ext/clean.sh
Normal file
1
examples/ext/clean.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
rm -rf build
|
||||
5
examples/ext/ext/add.cpp
Normal file
5
examples/ext/ext/add.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include <stdint.h>
|
||||
|
||||
extern "C" uint32_t my_add(uint32_t a, uint32_t b) {
|
||||
return a + b;
|
||||
}
|
||||
5
examples/ext/lib/Add.lean
Normal file
5
examples/ext/lib/Add.lean
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
@[extern "my_add"]
|
||||
constant myAdd : UInt32 → UInt32 → UInt32
|
||||
|
||||
def main : IO Unit :=
|
||||
IO.println <| myAdd 1 2
|
||||
33
examples/ext/package.lean
Normal file
33
examples/ext/package.lean
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Lake.Build
|
||||
import Lake.Package
|
||||
open Lake System
|
||||
|
||||
def extDir : FilePath := "ext"
|
||||
def addSrc := extDir / "add.cpp"
|
||||
|
||||
def buildDir := defaultBuildDir
|
||||
def addO := buildDir / extDir / "add.o"
|
||||
def extLib := buildDir / extDir / "libext.a"
|
||||
|
||||
def fetchAddOTarget : IO FileTarget := do
|
||||
skipIfNewer addO (← getMTime addSrc) <|
|
||||
BuildTask.spawn <| compileO addO addSrc (cmd := "c++")
|
||||
|
||||
def fetchExtLibTarget : IO FileTarget := do
|
||||
let oTarget ← fetchAddOTarget
|
||||
skipIfNewer extLib oTarget.mtime <|
|
||||
oTarget >> compileStaticLib extLib #[addO]
|
||||
|
||||
def package : PackageConfig := {
|
||||
name := "ext"
|
||||
version := "0.1"
|
||||
-- customize layout
|
||||
srcDir := "lib"
|
||||
moduleRoot := `Add
|
||||
binName := "add"
|
||||
-- specify path to the lib for linker
|
||||
linkArgs := #[extLib.toString]
|
||||
-- specify the lib target as an additional dependency
|
||||
buildMoreDepsTarget := fetchExtLibTarget.map fun target =>
|
||||
LeanTarget.fromMTimeTarget <| target.discardArtifact
|
||||
}
|
||||
1
examples/ext/package.sh
Normal file
1
examples/ext/package.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
../../build/bin/Lake build-bin
|
||||
3
examples/ext/test.sh
Normal file
3
examples/ext/test.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
./clean.sh
|
||||
./package.sh
|
||||
./build/bin/add
|
||||
Loading…
Add table
Reference in a new issue