mirror of
https://github.com/CompeyDev/lei.git
synced 2024-12-12 04:40:42 +00:00
feat(build): add cleanbuild system + a touch of color
This commit is contained in:
parent
9088f6188d
commit
efaccf57ad
1 changed files with 24 additions and 4 deletions
|
@ -5,6 +5,9 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const LUAU_VERSION = "0.634"
|
||||
|
@ -17,6 +20,8 @@ func bail(err error) {
|
|||
}
|
||||
|
||||
func buildVm(artifactPath string, cmakeFlags ...string) {
|
||||
color.Blue.Println("> Cloning luau-lang/luau")
|
||||
|
||||
dir, homeDirErr := os.MkdirTemp("", "lei-build")
|
||||
bail(homeDirErr)
|
||||
|
||||
|
@ -26,6 +31,10 @@ func buildVm(artifactPath string, cmakeFlags ...string) {
|
|||
Exec("git", "", "clone", "https://github.com/luau-lang/luau.git", dir)
|
||||
Exec("git", dir, "checkout", LUAU_VERSION)
|
||||
|
||||
color.Green.Printf("> Cloned repo to%s\n\n", dir)
|
||||
|
||||
color.Blue.Println("> Compile libLuau.VM.a")
|
||||
|
||||
// Build the Luau VM using CMake
|
||||
buildDir := path.Join(dir, "cmake")
|
||||
bail(os.Mkdir(buildDir, os.ModePerm))
|
||||
|
@ -34,9 +43,8 @@ func buildVm(artifactPath string, cmakeFlags ...string) {
|
|||
Exec("cmake", buildDir, append(defaultCmakeFlags, cmakeFlags...)...)
|
||||
Exec("cmake", buildDir, "--build", ".", "--target Luau.VM", "--config", "RelWithDebInfo")
|
||||
|
||||
// TODO: Write status file including version & build type (vector3 or vector4)
|
||||
// If current build type and version differ, then rebuild from scratch and
|
||||
// replace
|
||||
color.Green.Println("> Successfully compiled!\n")
|
||||
|
||||
// Copy the artifact to the artifact directory
|
||||
artifactFile, artifactErr := os.ReadFile(path.Join(buildDir, ARTIFACT_NAME))
|
||||
bail(artifactErr)
|
||||
|
@ -49,6 +57,7 @@ func main() {
|
|||
|
||||
artifactDir := path.Join(homeDir, ".lei")
|
||||
artifactPath := path.Join(artifactDir, ARTIFACT_NAME)
|
||||
lockfilePath := path.Join(artifactDir, ".lock")
|
||||
|
||||
bail(os.MkdirAll(artifactDir, os.ModePerm))
|
||||
|
||||
|
@ -62,16 +71,23 @@ func main() {
|
|||
for _, arg := range args {
|
||||
if arg == "--enable-vector4" {
|
||||
features = append(features, "LUAU_VECTOR4")
|
||||
// FIXME: This flag apparently isn't recognized by cmake for some reason
|
||||
cmakeFlags = append(cmakeFlags, "-DLUAU_VECTOR_SIZE=4")
|
||||
} else {
|
||||
goArgs = append(goArgs, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(artifactPath); err == nil {
|
||||
lockfileContents, err := os.ReadFile(lockfilePath)
|
||||
bail(err)
|
||||
|
||||
serFeatures := fmt.Sprintf("%v", features)
|
||||
toCleanBuild := string(lockfileContents) != serFeatures
|
||||
if _, err := os.Stat(artifactPath); err == nil && !toCleanBuild {
|
||||
fmt.Printf("[build] Using existing artifact at %s\n", artifactPath)
|
||||
} else {
|
||||
buildVm(artifactPath, cmakeFlags...)
|
||||
bail(os.WriteFile(lockfilePath, []byte(serFeatures), os.ModePerm))
|
||||
}
|
||||
|
||||
buildTags := []string{}
|
||||
|
@ -79,6 +95,10 @@ func main() {
|
|||
buildTags = append(buildTags, []string{"-tags", strings.Join(features, ",")}...)
|
||||
}
|
||||
|
||||
w, _, termErr := term.GetSize(int(os.Stdout.Fd()))
|
||||
bail(termErr)
|
||||
fmt.Println(strings.Repeat("=", w))
|
||||
|
||||
subcommand := goArgs[0]
|
||||
goArgs = goArgs[1:]
|
||||
combinedArgs := append(buildTags, goArgs...)
|
||||
|
|
Loading…
Reference in a new issue