Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build LuaJIT rolling release from git #50

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ jobs:
strategy:
fail-fast: false
matrix:
luaVersion: ["5.1.5", "5.2.4", "5.3.6", "5.4.4", "luajit-2.0.5", "luajit-2.1.0-beta3", "luajit-openresty", "5.1", "5.4"]
luaVersion: ["5.1.5", "5.2.4", "5.3.6", "5.4.4", "luajit", "luajit-2.0", "luajit-2.1", "luajit-2.0.5", "luajit-2.1.0-beta3", "luajit-openresty", "5.1", "5.4"]
machineTag: ["ubuntu-latest", "macos-latest", "windows-latest"]
exclude:
- luaVersion: "luajit-2.0"
machineTag: "macos-latest"
- luaVersion: "luajit-2.0.5"
machineTag: "macos-latest"
- luaVersion: "luajit-2.0.5"
machineTag: "windows-latest"
- luaVersion: "luajit-2.1.0-beta3"
machineTag: "windows-latest"

runs-on: ${{ matrix.machineTag }}

Expand All @@ -32,8 +41,17 @@ jobs:
strategy:
fail-fast: false
matrix:
luaVersion: ["5.1.5", "5.2.4", "5.3.6", "5.4.4", "luajit-2.0.5", "luajit-2.1.0-beta3", "luajit-openresty", "5.1", "5.4"]
luaVersion: ["5.1.5", "5.2.4", "5.3.6", "5.4.4", "luajit", "luajit-2.0", "luajit-2.1", "luajit-2.0.5", "luajit-2.1.0-beta3", "luajit-openresty", "5.1", "5.4"]
machineTag: ["ubuntu-latest", "macos-latest", "windows-latest"]
exclude:
- luaVersion: "luajit-2.0"
machineTag: "macos-latest"
- luaVersion: "luajit-2.0.5"
machineTag: "macos-latest"
- luaVersion: "luajit-2.0.5"
machineTag: "windows-latest"
- luaVersion: "luajit-2.1.0-beta3"
machineTag: "windows-latest"

runs-on: ${{ matrix.machineTag }}

Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Github Action for Lua and LuaJIT

### `leafo/gh-actions-lua`
### `luarocks/gh-actions-lua`

