Skip to content

Commit 4da090a

Browse files
committed
[CMake+CI] Add Alpine builder for musl
Signed-off-by: AeroStun <24841307+AeroStun@users.noreply.github.com>
1 parent c49e880 commit 4da090a

File tree

7 files changed

+275
-12
lines changed

7 files changed

+275
-12
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ jobs:
44
make-release:
55
name: Publish release
66
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
7-
needs: [ build-linux, build-macos, build-windows ]
7+
needs: [ build-linux, build-macos, build-windows, package-alpine ]
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111
- name: Download all build artifacts
12-
uses: actions/download-artifact@v2
12+
uses: actions/download-artifact@v3
1313
- name: Create Release
1414
shell: bash
1515
run: |
@@ -62,15 +62,15 @@ jobs:
6262
cmake -DCMAKE_INSTALL_PREFIX=/opt/llvm_static -S . -B build
6363
cmake --build ./build --target install
6464
cd ..
65-
- uses: actions/checkout@v2
65+
- uses: actions/checkout@v3
6666
- name: Configure
6767
run: cmake -G Ninja -DARDPRE_CXXRT_LINKING=STATIC -DSLIBCLANG_DIR=/opt/llvm_static -S . -B dist
6868
- name: Build
6969
run: cmake --build ./dist
7070
- name: Package
7171
run: (cd dist; cpack -G TGZ .)
7272
- name: Upload artifacts
73-
uses: 'actions/upload-artifact@v2'
73+
uses: actions/upload-artifact@v3
7474
with:
7575
name: ardpre-linux
7676
path: dist/*.tar.gz
@@ -101,7 +101,7 @@ jobs:
101101
cmake -DCMAKE_INSTALL_PREFIX=~/llvm_static -S . -B build
102102
cmake --build ./build --target install
103103
cd ..
104-
- uses: actions/checkout@v2
104+
- uses: actions/checkout@v3
105105
- name: Configure
106106
run: |
107107
export CC="$(brew --prefix llvm)/bin/clang -stdlib=libc++ -nostdinc++ -I$(brew --prefix)/opt/llvm/include/c++/v1 -Wno-unused-command-line-argument"
@@ -113,7 +113,7 @@ jobs:
113113
- name: Package
114114
run: (cd dist; cpack -G TGZ .)
115115
- name: Upload artifacts
116-
uses: 'actions/upload-artifact@v2'
116+
uses: actions/upload-artifact@v3
117117
with:
118118
name: ardpre-macos
119119
path: dist/*.tar.gz
@@ -136,7 +136,7 @@ jobs:
136136
cmake -DCMAKE_INSTALL_PREFIX=C:\llvm_static -DLLVM_USE_CRT_RELEASE=MT -S . -B build
137137
cmake --build ./build --target install --config Release
138138
cd ..
139-
- uses: actions/checkout@v2
139+
- uses: actions/checkout@v3
140140
- name: Configure
141141
run: cmake -DSLIBCLANG_DIR=C:\llvm_static -DARDPRE_CXXRT_LINKING=STATIC -S . -B dist
142142
- name: Build
@@ -146,7 +146,39 @@ jobs:
146146
cd dist
147147
cpack -G ZIP .
148148
- name: Upload artifacts
149-
uses: 'actions/upload-artifact@v2'
149+
uses: actions/upload-artifact@v3
150150
with:
151151
name: ardpre-windows
152152
path: dist/*.zip
153+
package-alpine:
154+
name: Package Alpine APK
155+
runs-on: ubuntu-latest
156+
container: alpine:latest
157+
steps:
158+
- name: Get deps
159+
run: |
160+
apk update
161+
apk upgrade
162+
apk add alpine-sdk atools git ninja cmake gcc g++ clang-dev clang-static llvm12-dev llvm12-static
163+
echo '' | abuild-keygen -aq &> /dev/null
164+
- uses: actions/checkout@v3
165+
- name: Configure
166+
run: |
167+
cmake -G Ninja \
168+
-DLIBCLANG_SYS=True \
169+
-DARDPRE_CPACK_PROFILE=APKBUILD \
170+
-DCMAKE_INSTALL_PREFIX=/usr \
171+
-B dist
172+
- name: Build
173+
run: cmake --build ./dist
174+
- name: Package
175+
run: cmake --build ./dist --target package
176+
- name: Lint APKBUILD
177+
run: apkbuild-lint ./dist/APKBUILD || true
178+
- name: Upload artifacts
179+
uses: actions/upload-artifact@v3
180+
with:
181+
name: ardpre-alpine
182+
path: |
183+
dist/APKBUILD
184+
dist/*.apk

CMake/Modules/CPackCommon.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# CPackCommon.cmake
3+
# Copyright 2021-2022 ItJustWorksTM
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
include_guard ()
19+
20+
set (CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
21+
22+
if (DEFINED CMAKE_OSX_ARCHITECTURES)
23+
list (LENGTH CMAKE_OSX_ARCHITECTURES osx_arch_count)
24+
if (osx_arch_count GREATER 1)
25+
set (CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-universal")
26+
endif ()
27+
endif ()
28+
29+
set (CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
30+
set (CPACK_PACKAGE_VENDOR "ItJustWorksTM")
31+
set (CPACK_PACKAGE_CONTACT "${CPACK_PACKAGE_VENDOR} <itjustworkstm@aerostun.dev>")
32+
set (CMAKE_PROJECT_DESCRIPTION "SMCE's replacement for Arduino's ctags-based preprocessor")
33+
set (CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/ItJustWorksTM/arduino-prelude")
34+
set (CPACK_PACKAGE_DESCRIPTION "LLVM-based prelude generator for Arduino sketches.")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# PackagingProfiles/APKBUILD.cmake
3+
# Copyright 2022 ItJustWorksTM
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
include_guard ()
19+
set (CPACK_GENERATOR External)
20+
set (CPACK_EXTERNAL_PACKAGE_SCRIPT "${PROJECT_SOURCE_DIR}/CPack/Generators/APKBUILD/APKBUILD.cmake")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# PackagingProfiles/Default.cmake
3+
# Copyright 2021-2022 ItJustWorksTM
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
include_guard ()
19+
20+
if (WIN32)
21+
set (CPACK_GENERATOR ZIP 7Z)
22+
else ()
23+
set (CPACK_GENERATOR TXZ TGZ STGZ)
24+
endif ()

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cmake_minimum_required (VERSION 3.13.4)
1919
cmake_policy (SET CMP0022 NEW)
2020
cmake_policy (SET CMP0091 NEW)
2121

22+
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake/Modules")
2223
project (arduino-prelude VERSION 1.0.22)
2324

2425
add_executable (arduino-prelude)
@@ -59,6 +60,9 @@ if (DEFINED SLIBCLANG_DIR)
5960
endif ()
6061
target_compile_options (arduino-prelude PUBLIC -Os -ffunction-sections -fdata-sections)
6162
endif ()
63+
elseif (LIBCLANG_SYS)
64+
find_package (Clang REQUIRED)
65+
target_link_libraries (arduino-prelude PRIVATE libclang)
6266
else ()
6367
find_package (LLVM 13 REQUIRED CONFIG)
6468
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
@@ -74,8 +78,12 @@ else ()
7478
target_link_libraries (arduino-prelude PUBLIC ${LLVM_LIBS} clang)
7579
endif ()
7680

77-
install (TARGETS arduino-prelude
78-
RUNTIME DESTINATION .
79-
)
81+
install (TARGETS arduino-prelude RUNTIME)
8082

83+
if (NOT DEFINED ARDPRE_CPACK_PROFILE)
84+
set (ARDPRE_CPACK_PROFILE "Archive")
85+
endif ()
86+
87+
include (CPackCommon)
88+
include ("${PROJECT_SOURCE_DIR}/CMake/PackagingProfiles/${ARDPRE_CPACK_PROFILE}.cmake")
8189
include (CPack)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#
2+
# APKBUILD.cmake
3+
# Copyright 2022 ItJustWorksTM
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
cmake_minimum_required (VERSION 3.16)
19+
message (DEBUG "CPack APKBUILD Packager v0.1")
20+
21+
if (NOT DEFINED APKBUILD_PACKAGE_NAME)
22+
set (APKBUILD_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
23+
endif ()
24+
if (NOT DEFINED APKBUILD_PACKAGE_VERSION)
25+
set (APKBUILD_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
26+
endif ()
27+
if (NOT DEFINED APKBUILD_PACKAGE_RELEASE)
28+
set (APKBUILD_PACKAGE_RELEASE 0)
29+
endif ()
30+
if (NOT DEFINED APKBUILD_PACKAGE_DESCRIPTION)
31+
set (APKBUILD_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
32+
endif ()
33+
string (REPLACE "\n" "\\n" APKBUILD_PACKAGE_DESCRIPTION "${APKBUILD_PACKAGE_DESCRIPTION}")
34+
if (NOT DEFINED APKBUILD_PACKAGE_HOMEPAGE)
35+
set (APKBUILD_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}")
36+
endif ()
37+
if (NOT DEFINED APKBUILD_PACKAGE_ARCHITECTURE)
38+
set (APKBUILD_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
39+
endif ()
40+
if (NOT DEFINED APKBUILD_PACKAGE_LICENSE)
41+
set (APKBUILD_PACKAGE_LICENSE "unknown")
42+
endif()
43+
if (NOT DEFINED APKBUILD_PACKAGE_DEPENDS)
44+
set (APKBUILD_PACKAGE_DEPENDS "")
45+
endif()
46+
47+
set (SRCDIR ".")
48+
set (BUILDDIR "$srcdir/build")
49+
configure_file ("${CMAKE_CURRENT_LIST_DIR}/APKBUILD.in" "${CPACK_PACKAGE_DIRECTORY}/APKBUILD" @ONLY)
50+
51+
if (NOT DEFINED APKBUILD_GENERATE_PACKAGE)
52+
set (APKBUILD_GENERATE_PACKAGE Yes)
53+
endif ()
54+
if (NOT APKBUILD_GENERATE_PACKAGE)
55+
return ()
56+
endif ()
57+
58+
59+
list (GET CPACK_BUILD_SOURCE_DIRS 0 CPACK_SOURCE_DIR)
60+
list (GET CPACK_BUILD_SOURCE_DIRS 1 CPACK_BUILD_DIR)
61+
file (MAKE_DIRECTORY "${CPACK_BUILD_DIR}/cpack-abuild")
62+
set (SRCDIR "${CPACK_SOURCE_DIR}")
63+
set (BUILDDIR "${CPACK_BUILD_DIR}")
64+
configure_file ("${CMAKE_CURRENT_LIST_DIR}/APKBUILD.in" "${CPACK_BUILD_DIR}/cpack-abuild/APKBUILD" @ONLY)
65+
66+
find_program (ID_EXECUTABLE id)
67+
if (NOT ID_EXECUTABLE)
68+
message (FATAL_ERROR "Unable to detect current user id (root check)")
69+
endif ()
70+
71+
execute_process (COMMAND "${ID_EXECUTABLE}" -u OUTPUT_VARIABLE uid)
72+
73+
if (uid EQUAL 0)
74+
set (abuild_maybe_root -F)
75+
else ()
76+
set (abuild_maybe_root)
77+
endif ()
78+
79+
find_program (ABUILD_EXECUTABLE abuild REQUIRED)
80+
execute_process (
81+
COMMAND "${ABUILD_EXECUTABLE}" -P "${CPACK_TEMPORARY_DIRECTORY}" ${abuild_maybe_root} rootpkg
82+
WORKING_DIRECTORY "${CPACK_BUILD_DIR}/cpack-abuild"
83+
)
84+
85+
set (CPACK_EXTERNAL_BUILT_PACKAGES)
86+
file (GLOB_RECURSE package_files "${CPACK_TEMPORARY_DIRECTORY}/*.apk")
87+
foreach (package_file IN LISTS package_files)
88+
file (COPY "${package_file}" DESTINATION "${CPACK_PACKAGE_DIRECTORY}")
89+
get_filename_component (package_filename "${package_file}" NAME)
90+
list (APPEND CPACK_EXTERNAL_BUILT_PACKAGES "${CPACK_PACKAGE_DIRECTORY}/${package_filename}")
91+
endforeach ()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# APKBUILD.in
3+
# Copyright 2022 ItJustWorksTM
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Contributor: AeroStun
18+
# Maintainer: ItJustWorksTM
19+
pkgname=@APKBUILD_PACKAGE_NAME@
20+
pkgver=@APKBUILD_PACKAGE_VERSION@
21+
pkgrel=@APKBUILD_PACKAGE_RELEASE@
22+
pkgdesc="@APKBUILD_PACKAGE_DESCRIPTION@"
23+
url="@APKBUILD_PACKAGE_HOMEPAGE@"
24+
arch="@APKBUILD_PACKAGE_ARCHITECTURE@"
25+
license="@APKBUILD_PACKAGE_LICENSE@"
26+
depends="@APKBUILD_PACKAGE_DEPENDS@"
27+
makedepends="cmake"
28+
checkdepends=""
29+
install=""
30+
subpackages=""
31+
source="CMakeLists.txt"
32+
builddir="@BUILDDIR@"
33+
34+
build() {
35+
if [ "$CBUILD" != "$CHOST" ]; then
36+
CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
37+
fi
38+
cmake \
39+
-DCMAKE_INSTALL_PREFIX=/usr \
40+
-DCMAKE_BUILD_TYPE=None \
41+
$CMAKE_CROSSOPTS \
42+
-S "@SRCDIR@" -B "$builddir"
43+
cmake --build "$builddir"
44+
}
45+
46+
check() {
47+
cd "$builddir"
48+
CTEST_OUTPUT_ON_FAILURE=TRUE ctest
49+
}
50+
51+
package() {
52+
DESTDIR="$pkgdir" cmake --install "$builddir"
53+
}
54+

0 commit comments

Comments
 (0)