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

WIP PR for LuaJIT support #7

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
71 changes: 44 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,54 @@ name: test
on: [push]

jobs:
test:
# test:
# strategy:
# matrix:
# luaVersion: ["5.1.5", "5.2.4", "5.3.5"]
# os: [macOs-latest, ubuntu-latest]

# runs-on: ${{ matrix.os }}

# steps:
# - uses: actions/checkout@master
# - uses: ./
# with:
# lua-version: ${{ matrix.luaVersion }}

# - name: test lua
# run: |
# which lua
# lua -e "print(_VERSION)"
# windows:
# runs-on: windows-latest
# strategy:
# matrix:
# luaVersion: ["5.1.5", "5.2.4", "5.3.5"]
# platform: [Win32, x64]
# steps:
# - uses: actions/checkout@master
# - uses: ./
# with:
# lua-version: ${{ matrix.luaVersion }}
# platform: ${{ matrix.platform }}
# - name: test lua
# run: |
# which lua
# lua -e "print(_VERSION)"
lua-jit:
strategy:
matrix:
luaVersion: ["5.1.5", "5.2.4", "5.3.5"]
luaVersion: ["luajit-2.0.5", "luajit-2.1.0-beta3"]
os: [macOs-latest, ubuntu-latest]

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

steps:
- uses: actions/checkout@master
- uses: ./
with:
lua-version: ${{ matrix.luaVersion }}
- uses: actions/checkout@master
- uses: ./
with:
lua-version: ${{ matrix.luaVersion }}

- name: test lua
run: |
which lua
lua -e "print(_VERSION)"
windows:
runs-on: windows-latest
strategy:
matrix:
luaVersion: ["5.1.5", "5.2.4", "5.3.5"]
platform: [Win32, x64]
steps:
- uses: actions/checkout@master
- uses: ./
with:
lua-version: ${{ matrix.luaVersion }}
platform: ${{ matrix.platform }}
- name: test lua
run: |
which lua
lua -e "print(_VERSION)"
- name: test lua
run: |
which luajit
luajit -e "print(_VERSION)"
71 changes: 67 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ const exec = require("@actions/exec")
const io = require("@actions/io")
const tc = require("@actions/tool-cache")



process.env["DEBUG"] = process.env["DEBUG"] || "setup-lua"
const debug = require("debug")("setup-lua")
const path = require("path")
const fs = require("fs")
const md5File = require('md5-file')
const os = require("os")

const SOURCE_DIRECTORY = path.join(process.cwd(), ".source/")
const INSTALL_PREFIX = path.join(process.cwd(), ".lua/")
Expand Down Expand Up @@ -93,15 +98,19 @@ function mergeDirectory(source, dest) {
}

function getTarball(version) {
debug("getTarball %s", version)
const v = VERSION_ALIASES[version] || version
debug("maybe aliased version %s", v || "v is undefined...")
if (!TARBALLS[v] || TARBALLS[v].length != 2) {
throw RangeError("Unsupported lua version: " + version)
}
return [TARBALLS[v][1], TARBALLS[v][0]]
}

function getLuaVersion() {
debug("getLuaVersion")
const luaVersion = core.getInput('lua-version', { required: false })
debug("version from input %s", luaVersion)
return VERSION_ALIASES[luaVersion] || luaVersion || "5.1.5"
}

Expand All @@ -111,6 +120,7 @@ function getPlatform() {
}