[![Actions Status](https://github.com/leafo/gh-actions-lua/workflows/test/badge.svg)](https://github.com/leafo/gh-actions-lua/actions)
[![Actions Status](https://github.com/luarocks/gh-actions-lua/workflows/test/badge.svg)](https://github.com/luarocks/gh-actions-lua/actions)

**Note**: You must use version 8 or greater as GitHub has
deprecated older versions of the actions core libraries.
Expand All @@ -13,7 +13,7 @@ directly in workflows.

Other Lua GitHub actions:

* [`leafo/gh-actions-luarocks`](https://github.com/leafo/gh-actions-luarocks)
* [`luarocks/gh-actions-luarocks`](https://github.com/luarocks/gh-actions-luarocks)
* inputs: `luarocksVersion`


Expand All @@ -22,21 +22,21 @@ Other Lua GitHub actions:
Install Lua: (Will typically default to the latest release, 5.4.4 as of this readme)

```yaml
- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
```

Install specific version of Lua:

```yaml
- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
```

Install specific version of LuaJIT:

```yaml
- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: "luajit-2.1.0-beta3"
```
Expand All @@ -47,7 +47,7 @@ include this line on non-Windows platforms, as the action will do nothing in tho

```yaml
- uses: ilammy/msvc-dev-cmd@v1
- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
```

## Inputs
Expand All @@ -65,14 +65,15 @@ Examples of versions:
* `"5.2.4"`
* `"5.3.5"`
* `"5.4.1"`
* `"luajit-2.0.5"`
* `"luajit-2.1.0-beta3"`
* `"luajit-2.0"`
* `"luajit-2.1"`
* `"luajit-master"`
* `"luajit-openresty"`

The version specifies where the source is downloaded from:

* `luajit-openresty` — will allways pull master from https://github.com/openresty/luajit2
* Anything starting with `luajit-` — from http://luajit.org/download.html
* `luajit-openresty` — will always pull master from https://github.com/openresty/luajit2
* Anything else starting with `luajit-` — pulls a master or version branch from https://github.com/luajit/luajit
* Anything else — from https://www.lua.org/ftp/

**Version aliases**
Expand All @@ -89,7 +90,7 @@ Additional flags to pass to `make` when building Lua.
Example value:

```yaml
- uses: leafo/gh-actions-lua@master
- uses: luarocks/gh-actions-lua@master
with:
luaVersion: 5.3
luaCompileFlags: LUA_CFLAGS="-DLUA_INT_TYPE=LUA_INT_INT"
Expand All @@ -116,11 +117,11 @@ jobs:
steps:
- uses: actions/checkout@master

- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: "5.1.5"

- uses: leafo/gh-actions-luarocks@v4
- uses: luarocks/gh-actions-luarocks@v4

- name: build
run: |
Expand Down Expand Up @@ -153,7 +154,7 @@ jobs:

steps:
- uses: actions/checkout@master
- uses: leafo/gh-actions-lua@v10
- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: ${{ matrix.luaVersion }}

Expand Down
102 changes: 55 additions & 47 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,36 @@ const VERSION_ALIASES = {
"5.1": "5.1.5",
"5.2": "5.2.4",
"5.3": "5.3.6",
"5.4": "5.4.4",
"luajit": "luajit-2.1.0-beta3",
"5.4": "5.4.7",
"luajit": "luajit-2.1",
}

const LUAJIT_REPOS = {
"luajit-2.0": {
"url": "https://github.com/luajit/luajit.git",
"branch": "v2.0",
"binary": "luajit"
},
"luajit-2.1": {
"url": "https://github.com/luajit/luajit.git",
"branch": "v2.1",
"binary": "luajit"
},
"luajit-2.1.0-beta3": {
"url": "https://github.com/luajit/luajit.git",
"branch": "v2.1.0-beta3",
"binary": "luajit-2.1.0-beta3"
},
"luajit-master": {
"url": "https://github.com/luajit/luajit.git",
"branch": "master",
"binary": "luajit"
},
"luajit-openresty": {
"url": "https://github.com/openresty/luajit2.git",
"branch": "v2.1-agentzh",
"binary": "luajit"
},
}

const isMacOS = () => (process.platform || "").startsWith("darwin")
Expand All @@ -38,6 +66,7 @@ const processCwd = () => {
async function finish_luajit_install(src, dst, luajit) {
if (isWindows()) {
await fsp.copyFile(pathJoin(src, "lua51.dll"), pathJoin(dst, "bin", "lua51.dll"))
await fsp.copyFile(pathJoin(src, "lua51.dll"), pathJoin(dst, "lib", "lua51.dll"))

await exec.exec(`ln -s ${luajit} lua.exe`, undefined, {
cwd: pathJoin(dst, "bin")
Expand All @@ -49,13 +78,27 @@ async function finish_luajit_install(src, dst, luajit) {
}
}

async function install_luajit_openresty(luaInstallPath) {
async function install_luajit(luaInstallPath, luaVersion) {
const luajitVersion = luaVersion.substr("luajit-".length)

let repo = LUAJIT_REPOS[luaVersion];
if (!repo) {
repo = {
"url": LUAJIT_REPOS["luajit-master"].url,
"branch": "v" + luajitVersion,
"binary": "luajit"
}
}

const buildPath = path.join(process.env["RUNNER_TEMP"], BUILD_PREFIX)
const luaCompileFlags = core.getInput('luaCompileFlags')

// "luajit" or "luajit2"
const baseDir = repo.url.match(/.*\/(.*)\.git/)[1]

await io.mkdirP(buildPath)

await exec.exec("git clone https://github.com/openresty/luajit2.git", undefined, {
await exec.exec(`git clone --branch ${repo.branch} --single-branch ${repo.url}`, undefined, {
cwd: buildPath
})

Expand All @@ -70,45 +113,15 @@ async function install_luajit_openresty(luaInstallPath) {
}

await exec.exec(`make ${finalCompileFlags}`, undefined, {
cwd: pathJoin(buildPath, "luajit2"),
cwd: pathJoin(buildPath, baseDir),
...(isWindows() ? { env: { SHELL: 'cmd' }} : {})
})

await exec.exec(`make -j install PREFIX="${luaInstallPath}"`, undefined, {
cwd: pathJoin(buildPath, "luajit2")
cwd: pathJoin(buildPath, baseDir)
})

await finish_luajit_install(pathJoin(buildPath, "luajit2", "src"), luaInstallPath, "luajit")
}

async function install_luajit(luaInstallPath, luajitVersion) {
const luaExtractPath = pathJoin(process.env["RUNNER_TEMP"], BUILD_PREFIX, `LuaJIT-${luajitVersion}`)

const luaCompileFlags = core.getInput('luaCompileFlags')

const luaSourceTar = await tc.downloadTool(`https://luajit.org/download/LuaJIT-${luajitVersion}.tar.gz`)
await io.mkdirP(luaExtractPath)
await tc.extractTar(luaSourceTar, path.join(process.env["RUNNER_TEMP"], BUILD_PREFIX))

let finalCompileFlags = "-j"

if (isMacOS()) {
finalCompileFlags += " MACOSX_DEPLOYMENT_TARGET=10.15"
}

if (luaCompileFlags) {
finalCompileFlags += ` ${luaCompileFlags}`
}

await exec.exec(`make ${finalCompileFlags}`, undefined, {
cwd: luaExtractPath
})

await exec.exec(`make -j install PREFIX="${luaInstallPath}"`, undefined, {
cwd: luaExtractPath
})

await finish_luajit_install(pathJoin(luaExtractPath, "src"), luaInstallPath, `luajit-${luajitVersion}`)
await finish_luajit_install(pathJoin(buildPath, baseDir, "src"), luaInstallPath, repo.binary)
}

async function msvc_link(luaExtractPath, linkCmd, outFile, objs) {
Expand Down Expand Up @@ -173,21 +186,21 @@ async function install_plain_lua_windows(luaExtractPath, luaInstallPath, luaVers
}
})

objs["lua"] = [ ...objs["lua"], ...objs["lib"] ]
objs["luac"] = [ ...objs["luac"], ...objs["lib"] ]

let luaXYZ = luaVersion.split(".")
let libFile = "lua" + luaXYZ[0] + luaXYZ[1] + ".lib"
let dllFile = "lua" + luaXYZ[0] + luaXYZ[1] + ".dll"

objs["lua"] = [ ...objs["lua"], libFile ]
objs["luac"] = [ ...objs["luac"], ...objs["lib"] ]

await msvc_link(luaExtractPath, "link /nologo /DLL", dllFile, objs["lib"]);
await msvc_link(luaExtractPath, "link /nologo", "luac.exe", objs["luac"]);
await msvc_link(luaExtractPath, "link /nologo", "lua.exe", objs["lua"]);

const luaHpp = (await exists(pathJoin(src, "lua.hpp"))) ? "lua.hpp" : "../etc/lua.hpp"
const headers = [ "lua.h", "luaconf.h", "lualib.h", "lauxlib.h", luaHpp ]

await install_files(pathJoin(luaInstallPath, "bin"), luaExtractPath, [ "lua.exe", "luac.exe" ])
await install_files(pathJoin(luaInstallPath, "bin"), luaExtractPath, [ "lua.exe", "luac.exe", dllFile ])
await install_files(pathJoin(luaInstallPath, "lib"), luaExtractPath, [ dllFile, libFile ])
await install_files(pathJoin(luaInstallPath, "include"), src, headers)
}
Expand Down Expand Up @@ -231,13 +244,8 @@ async function install_plain_lua(luaInstallPath, luaVersion) {
}

async function install(luaInstallPath, luaVersion) {
if (luaVersion == "luajit-openresty") {
return await install_luajit_openresty(luaInstallPath)
}

if (luaVersion.startsWith("luajit-")) {
const luajitVersion = luaVersion.substr("luajit-".length)
return await install_luajit(luaInstallPath, luajitVersion)
return await install_luajit(luaInstallPath, luaVersion)
}

return await install_plain_lua(luaInstallPath, luaVersion)
Expand Down
Loading