Skip to content

Commit ecca170

Browse files
committed
Switched to CMake and building natively on Windows, macOS, and Linux.
1 parent 52d8ab6 commit ecca170

File tree

5 files changed

+104
-103
lines changed

5 files changed

+104
-103
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,56 @@
11
name: release
22
on:
33
push:
4-
branch: default
4+
branches: default
55

66
jobs:
77
build:
8-
runs-on: ubuntu-20.04
9-
container: ghcr.io/orbitalquark/textadept-build:v2.0
8+
strategy:
9+
matrix:
10+
os: [ubuntu-20.04, windows-2019, macOS-11]
11+
runs-on: ${{ matrix.os }}
1012
steps:
11-
- name: Checkout textadept
12-
uses: actions/checkout@v2
13-
with:
14-
repository: orbitalquark/textadept
15-
path: textadept
13+
- name: Checkout
14+
uses: actions/checkout@v3
1615
- name: Checkout textadept-build dependencies
17-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1817
with:
1918
repository: orbitalquark/textadept-build
2019
path: textadept-build
21-
- name: Checkout textadept-file-diff module
22-
uses: actions/checkout@v2
23-
with:
24-
path: textadept/modules/file_diff
2520
- name: Build
2621
shell: bash
2722
run: |
28-
mv textadept-build/* textadept/src && make -C textadept/src lua
29-
make -C textadept/modules/file_diff release
23+
mkdir -p build/_deps && mv textadept-build/* build/_deps && rm -r textadept-build
24+
cmake -S . -B build
25+
cmake --build build --config Release --target diff -j
26+
cmake --install build --config Release
3027
- name: Upload artifacts
31-
uses: actions/upload-artifact@v2
28+
uses: actions/upload-artifact@v3
3229
with:
3330
name: artifacts
34-
path: textadept/modules/file_diff/file_diff.zip
31+
path: |
32+
*.so
33+
*.dll
3534
release:
3635
runs-on: ubuntu-latest
3736
needs: build
3837
steps:
3938
- name: Checkout
40-
uses: actions/checkout@v2
39+
uses: actions/checkout@v3
40+
- name: Download artifacts
41+
uses: actions/download-artifact@v3
42+
with:
43+
name: artifacts
44+
- name: Package
45+
shell: bash
46+
run: |
47+
git archive HEAD --prefix file_diff/ | tar -xf -
48+
mv *.so *.dll file_diff
49+
zip -r file_diff.zip file_diff
4150
- name: Tag
4251
run: |
4352
git tag latest
4453
git push -f origin latest
45-
- name: Download artifacts
46-
uses: actions/download-artifact@v2
47-
with:
48-
name: artifacts
4954
- name: Create release
5055
uses: ncipollo/release-action@v1
5156
with:
@@ -57,7 +62,7 @@ jobs:
5762
token: ${{ secrets.GITHUB_TOKEN }}
5863
cleanup:
5964
runs-on: ubuntu-latest
60-
needs: [build, release]
65+
needs: release
6166
steps:
6267
- name: Remove older build artifacts
6368
uses: c-hive/gha-remove-artifacts@v1

CMakeLists.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2022 Mitchell. See LICENSE.
2+
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED true)
7+
if(APPLE)
8+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
9+
endif()
10+
11+
set(src ${CMAKE_SOURCE_DIR})
12+
13+
# Dependencies.
14+
include(FetchContent)
15+
set(FETCHCONTENT_QUIET OFF)
16+
set(diff_match_patch_zip 7f95b37e554453262e2bcda830724fc362614103.zip)
17+
FetchContent_Declare(diff_match_patch
18+
URL https://github.com/leutloff/diff-match-patch-cpp-stl/archive/${diff_match_patch_zip})
19+
FetchContent_MakeAvailable(diff_match_patch)
20+
set(lua_tgz lua-5.4.4.tar.gz)
21+
set(lua_url file://${CMAKE_BINARY_DIR}/_deps/${lua_tgz})
22+
if(NOT EXISTS ${CMAKE_BINARY_DIR}/_deps/${lua_tgz})
23+
set(lua_url https://www.lua.org/ftp/${lua_tgz})
24+
endif()
25+
FetchContent_Declare(lua URL ${lua_url})
26+
FetchContent_MakeAvailable(lua)
27+
28+
# Build.
29+
project(diff LANGUAGES CXX C)
30+
if(WIN32)
31+
# On Windows, DLLs cannot do dynamic lookup. They need symbols to link to at build time.
32+
# Rather than fetching a Textadept build and creating separate DLLs linked to textadept.lib and
33+
# textadept-curses.lib, just embed a minimal copy of Lua in a single DLL.
34+
file(GLOB lua_src ${lua_SOURCE_DIR}/src/*.c)
35+
list(FILTER lua_src EXCLUDE REGEX "(lua|luac|[^x]lib|linit)\.c$") # of *lib.c, keep only lauxlib.c
36+
endif()
37+
add_library(diff SHARED diff.cxx ${lua_src})
38+
target_include_directories(diff PRIVATE ${diff_match_patch_SOURCE_DIR} ${lua_SOURCE_DIR}/src)
39+
if(WIN32)
40+
target_compile_definitions(diff PRIVATE LUA_BUILD_AS_DLL LUA_LIB)
41+
elseif(APPLE)
42+
target_link_options(diff PRIVATE -undefined dynamic_lookup)
43+
endif()
44+
45+
# Install.
46+
install(TARGETS diff DESTINATION ${src})
47+
if(NOT (WIN32 OR APPLE))
48+
install(CODE "file(RENAME ${src}/libdiff.so ${src}/diff.so)")
49+
elseif(APPLE)
50+
install(CODE "file(RENAME ${src}/libdiff.dylib ${src}/diffosx.so)")
51+
endif()
52+
53+
# Documentation.
54+
get_filename_component(ta_dir ${src}/../../ ABSOLUTE)
55+
add_custom_target(docs DEPENDS README.md luadoc)
56+
add_custom_command(OUTPUT ${src}/README.md
57+
COMMAND luadoc --doclet markdowndoc ${src}/init.lua > ${src}/README.md
58+
COMMAND sed -i -e "1,+4d" -e "6c# File Diff" -e "7d" -e "s/^##/#/;" ${src}/README.md
59+
DEPENDS init.lua
60+
WORKING_DIRECTORY ${ta_dir}/scripts
61+
VERBATIM)
62+
add_custom_target(luadoc DEPENDS tags api)
63+
add_custom_command(OUTPUT ${src}/tags ${src}/api
64+
COMMAND luadoc -d ${src} --doclet tadoc ${src}/init.lua --ta-home=${ta_dir}
65+
DEPENDS init.lua
66+
WORKING_DIRECTORY ${ta_dir}/modules/lua)

Makefile

Lines changed: 0 additions & 74 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ Install this module by copying it into your *~/.textadept/modules/* directory or
1010
## Compiling
1111

1212
Releases include binaries, so building this modules should not be necessary. If you want
13-
to build manually, run `make deps` followed by `make diff.so`. This assumes the module is
14-
installed in Textadept's *modules/* directory. If it is not (e.g. it is in your `_USERHOME`),
15-
run `make ta=/path/to/textadept diff.so`.
13+
to build manually, use CMake. For example:
14+
15+
cmake -S . -B build_dir
16+
cmake --build build_dir --target diff
17+
cmake --install build_dir
1618

1719
## Usage
1820

init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ local M = {}
1414
-- ### Compiling
1515
--
1616
-- Releases include binaries, so building this modules should not be necessary. If you want
17-
-- to build manually, run `make deps` followed by `make diff.so`. This assumes the module is
18-
-- installed in Textadept's *modules/* directory. If it is not (e.g. it is in your `_USERHOME`),
19-
-- run `make ta=/path/to/textadept diff.so`.
17+
-- to build manually, use CMake. For example:
18+
--
19+
-- cmake -S . -B build_dir
20+
-- cmake --build build_dir --target diff
21+
-- cmake --install build_dir
2022
--
2123
-- ### Usage
2224
--

0 commit comments

Comments
 (0)