async function download(url, hash) {
debug("download url: %s, hash: %s", url, hash)
const luaSourceTar = await tc.downloadTool(url)
if (hash != md5File.sync(luaSourceTar)) {
throw Error("MD5 mismatch, please check your network.");
Expand All @@ -119,30 +129,39 @@ async function download(url, hash) {
}

function tarballContentDirectory(version) {
debug("tarballContentDirectory %s", version)
if (version.startsWith("luajit")) {
const luajitVersion = luaVersion.substr("luajit-".length)
const luajitVersion = version.substr("luajit-".length)
debug("LuaJIT version: %s", luajitVersion)
return `LuaJIT-${luajitVersion}`
}
return `lua-${version}`
}

async function extractTarball(tarball, version) {
debug("extractTarball %s", version)
await io.mkdirP(SOURCE_DIRECTORY)
debug("made source directory")
await exec.exec(`cmake -E tar xzf "${tarball}"`, undefined, {
cwd: SOURCE_DIRECTORY
})
debug("executed cmake -E tar xzf")
showDirectory(SOURCE_DIRECTORY)
const dir = tarballContentDirectory(version)
debug("tarball content directory: %s", dir)
return path.join(SOURCE_DIRECTORY, dir)
}

async function downloadSource(luaVersion) {
debug("downloadSource %s", luaVersion)
const [url, hash] = getTarball(luaVersion)
debug("tarball url: %s, hash: %s", url, hash)
const tarball = await download(url, hash)
return extractTarball(tarball, luaVersion)
}

async function installSystemDependencies() {
debug("installSystemDependencies")
if (process.platform == "linux") {
return await exec.exec("sudo apt-get install -q libreadline-dev libncurses-dev", undefined, {
env: {
Expand All @@ -163,22 +182,61 @@ async function installSystemDependencies() {
}

async function addCMakeBuildScripts(sourcePath, luaVersion) {
debug("addCMakeBuildScripts %s, %s", sourcePath, luaVersion)
fs.unlinkSync(path.join(sourcePath, "src", "luaconf.h"))
debug("removed luaconf.h")
mergeDirectory(path.join(__dirname, "patch", "shared"), sourcePath)
const v = luaVersion.replace(/\.\d*$/,'')
debug("merged patch/shared with %s", sourcePath)
const v = luaVersion.replace(/\.\d*(-beta\d+)?$/,'')
debug("v: %s", v)
mergeDirectory(path.join(__dirname, "patch", "lua", v), sourcePath)
console.log("VERSION: " + v)
showDirectory(sourcePath)
}

async function buildAndInstall(sourcePath, platform) {
debug("buildAndInstall %s, %s", sourcePath, platform)
await buildAndInstallLua5(sourcePath, platform)
// if (/jit/i.test(sourcePath)) {
// await buildAndInstallLuaJIT(sourcePath, platform)
// } else {
// }
core.addPath(path.join(INSTALL_PREFIX, "bin"));
}

async function buildAndInstallLuaJIT(sourcePath) {
debug("buildAndInstallLuaJIT %s", sourcePath)
let env
if (process.platform == "darwin") {
env = {
MACOSX_DEPLOYMENT_TARGET: os.release().split('.').slice(0, 2).map(n => `0${n}`.substr(-2)).join('.'),
}
}
await exec.exec(`make PREFIX=${INSTALL_PREFIX}`, undefined, { cwd: sourcePath, env })
await exec.exec("sudo -E make install", undefined, { cwd: sourcePath })
if (/beta/i.test(sourcePath)) {
let version = path.parse(sourcePath).base
if (!version) {
throw new Error(`Unable to determine full beta binary name from source path: ${sourcePath}`)
}
await exec.exec("sudo -E ln -sf luajit-2.1.0-beta3 /usr/local/bin/luajit")
}
}

async function buildAndInstallLua5(sourcePath, platform) {
debug("buildAndInstallLua5 %s, %s", sourcePath, platform)
if(platform){
await exec.exec(`cmake -H"${sourcePath}" -Bbuild -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -A${platform}`, undefined, {
cwd: sourcePath
})
}
else{
let env
if (process.platform == "darwin" && /jit/i.test(sourcePath)) {
env = {
MACOSX_DEPLOYMENT_TARGET: os.release().split('.').slice(0, 2).map(n => `0${n}`.substr(-2)).join('.'),
}
}
await exec.exec(`cmake -H"${sourcePath}" -Bbuild -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}`, undefined, {
cwd: sourcePath
})
Expand All @@ -187,17 +245,22 @@ async function buildAndInstall(sourcePath, platform) {
await exec.exec(`cmake --build build --config Release --target install`, undefined, {
cwd: sourcePath
})

core.addPath(path.join(INSTALL_PREFIX, "bin"));
}

async function main() {
debug("main")
await installSystemDependencies()
debug("System dependencies installed")
const luaVersion = getLuaVersion()
debug("Got lua version: %s", luaVersion)
const platform = getPlatform();
debug("Got Platform: %s", platform)
const sourcePath = await downloadSource(luaVersion)
debug("Downloaded to: %s", sourcePath)
await addCMakeBuildScripts(sourcePath, luaVersion)
debug("Added cmake build scripts")
await buildAndInstall(sourcePath, platform)
debug("built and installed")
}

main().catch(err => {
Expand Down
19 changes: 19 additions & 0 deletions node_modules/debug/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading