test: add test of LLVM integration into lake

This commit is contained in:
Siddharth Bhat 2023-10-06 17:05:54 +01:00 committed by Sebastian Ullrich
parent 3b175fdb0e
commit 5980e665a8
8 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,3 @@
/build
/lakefile.olean
/lake-packages/*

View file

@ -0,0 +1,3 @@
-- This module serves as the root of the `LlvmBitcodeGen` library.
-- Import modules here that should be built as part of the library.
import «LlvmBitcodeGen».Basic

View file

@ -0,0 +1 @@
def hello := "world"

View file

@ -0,0 +1,7 @@
import «LlvmBitcodeGen»
import Lean
open Lean
def main : IO Unit :=
IO.println s!"LLVM backend enabled: '{Lean.Internal.hasLLVMBackend ()}'"

View file

@ -0,0 +1,3 @@
rm -rf build
rm -rf lakefile.olean
rm -rf lake-manifest.json

View file

@ -0,0 +1,4 @@
{"version": 6,
"packagesDir": "lake-packages",
"packages": [],
"name": "«llvm-bitcode-gen»"}

View file

@ -0,0 +1,24 @@
import Lake
import Lean
open Lean
open Lake DSL
package «llvm-bitcode-gen» where
-- add package configuration options here
backend := .llvm
lean_lib «LlvmBitcodeGen» where
-- add library configuration options here
@[default_target]
lean_exe «llvm-bitcode-gen» where
root := `Main
-- Enables the use of the Lean interpreter by the executable (e.g.,
-- `runFrontend`) at the expense of increased binary size on Linux.
-- Remove this line if you do not need such functionality.
supportInterpreter := true
script hasLLVMBackend do
IO.println s!"Lake Lean.Internal.hasLLVMBackend: {Lean.Internal.hasLLVMBackend ()}"
return 0

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euxo pipefail
LAKE=${LAKE:-../../build/bin/lake}
./clean.sh
# Skip test if we don't have LLVM backend in the Lean toolchain
if [[ ! $(lean --features) =~ LLVM ]]; then
echo "Skipping test: 'lean' does not have LLVM backend enabled"
exit 0
fi
$LAKE update
$LAKE build -v | grep "Main.bc.o" # check that we build using the bitcode object file.
# If we have the LLVM backend, check that the `lakefile.lean` is aware of this.
lake script run llvm-bitcode-gen/hasLLVMBackend | grep "true"
# If we have the LLVM backend in the Lean toolchain, then we expect this to
# print `true`, as this queries the same flag that Lake queries to check the presence
# of the LLVM toolchian.
./build/bin/llvm-bitcode-gen | grep 'true'
# If we have the LLVM backend, check that lake builds bitcode artefacts.
test -f build/ir/LlvmBitcodeGen.bc
test -f build/ir/Main.bc