Skip to content

Instantly share code, notes, and snippets.

@nopeless
Created October 10, 2023 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nopeless/de092edf3202a076e9ba40dbd39ffbf6 to your computer and use it in GitHub Desktop.
Save nopeless/de092edf3202a076e9ba40dbd39ffbf6 to your computer and use it in GitHub Desktop.
Simple Lua build script for Windows using MSVC
<#
Instructions:
Clone/download Lua source code from https://www.lua.org
Run this script from the root of the source code directory
You may need to install Visual Studio build tools with MSVC compiler
#>
Write-Host "Lua build script for Windows"
Write-Host "Copyright (c) 2023 nopeless"
Write-Host "Licensed under WTFPL"
Write-Host "Lua codebase by Lua.org, PUC-Rio"
Write-Host
Write-Host ("=" * 80)
$ErrorActionPreference = "Stop"
# ==== enough rambling ====
$cl = (Get-Command "cl.exe" -ErrorAction SilentlyContinue)
if (-not $cl) { $cl = $Env:MSVC_CL } else { $cl = $cl.source }
$outfile = Join-Path $pwd "lua.exe"
if (-not $cl) {
Write-Host -ForegroundColor Red "ERR: cl.exe not found, please install Visual Studio build tools with MSVC compiler"
Write-Host "If you have it installed, either
- set `$Env:MSVC_CL to the path of cl.exe (current value: $Env:MSVC_CL)
- add cl.exe directory to PATH
- or run this script from the Developer Command Prompt for VS"
exit 1
}
Write-Host "Using cl.exe at $cl"
Write-Host "Output file: $outfile"
# ==== build ====
Write-Host "Clearing temp directory"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "temp"
New-Item -ItemType Directory -Path "temp" > $null
Write-Host "Copying source files"
Copy-Item -Path "*.[ch]" -Destination "temp"
# This file is just a merged file
Write-Host "Deleting temp\onelua.c"
Remove-Item -Path "temp\onelua.c"
Write-Host "Compiling using /O2 /favor:AMD64"
Write-Host "Logs are in temp/cl-compile.log"
try {
Set-Location temp
& $cl *.c /Fe:$outfile /O2 /favor:AMD64 > cl-compile.log
}
catch {
Write-Host -ForegroundColor Red "ERR: cl.exe failed to compile"
Write-Host "Check temp/cl-compile.log for more info"
exit 1
}
finally {
Set-Location ..
}
Write-Host "Testing lua.exe"
& $outfile -v | Write-Host
& $outfile -e "print('Hello,' .. ' world!')" | Write-Host
Write-Host "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment