Skip to content

Instantly share code, notes, and snippets.

@mjstephan
Forked from zirkuswurstikus/lua_build_macos.sh
Created April 28, 2025 14:24
Show Gist options
  • Select an option

  • Save mjstephan/c6204b5a24c19e5bd992091e289043d2 to your computer and use it in GitHub Desktop.

Select an option

Save mjstephan/c6204b5a24c19e5bd992091e289043d2 to your computer and use it in GitHub Desktop.

Revisions

  1. @zirkuswurstikus zirkuswurstikus revised this gist Jul 15, 2024. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions lua_build_macos.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Build & install Lua on macOS

    # We will compile Lua 5.1 because it is compatible with openresty/lapis.
    # Replace the variables from line 30 ff to install a diffrent version.

    # See: https://www.lua.org/manual/5.1/

    @@ -25,11 +26,11 @@ softwareupdate --install --all
    ## Create Lua Directory

    # Where to install lua, luajit, luarocks ..?
    LUA=~/devop/lua/
    LUA=~/devop/lua
    mkdir -p $LUA

    ## Download and Extract Lua Sources
    cd /tmp
    cd /tmp
    wget https://www.lua.org/ftp/lua-5.1.5.tar.gz

    # Optional: Check hash
    @@ -48,7 +49,7 @@ make macosx
    make test && make install

    ## Optional: Update environment variables
    # We place the Lua related variabls in a dedicated file and sourc it.
    # We place the Lua related variabls in a dedicated file and source it.

    echo 'export PATH=${LUA}bin:$PATH' >> ${LUA}/.profile
    echo "export LUA_CPATH=${LUA}lib/lua/5.1/?.so" >> ${LUA}/.profile
    @@ -77,7 +78,7 @@ tar xvf luarocks-3.9.1.tar.gz
    cd luarocks-3.9.1/

    # Configure and install LuaRocks
    ./configure --prefix=${LUA} --with-lua=${LUA} --lua-suffix=5.1 --with-lua-include=${LUA}include
    ./configure --prefix=${LUA} --with-lua=${LUA} --lua-suffix=5.1 --with-lua-include=${LUA}/include
    make build && make install

    # Verify LuaRocks installation
    @@ -86,7 +87,7 @@ luarocks --version

    ### Build and Install LuaJIT

    # Create a git folder in the Lua directory
    # Create a git folder in the Lua directory to keep things together (optional)
    mkdir $LUA/git
    cd $LUA/git

    @@ -111,7 +112,7 @@ luajit -v
    echo 'external_deps_dirs = { "/opt/homebrew" }' >> ${LUA}/etc/luarocks/config-5.1.lua

    ## Install LuaSec rock (optional to test luarocks)
    # Ensure OpenSSL is installed via Homebrew for example
    # Ensure OpenSSL is installed - for example via Homebrew
    # brew install openssl
    # you may adjust the path to libs
    luarocks --local install luasec \
  2. @zirkuswurstikus zirkuswurstikus revised this gist May 28, 2024. 1 changed file with 18 additions and 15 deletions.
    33 changes: 18 additions & 15 deletions lua_build_macos.sh
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,35 @@
    # Install Lua on macOS

    # see a recording at https://asciinema.org/a/436ETWqckvdkjrHolTJ2YSzqw
    # Build & install Lua on macOS

    # We will compile Lua 5.1 because it is compatible with openresty/lapis.

    # See: https://www.lua.org/manual/5.4/readme.html
    # See: https://www.lua.org/manual/5.1/

    # NOTE: We create a dedicated directory for the Lua stuff.
    # NOTE:
    # We create a dedicated directory for the Lua stuff to putt all the stuff in.

    # TIP:
    # see a recording at https://asciinema.org/a/436ETWqckvdkjrHolTJ2YSzqw

    ## Check CPU Brand
    ## Tested on ...

    sysctl -n machdep.cpu.brand_string
    # Output: Apple M1
    sysctl -n machdep.cpu.brand_string # Apple M1
    sw_vers -productName # macOS
    sw_vers -productVersion # 14.5

    ## Install Build Tools
    ## Install build tools

    xcode-select --install
    # Optional: Update all software
    softwareupdate --install --all

    ## Create Lua Directory

    # Where to install lua, luajit, luarocks ...
    # Where to install lua, luajit, luarocks ..?
    LUA=~/devop/lua/

    mkdir -p $LUA
    cd /tmp

    ## Download and Extract Lua Sources

    cd /tmp
    wget https://www.lua.org/ftp/lua-5.1.5.tar.gz

    # Optional: Check hash
    @@ -46,7 +47,8 @@ sed -i '' "s#/usr/local#${LUA}/#g" Makefile
    make macosx
    make test && make install

    ## Update environment variables
    ## Optional: Update environment variables
    # We place the Lua related variabls in a dedicated file and sourc it.

    echo 'export PATH=${LUA}bin:$PATH' >> ${LUA}/.profile
    echo "export LUA_CPATH=${LUA}lib/lua/5.1/?.so" >> ${LUA}/.profile
    @@ -65,7 +67,7 @@ lua -v
    file ${LUA}/bin/lua
    # Expected Output: ... Mach-O 64-bit executable arm64

    ### Build and Install LuaRocks
    ### Build and install LuaRocks

    cd /tmp
    wget https://luarocks.org/releases/luarocks-3.9.1.tar.gz
    @@ -115,3 +117,4 @@ echo 'external_deps_dirs = { "/opt/homebrew" }' >> ${LUA}/etc/luarocks/config-5.
    luarocks --local install luasec \
    OPENSSL_INCDIR=/opt/homebrew/Cellar/openssl@3/3.3.0/include/ \
    OPENSSL_LIBDIR=/opt/homebrew/Cellar/openssl@3/3.3.0/lib

  3. @zirkuswurstikus zirkuswurstikus renamed this gist May 28, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @zirkuswurstikus zirkuswurstikus renamed this gist May 28, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @zirkuswurstikus zirkuswurstikus revised this gist May 27, 2024. No changes.
  6. @zirkuswurstikus zirkuswurstikus revised this gist May 27, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Lua_Build_Install_MacOS.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Install Lua on macOS

    # see a recording at https://asciinema.org/a/436ETWqckvdkjrHolTJ2YSzqw

    # We will compile Lua 5.1 because it is compatible with openresty/lapis.

    # See: https://www.lua.org/manual/5.4/readme.html
  7. @zirkuswurstikus zirkuswurstikus renamed this gist May 27, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @zirkuswurstikus zirkuswurstikus created this gist May 27, 2024.
    115 changes: 115 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    # Install Lua on macOS

    # We will compile Lua 5.1 because it is compatible with openresty/lapis.

    # See: https://www.lua.org/manual/5.4/readme.html

    # NOTE: We create a dedicated directory for the Lua stuff.

    ## Check CPU Brand

    sysctl -n machdep.cpu.brand_string
    # Output: Apple M1

    ## Install Build Tools

    xcode-select --install
    # Optional: Update all software
    softwareupdate --install --all

    ## Create Lua Directory

    # Where to install lua, luajit, luarocks ...
    LUA=~/devop/lua/

    mkdir -p $LUA
    cd /tmp

    ## Download and Extract Lua Sources

    wget https://www.lua.org/ftp/lua-5.1.5.tar.gz

    # Optional: Check hash
    shasum -a 256 lua-5.1.5.tar.gz | grep -q '2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333' \
    && echo "Hash matches" || echo "Hash does not match"

    tar xvf lua-5.1.5.tar.gz
    cd lua-5.1.5/

    ## Modify Makefile to set destination dir

    sed -i '' "s#/usr/local#${LUA}/#g" Makefile

    ## Compile and install Lua
    make macosx
    make test && make install

    ## Update environment variables

    echo 'export PATH=${LUA}bin:$PATH' >> ${LUA}/.profile
    echo "export LUA_CPATH=${LUA}lib/lua/5.1/?.so" >> ${LUA}/.profile
    echo "export LUA_PATH=${LUA}share/lua/5.1/?.lua;;" >> ${LUA}/.profile
    echo "export MANPATH=${LUA}share/man:\$MANPATH" >> ${LUA}/.profile
    echo 'source ${LUA}/.profile' >> ~/.bashrc
    echo 'source ${LUA}/.profile' >> ~/.zshrc

    source ${LUA}/.profile

    ### Verify Lua Installation

    which lua
    lua -v
    # Expected Output: Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
    file ${LUA}/bin/lua
    # Expected Output: ... Mach-O 64-bit executable arm64

    ### Build and Install LuaRocks

    cd /tmp
    wget https://luarocks.org/releases/luarocks-3.9.1.tar.gz

    # Extract and enter the directory
    tar xvf luarocks-3.9.1.tar.gz
    cd luarocks-3.9.1/

    # Configure and install LuaRocks
    ./configure --prefix=${LUA} --with-lua=${LUA} --lua-suffix=5.1 --with-lua-include=${LUA}include
    make build && make install

    # Verify LuaRocks installation
    lua -v
    luarocks --version

    ### Build and Install LuaJIT

    # Create a git folder in the Lua directory
    mkdir $LUA/git
    cd $LUA/git

    # Clone the LuaJIT repository
    git clone https://luajit.org/git/luajit.git
    cd luajit

    # Get macOS version and set MACOSX_DEPLOYMENT_TARGET
    MACOS_VERSION=$(sw_vers -productVersion)
    MACOSX_DEPLOYMENT_TARGET=${MACOS_VERSION%.*}

    # Compile and install LuaJIT
    MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} make
    MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} make install PREFIX=${LUA}

    source ${LUA}/.profile
    luajit -v

    ### Install LuaSec for Testing

    # Add external dependencies directory to LuaRocks config
    echo 'external_deps_dirs = { "/opt/homebrew" }' >> ${LUA}/etc/luarocks/config-5.1.lua

    ## Install LuaSec rock (optional to test luarocks)
    # Ensure OpenSSL is installed via Homebrew for example
    # brew install openssl
    # you may adjust the path to libs
    luarocks --local install luasec \
    OPENSSL_INCDIR=/opt/homebrew/Cellar/openssl@3/3.3.0/include/ \
    OPENSSL_LIBDIR=/opt/homebrew/Cellar/openssl@3/3.3.0/lib