Skip to content

Commit

Permalink
feat(windows): powershell script w/ link flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner committed Jan 19, 2024
1 parent 9e920d3 commit f3450ec
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
- uses: crystal-lang/install-crystal@v1
- uses: ilammy/msvc-dev-cmd@v1
- name: Build LuaJIT for Windows
run: .\scripts\build_luajit.bat
run: .\scripts\build.ps1
- name: Run tests
run: crystal spec
run: crystal spec --link-flags="/LIBPATH:$(Get-Location)\ext\luajit"
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ LuaJIT bindings for Crystal

1. Install [LuaJIT](https://luajit.org)
- [Linux](https://www.google.com/search?q=install+luajit+linux)
- Install with package manager
- [Mac](https://www.google.com/search?q=install+luajit+mac)
- Install with brew
- `brew install luajit`
- [Windows](https://www.google.com/search?q=install+luajit+windows)
- Run `.\scripts\build_luajit.bat` to clone, build, and install LuaJIT library into `ext/` directory
- Execute `.\scripts\build.ps1`
- See output for `--link-flags`
- Add to crystal commands, e.g. `crystal run --link-flags="/LIBPATH:<absolute location to ext\luajit>" src/example.cr`

2. Add the dependency to your `shard.yml`:

Expand Down
45 changes: 45 additions & 0 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$ErrorActionPreference = "Stop"

# Save the current directory
$currentDir = Get-Location

# Define the LuaJIT extension directory
$luaExtDir = Join-Path -Path $currentDir -ChildPath "ext\luajit"

# Build LuaJIT unless $luaExtDir\lua51.lib exists
if (-not (Test-Path -Path "$luaExtDir\lua51.lib")) {
# Create a temporary directory
$luaDir = New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString())

# Clone LuaJIT
git clone https://github.com/LuaJIT/LuaJIT.git $luaDir

# Change directory to LuaJIT src
Set-Location -Path (Join-Path -Path $luaDir -ChildPath "src")

# Build LuaJIT (dynamic)
.\msvcbuild.bat
Rename-Item -Path lua51.lib -NewName lua51-dynamic.lib

# Build LuaJIT (static)
.\msvcbuild.bat static

# Copy files to $luaExtDir
$null = New-Item -ItemType Directory -Force -Path $luaExtDir
Copy-Item -Path lua51-dynamic.lib -Destination $luaExtDir
Copy-Item -Path lua51.dll -Destination $luaExtDir
Copy-Item -Path lua51.lib -Destination $luaExtDir

# Copy jit.* modules to $luaExtDir\lua\jit
$null = New-Item -ItemType Directory -Force -Path "$luaExtDir\lua"
Move-Item -Path jit -Destination "$luaExtDir\lua"

# Return to the original directory
Set-Location -Path $currentDir

# Remove the temporary directory
Remove-Item -Path $luaDir -Recurse -Force

Write-Output "Add the following to any crystal commands:"
Write-Output " --link-flags=/LIBPATH:$luaExtDir"
}
63 changes: 0 additions & 63 deletions scripts/build_luajit.bat

This file was deleted.

0 comments on commit f3450ec

Please sign in to comment.