Skip to content

Commit 2273e51

Browse files
atticusofspartadtfiedler
authored andcommitted
fix(lua): cross platform install script for lua
1 parent e3863a5 commit 2273e51

File tree

5 files changed

+160
-30
lines changed

5 files changed

+160
-30
lines changed

.busted

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ return {
44
default = {
55
root = "src",
66
pattern = "**/*_spec.lua$",
7+
exclude = {
8+
"**/luarocks-3.9.1/**",
9+
"**/lua-5.3.1/**"
10+
},
711
helper = "spec/setup.lua",
812
verbose = true,
913
coverage = true,

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ process.wasm
1616
dist
1717
publish-output.json
1818
luarocks-3.9.1
19+
lua-5.3.1
1920
temp-build
2021
build
2122
aos-process

README.md

+5-30
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ This repository provides two flavours of ANT process module, AOS and a custom mo
4040
- [Developers](#developers)
4141
- [Requirements](#requirements)
4242
- [Lua Setup (MacOS)](#lua-setup-macos)
43-
- [LuaRocks Setup](#luarocks-setup)
4443
- [aos](#aos)
4544
- [Code Formatting](#code-formatting)
4645
- [Testing](#testing-1)
@@ -320,35 +319,11 @@ Calls the IO Network process to reassign the given ArNS name to a new ANT ID if
320319
### Lua Setup (MacOS)
321320

322321
1. Clone the repository and navigate to the project directory.
323-
1. Install `lua`
324-
- `brew install [email protected]`
325-
1. Add the following to your `.zshrc` or `.bashrc` file:
326-
327-
```bash
328-
echo 'export LDFLAGS="-L/usr/local/opt/[email protected]/lib"' >> ~/.zshrc
329-
echo 'export CPPFLAGS="-I/usr/local/opt/[email protected]/include"' >> ~/.zshrc
330-
echo 'export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"' >> ~/.zshrc
331-
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
332-
```
333-
334-
1. Run `source ~/.zshrc` or `source ~/.bashrc` to apply the changes.
335-
1. Run `lua -v` to verify the installation.
336-
337-
### LuaRocks Setup
338-
339-
1. Install `luarocks`
340-
341-
```bash
342-
curl -R -O http://luarocks.github.io/luarocks/releases/luarocks-3.9.1.tar.gz
343-
tar zxpf luarocks-3.9.1.tar.gz
344-
cd luarocks-3.9.1
345-
./configure --with-lua=/usr/local/opt/[email protected] --with-lua-include=/usr/local/opt/[email protected]/include
346-
make build
347-
sudo make install
348-
```
349-
350-
1. Check the installation by running `luarocks --version`.
351-
1. Check the LuaRocks configuration by running `luarocks config | grep LUA`
322+
2. run the following:
323+
324+
```shell
325+
yarn install-lua-deps
326+
```
352327

353328
If you ever need to refresh .luarocks, run the following command:
354329

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"aos:load": "node tools/bundle-aos.mjs && node tools/load-aos.mjs",
1313
"aos:spawn": "node tools/spawn-aos.mjs",
1414
"test": "yarn aos:build && node --test --test-concurrency 1 --experimental-wasm-memory64 **/*.test.mjs",
15+
"install-lua-deps": "sh tools/install-lua-deps.sh && luarocks install ar-io-ao-0.1-1.rockspec",
1516
"prepare": "husky"
1617
},
1718
"devDependencies": {

tools/install-lua-deps.sh

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/bash
2+
3+
# Exit on error and enable debug mode
4+
set -e
5+
set -x
6+
7+
# Detect operating system
8+
OS=$(uname -s)
9+
10+
# Lua and LuaRocks versions
11+
LUA_VERSION="5.3.1"
12+
LUAROCKS_VERSION="3.9.1"
13+
14+
install_dependencies() {
15+
case "$OS" in
16+
Darwin*)
17+
echo "Installing dependencies on macOS..."
18+
if ! command -v brew &> /dev/null; then
19+
echo "Homebrew not found. Installing Homebrew..."
20+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
21+
fi
22+
brew install gcc make curl readline
23+
;;
24+
Linux*)
25+
echo "Installing dependencies on Linux..."
26+
if command -v apt-get &> /dev/null; then
27+
echo "Using apt-get to install dependencies..."
28+
sudo dpkg --remove-architecture i386 || true
29+
sudo apt-get update
30+
sudo apt-get install -y build-essential curl libreadline-dev
31+
elif command -v yum &> /dev/null; then
32+
echo "Using yum to install dependencies..."
33+
sudo yum groupinstall -y "Development Tools"
34+
sudo yum install -y curl readline-devel
35+
else
36+
echo "Unsupported Linux package manager. Please install build tools and curl manually."
37+
exit 1
38+
fi
39+
;;
40+
*)
41+
echo "Unsupported operating system: $OS"
42+
exit 1
43+
;;
44+
esac
45+
}
46+
47+
# Function to download with retry
48+
download_with_retry() {
49+
local url="$1"
50+
local output="$2"
51+
local max_attempts=3
52+
local attempt=1
53+
54+
while [ $attempt -le $max_attempts ]; do
55+
echo "Downloading $url (Attempt $attempt)..."
56+
if curl -L -o "$output" "$url"; then
57+
return 0
58+
fi
59+
attempt=$((attempt + 1))
60+
sleep 2
61+
done
62+
63+
echo "Failed to download $url after $max_attempts attempts"
64+
exit 1
65+
}
66+
67+
# Function to install Lua
68+
install_lua() {
69+
echo "Installing Lua $LUA_VERSION..."
70+
71+
# Download Lua
72+
download_with_retry "https://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz" "lua-${LUA_VERSION}.tar.gz"
73+
74+
# Extract and build
75+
tar -xzf "lua-${LUA_VERSION}.tar.gz"
76+
cd "lua-${LUA_VERSION}"
77+
78+
case "$OS" in
79+
Darwin*)
80+
make macosx
81+
sudo make install
82+
;;
83+
Linux*)
84+
make linux
85+
sudo make install
86+
;;
87+
esac
88+
89+
cd ..
90+
rm -rf "lua-${LUA_VERSION}" "lua-${LUA_VERSION}.tar.gz"
91+
echo "Lua $LUA_VERSION installed successfully."
92+
}
93+
94+
# Function to install LuaRocks
95+
install_luarocks() {
96+
echo "Installing LuaRocks $LUAROCKS_VERSION..."
97+
98+
# Download LuaRocks
99+
download_with_retry "https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz" "luarocks-${LUAROCKS_VERSION}.tar.gz"
100+
101+
# Extract and configure
102+
tar -xzf "luarocks-${LUAROCKS_VERSION}.tar.gz"
103+
cd "luarocks-${LUAROCKS_VERSION}"
104+
105+
./configure --with-lua=/usr/local --with-lua-include=/usr/local/include
106+
make build
107+
sudo make install
108+
109+
cd ..
110+
rm -rf "luarocks-${LUAROCKS_VERSION}" "luarocks-${LUAROCKS_VERSION}.tar.gz"
111+
echo "LuaRocks $LUAROCKS_VERSION installed successfully."
112+
}
113+
114+
# Function to check if Lua is installed
115+
is_lua_installed() {
116+
command -v lua &> /dev/null && lua -v 2>&1 | grep -q "${LUA_VERSION}"
117+
}
118+
119+
# Function to check if LuaRocks is installed
120+
is_luarocks_installed() {
121+
command -v luarocks &> /dev/null && luarocks --version 2>&1 | grep -q "${LUAROCKS_VERSION}"
122+
}
123+
124+
# Main function
125+
main() {
126+
echo "Starting installation process..."
127+
128+
# Install dependencies
129+
install_dependencies
130+
131+
# Install Lua if not already installed
132+
if ! is_lua_installed; then
133+
install_lua
134+
else
135+
echo "Lua $LUA_VERSION is already installed."
136+
fi
137+
138+
# Install LuaRocks if not already installed
139+
if ! is_luarocks_installed; then
140+
install_luarocks
141+
else
142+
echo "LuaRocks $LUAROCKS_VERSION is already installed."
143+
fi
144+
145+
echo "All installations completed successfully!"
146+
}
147+
148+
# Run the main function
149+
main

0 commit comments

Comments
 (0)