Skip to content

Commit

Permalink
Download LuaJIT rolling release from git
Browse files Browse the repository at this point in the history
As requested by luajit.org: https://luajit.org/download.html
  • Loading branch information
hishamhm committed Aug 26, 2024
1 parent bcb9f8a commit 8ab3b21
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
81 changes: 39 additions & 42 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,26 @@ const VERSION_ALIASES = {
"5.2": "5.2.4",
"5.3": "5.3.6",
"5.4": "5.4.4",
"luajit": "luajit-2.1.0-beta3",
"luajit": "luajit-2.1",
}

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

const isMacOS = () => (process.platform || "").startsWith("darwin")
Expand Down Expand Up @@ -49,13 +68,26 @@ 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
}
}

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

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

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 +102,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, "luajit")
}

async function msvc_link(luaExtractPath, linkCmd, outFile, objs) {
Expand Down Expand Up @@ -231,13 +233,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

0 comments on commit 8ab3b21

Please sign in to comment.