├── .commitlintrc.json
├── .github
└── workflows
│ ├── commitlint.yml
│ ├── package.yml
│ ├── release.yml
│ └── reusable-package.yml
├── .gitignore
├── Build-Lua.ps1
├── CMakeLists.txt
├── Install-Lua.ps1
├── LICENSE.txt
├── README.md
└── WixPatch.xml
/.commitlintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "header-max-length": [
4 | 2,
5 | "always",
6 | 72
7 | ],
8 | "type-enum": [
9 | 2,
10 | "always",
11 | [
12 | "docs",
13 | "feat",
14 | "fix",
15 | "refactor",
16 | "revert",
17 | "style",
18 | "test"
19 | ]
20 | ],
21 | "type-empty": [
22 | 2,
23 | "never"
24 | ]
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.github/workflows/commitlint.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on: [push, pull_request]
3 | jobs:
4 | commitlint:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - uses: actions/checkout@v3
8 | with:
9 | fetch-depth: 0
10 | - name: Install commitlint
11 | run: |
12 | npm install conventional-changelog-conventionalcommits
13 | npm install commitlint@latest
14 | - name: Print versions
15 | run: |
16 | git --version
17 | node --version
18 | npm --version
19 | npx commitlint --version
20 | - name: Validate current commit (last commit) with commitlint
21 | if: github.event_name == 'push'
22 | run: npx commitlint --from HEAD~1 --to HEAD --verbose
23 | - name: Validate PR commits with commitlint
24 | if: github.event_name == 'pull_request'
25 | run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose
--------------------------------------------------------------------------------
/.github/workflows/package.yml:
--------------------------------------------------------------------------------
1 | name: Package
2 | on:
3 | push:
4 | branches:
5 | - 'main'
6 | jobs:
7 | package:
8 | uses: ./.github/workflows/reusable-package.yml
9 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | workflow_dispatch:
4 | inputs:
5 | tag:
6 | description: 'Release tag'
7 | required: true
8 | type: string
9 | jobs:
10 | package:
11 | uses: ./.github/workflows/reusable-package.yml
12 | release:
13 | needs: package
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 | - uses: actions/download-artifact@v3
18 | - run: |
19 | gh release create "${TAG}" --notes "Lua ${TAG}" ./build/*.msi ./build/*.zip
20 | env:
21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 | TAG: ${{ inputs.tag }}
23 |
--------------------------------------------------------------------------------
/.github/workflows/reusable-package.yml:
--------------------------------------------------------------------------------
1 | name: Reusable package
2 | on:
3 | workflow_call:
4 | jobs:
5 | package:
6 | runs-on: windows-latest
7 | steps:
8 | - uses: actions/checkout@v3
9 | - name: Install required tools
10 | run: choco install ninja ghostscript
11 | - name: Generate Ninja build
12 | run: cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_C_COMPILER=clang
13 | - name: Package
14 | run: cmake --build build --target package
15 | - uses: actions/upload-artifact@v3
16 | with:
17 | name: build
18 | path: |
19 | build/*.msi
20 | build/*.zip
21 | if-no-files-found: error
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | CMakeLists.txt.user
2 | CMakeCache.txt
3 | CMakeFiles
4 | CMakeScripts
5 | Testing
6 | Makefile
7 | cmake_install.cmake
8 | install_manifest.txt
9 | compile_commands.json
10 | CTestTestfile.cmake
11 | _deps
12 |
13 | build/
14 | install/
15 | lua-*/
16 | luarocks-*/
17 | *.gz
18 | *.zip
19 | lua-logo-nolabel.ps
20 |
--------------------------------------------------------------------------------
/Build-Lua.ps1:
--------------------------------------------------------------------------------
1 | $ErrorActionPreference = 'Stop'
2 |
3 | if (Test-Path -Path build -PathType Container)
4 | {
5 | Remove-Item -Recurse -Force -Path build
6 | }
7 | cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo
8 | cmake --build build --target package
9 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.26)
2 | set(LUA_VERSION 5.4.6)
3 | project(Lua
4 | VERSION ${LUA_VERSION}
5 | DESCRIPTION "Lua and LuaRocks packaged by DEVCOM"
6 | HOMEPAGE_URL https://github.com/DevelopersCommunity/cmake-lua
7 | LANGUAGES C
8 | )
9 |
10 | # https://www.lua.org/ftp/
11 | set(LUA_TARBALL lua-${CMAKE_PROJECT_VERSION}.tar.gz)
12 | set(LUA_TARBALL_SHA256 7d5ea1b9cb6aa0b59ca3dde1c6adcb57ef83a1ba8e5432c0ecd06bf439b3ad88)
13 |
14 | if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL})
15 | file(DOWNLOAD https://www.lua.org/ftp/${LUA_TARBALL}
16 | ${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL}
17 | EXPECTED_HASH SHA256=${LUA_TARBALL_SHA256}
18 | )
19 | file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL}
20 | DESTINATION ${CMAKE_CURRENT_LIST_DIR}
21 | )
22 | endif()
23 |
24 | if(WIN32)
25 | set(LUAROCKS_VERSION 3.9.2)
26 | set(LUAROCKS_TARBALL luarocks-${LUAROCKS_VERSION}-windows-64.zip)
27 |
28 | if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL})
29 | file(DOWNLOAD http://luarocks.github.io/luarocks/releases/${LUAROCKS_TARBALL}
30 | ${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL}
31 | )
32 | file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL}
33 | DESTINATION ${CMAKE_CURRENT_LIST_DIR}
34 | )
35 | endif()
36 |
37 | set(LUA_LOGO lua-logo-nolabel.ps)
38 | if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${LUA_LOGO})
39 | file(DOWNLOAD https://www.lua.org/images/${LUA_LOGO}
40 | ${CMAKE_CURRENT_LIST_DIR}/${LUA_LOGO}
41 | )
42 | endif()
43 |
44 | add_custom_command(OUTPUT lua.ico
45 | COMMAND magick ${CMAKE_CURRENT_LIST_DIR}/${LUA_LOGO} -resize 256x256 lua.ico
46 | MAIN_DEPENDENCY ${CMAKE_CURRENT_LIST_DIR}/${LUA_LOGO}
47 | COMMENT "Generating Lua icon"
48 | )
49 | add_custom_target(luaicon ALL DEPENDS lua.ico)
50 | endif()
51 |
52 | set(LUA_SRC lua-${CMAKE_PROJECT_VERSION}/src)
53 | set(LUA_DOC lua-${CMAKE_PROJECT_VERSION}/doc)
54 |
55 | set(LIB
56 | ${LUA_SRC}/lapi.c
57 | ${LUA_SRC}/lcode.c
58 | ${LUA_SRC}/lctype.c
59 | ${LUA_SRC}/ldebug.c
60 | ${LUA_SRC}/ldo.c
61 | ${LUA_SRC}/ldump.c
62 | ${LUA_SRC}/lfunc.c
63 | ${LUA_SRC}/lgc.c
64 | ${LUA_SRC}/llex.c
65 | ${LUA_SRC}/lmem.c
66 | ${LUA_SRC}/lobject.c
67 | ${LUA_SRC}/lopcodes.c
68 | ${LUA_SRC}/lparser.c
69 | ${LUA_SRC}/lstate.c
70 | ${LUA_SRC}/lstring.c
71 | ${LUA_SRC}/ltable.c
72 | ${LUA_SRC}/ltm.c
73 | ${LUA_SRC}/lundump.c
74 | ${LUA_SRC}/lvm.c
75 | ${LUA_SRC}/lzio.c
76 | ${LUA_SRC}/lauxlib.c
77 | ${LUA_SRC}/lbaselib.c
78 | ${LUA_SRC}/lcorolib.c
79 | ${LUA_SRC}/ldblib.c
80 | ${LUA_SRC}/liolib.c
81 | ${LUA_SRC}/lmathlib.c
82 | ${LUA_SRC}/loadlib.c
83 | ${LUA_SRC}/loslib.c
84 | ${LUA_SRC}/lstrlib.c
85 | ${LUA_SRC}/ltablib.c
86 | ${LUA_SRC}/lutf8lib.c
87 | ${LUA_SRC}/linit.c
88 | )
89 |
90 | set(LUA
91 | ${LUA_SRC}/lua.c
92 | )
93 |
94 | set (LUAC
95 | ${LUA_SRC}/luac.c
96 | )
97 |
98 | add_executable(lua ${LUA} ${LIB})
99 | add_executable(luac ${LUAC} ${LIB})
100 |
101 | if(NOT WIN32)
102 | include(CheckLibraryExists)
103 | check_library_exists(m pow "" LIBEXISTS)
104 | if(LIBEXISTS)
105 | target_link_libraries(lua PUBLIC m)
106 | target_link_libraries(luac PUBLIC m)
107 | endif()
108 | endif()
109 |
110 | add_library(lualib SHARED ${LIB})
111 | target_sources(lualib
112 | PUBLIC
113 | FILE_SET include TYPE HEADERS BASE_DIRS ${LUA_SRC}
114 | FILES ${LUA_SRC}/lauxlib.h ${LUA_SRC}/lua.h ${LUA_SRC}/lua.hpp ${LUA_SRC}/luaconf.h ${LUA_SRC}/lualib.h
115 | )
116 |
117 | if(WIN32)
118 | target_compile_definitions(lualib PUBLIC LUA_BUILD_AS_DLL)
119 | set_property(TARGET lualib PROPERTY OUTPUT_NAME lua${CMAKE_PROJECT_VERSION_MAJOR}${CMAKE_PROJECT_VERSION_MINOR})
120 |
121 | install(PROGRAMS
122 | ${CMAKE_CURRENT_LIST_DIR}/luarocks-${LUAROCKS_VERSION}-windows-64/luarocks.exe
123 | ${CMAKE_CURRENT_LIST_DIR}/luarocks-${LUAROCKS_VERSION}-windows-64/luarocks-admin.exe
124 | TYPE BIN)
125 | else()
126 | set_property(TARGET lualib PROPERTY OUTPUT_NAME lua)
127 | endif()
128 |
129 | install(TARGETS lua luac)
130 | install(TARGETS lualib FILE_SET include)
131 | install(FILES ${CMAKE_CURRENT_LIST_DIR}/LICENSE.txt TYPE DOC)
132 |
133 | if(WIN32)
134 | set(CPACK_GENERATOR ZIP WIX)
135 | install(FILES
136 | ${CMAKE_CURRENT_BINARY_DIR}/lua.pdb
137 | ${CMAKE_CURRENT_BINARY_DIR}/luac.pdb
138 | ${CMAKE_CURRENT_BINARY_DIR}/lua54.pdb
139 | DESTINATION bin)
140 | set(CPACK_WIX_UPGRADE_GUID "3e5a792d-9d31-41d5-a93f-629ab7c7683d")
141 | set(CPACK_WIX_PRODUCT_ICON lua.ico)
142 | list(APPEND CPACK_WIX_EXTENSIONS WixUtilExtension)
143 | list(APPEND CPACK_WIX_PATCH_FILE ${CMAKE_CURRENT_LIST_DIR}/WixPatch.xml)
144 | else()
145 | install(FILES ${LUA_DOC}/lua.1 ${LUA_DOC}/luac.1
146 | DESTINATION man/man1
147 | )
148 | endif()
149 | set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
150 | set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/LICENSE.txt)
151 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_PROJECT_NAME})
152 | set(CPACK_PACKAGE_VENDOR DEVCOM)
153 | include(CPack)
154 |
--------------------------------------------------------------------------------
/Install-Lua.ps1:
--------------------------------------------------------------------------------
1 | $ErrorActionPreference = 'Stop'
2 |
3 | if (Test-Path -Path install -PathType Container)
4 | {
5 | Remove-Item -Recurse -Force -Path install
6 | }
7 | cmake --install build --prefix install
8 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright © 1994–2023 Lua.org, PUC-Rio.
2 | Copyright © 2007-2011, Kepler Project.
3 | Copyright © 2011-2022, the LuaRocks project authors.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CMake for Lua
2 |
3 | This is a CMake-based project to build and package [Lua](https://lua.org/) and
4 | [LuaRocks](https://luarocks.org/). As the [official Lua binaries
5 | repository](https://luabinaries.sourceforge.net/) is not updated very
6 | frequently, and the [compilation
7 | process](https://www.lua.org/manual/5.4/readme.html) for Windows binaries is not
8 | straightforward for non-C developers, you can use this project to build an
9 | updated version of Lua.
10 |
11 | The installer is used by the `DEVCOM.Lua`
12 | [winget](https://learn.microsoft.com/windows/package-manager/) package. You can
13 | install it with the following command:
14 |
15 | ```powershell
16 | winget install --id DEVCOM.Lua
17 | ```
18 |
19 | ## Build prerequisites
20 |
21 | - C compiler ([Microsoft Visual
22 | C++](https://learn.microsoft.com/cpp/overview/visual-cpp-in-visual-studio) or
23 | [Clang](https://clang.llvm.org/))
24 | - [CMake](https://cmake.org/)
25 | - [Ninja](https://ninja-build.org/)
26 | - [ImageMagick](https://imagemagick.org/)
27 | - [GhostScript](https://www.ghostscript.com/)
28 | - [WiX v3](https://wixtoolset.org/docs/wix3/)
29 |
30 | You can install the first five components with the following
31 | [winget](https://learn.microsoft.com/windows/package-manager/winget/) commands:
32 |
33 | ```powershell
34 | winget install --id LLVM.LLVM
35 | winget install --id Kitware.CMake
36 | winget install --id Ninja-build.Ninja
37 | winget install --id ImageMagick.ImageMagick
38 | winget install --id ArtifexSoftware.GhostScript
39 | ```
40 |
41 | WiX v3 is available at . It
42 | requires .NET Framework 3.5 that can be installed with the following command:
43 |
44 | ```powershell
45 | Start-Process `
46 | -FilePath pwsh `
47 | -ArgumentList "-Command `"& {Enable-WindowsOptionalFeature -Online -FeatureName NetFx3}`"" `
48 | -Wait `
49 | -Verb RunAs
50 | ```
51 |
52 | Update your path environment with `setx` (supposing you installed the tools in
53 | their default directories):
54 |
55 | ```powershell
56 | setx PATH ($(Get-ItemProperty -Path HKCU:\Environment -Name Path).Path + `
57 | "$env:ProgramFiles\LLVM\bin")
58 | ```
59 |
60 | Check if `PATH` was set correctly:
61 |
62 | ```
63 | Get-Command clang
64 | Get-Command cmake
65 | Get-Command ninja
66 | Get-Command magick
67 | Get-Command gswin64
68 | ```
69 |
70 | You may need to restart your Windows session if you can't find `ninja` even
71 | after restarting your terminal.
72 |
73 | ## Build
74 |
75 | Use the following commands to generate the installation package in both ZIP and
76 | MSI formats:
77 |
78 | ```powershell
79 | cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo
80 | cmake --build build --target package
81 | ```
82 |
83 | You need Internet access to execute the build process to download the Lua source
84 | code and LuaRocks binaries.
85 |
86 | For convenience, you can use the `Build-Lua.ps1` script to run these commands.
87 |
88 | If successful, the ZIP and MSI files will be available in the `build` directory.
89 |
--------------------------------------------------------------------------------
/WixPatch.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------