Skip to content

Commit 90283b5

Browse files
committed
Compile pawn apps to resources
1 parent 4e16575 commit 90283b5

7 files changed

Lines changed: 78 additions & 3 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
shell: bash
4242
run: |
4343
git config --global --add safe.directory /__w/InfiniTime/InfiniTime
44-
/opt/build.sh all
44+
/__w/InfiniTime/InfiniTime/docker/build.sh all
4545
- name: Output build size
4646
id: output-sizes
4747
shell: bash

docker/build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ main() {
3636
[ ! -d "$TOOLS_DIR/$GCC_ARM_PATH" ] && GetGcc
3737
[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ] && GetNrfSdk
3838
[ ! -d "$TOOLS_DIR/mcuboot" ] && GetMcuBoot
39+
[ ! -f "$TOOLS_DIR/pawn/pawncc" ] && GetPawn
3940

4041
mkdir -p "$BUILD_DIR"
4142

@@ -49,6 +50,15 @@ main() {
4950
return $BUILD_RESULT
5051
}
5152

53+
GetPawn() (
54+
set -e
55+
git clone -b v4.1.7152 https://codeberg.org/compuphase/pawn.git $TOOLS_DIR/pawn
56+
mkdir $TOOLS_DIR/pawn/build
57+
cd $TOOLS_DIR/pawn/build
58+
cmake ..
59+
make -j $(nproc) pawncc
60+
)
61+
5262
GetGcc() {
5363
wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/$GCC_ARM_VER/$GCC_ARM_PATH-$MACHINE-linux.tar.bz2 -O - | tar -xj -C $TOOLS_DIR/
5464
if [ ! -d "$TOOLS_DIR/$GCC_ARM_PATH" ]; then

src/resources/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ find_program(LV_IMG_CONV "lv_img_conv.py" NO_CACHE REQUIRED
77
HINTS "${CMAKE_CURRENT_SOURCE_DIR}")
88
message(STATUS "Using ${LV_IMG_CONV} to generate font files")
99

10+
find_program(PAWNCC "pawncc" NO_CACHE REQUIRED
11+
HINTS "$ENV{TOOLS_DIR}/pawn/build"
12+
"$ENV{TOOLS_DIR}/pawn/bin"
13+
"/usr/local/bin"
14+
"/usr/bin")
15+
message(STATUS "Using ${PAWNCC} to compile Pawn source files")
16+
1017
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
1118
# FindPython3 module introduces with CMake 3.12
1219
# https://cmake.org/cmake/help/latest/module/FindPython3.html
@@ -20,7 +27,8 @@ endif()
2027
add_custom_target(GenerateResources
2128
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate-fonts.py --lv-font-conv "${LV_FONT_CONV}" ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json
2229
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate-img.py --lv-img-conv "${LV_IMG_CONV}" ${CMAKE_CURRENT_SOURCE_DIR}/images.json
23-
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate-package.py --config ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json --config ${CMAKE_CURRENT_SOURCE_DIR}/images.json --obsolete obsolete_files.json --output infinitime-resources-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.zip
30+
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate-apps.py --pawncc ${PAWNCC} --include ${CMAKE_CURRENT_SOURCE_DIR}/../pawn/programs/include ${CMAKE_CURRENT_SOURCE_DIR}/apps.json
31+
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/generate-package.py --config ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json --config ${CMAKE_CURRENT_SOURCE_DIR}/images.json --config ${CMAKE_CURRENT_SOURCE_DIR}/apps.json --obsolete obsolete_files.json --output infinitime-resources-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.zip
2432
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fonts.json
2533
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/images.json
2634
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

src/resources/apps.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"hello_world": {
3+
"source": "apps/hello_world.p",
4+
"overlays": false,
5+
"target_path": "/apps/",
6+
"extension": ".amx"
7+
}
8+
}

src/resources/apps/hello_world.p

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@start() {
2+
var lv_obj: label = lv_label_create(screen, .text = "Hello world!")
3+
lv_obj_align(label, screen, LV_ALIGN_CENTER)
4+
}

src/resources/generate-apps.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import argparse
2+
import json
3+
import os
4+
import pathlib
5+
import shutil
6+
import subprocess
7+
import sys
8+
9+
DEFAULT_STACK_SIZE = 50
10+
OVERLAY_SIZE = 2048
11+
12+
def main():
13+
ap = argparse.ArgumentParser(description='compile Pawn source files into binaries')
14+
ap.add_argument('config', type=str, help='config file to use')
15+
ap.add_argument('--pawncc', type=str, help='Path to "pawncc" executable', default="pawncc")
16+
ap.add_argument('--include', '-i', type=str, help='Path to Pawn include folder in InfiniTime sources', default="src/pawn/programs/include")
17+
args = ap.parse_args()
18+
19+
with open(args.config, 'r') as fd:
20+
data = json.load(fd)
21+
22+
for name, app in data.items():
23+
print("Compiling Pawn: " + name)
24+
25+
source = app["source"]
26+
if not os.path.exists(source):
27+
source = os.path.join(os.path.dirname(sys.argv[0]), source)
28+
29+
args = [args.pawncc, "-p" + os.path.join(args.include, "infinitime.inc"), "-i" + args.include]
30+
if not app.get("debug", False):
31+
args.append("-O3")
32+
args.append("-d0")
33+
if app.get("overlays", False):
34+
args.append("-V" + str(OVERLAY_SIZE))
35+
args.append("-S" + str(app.get("stack_size", DEFAULT_STACK_SIZE)))
36+
37+
args.append(source)
38+
39+
subprocess.check_call(args) # The output will be written to the current directory with the ".amx" extension
40+
41+
sourcePath = pathlib.Path(source)
42+
shutil.move(sourcePath.stem + ".amx", sourcePath.stem + ".bin")
43+
44+
if __name__ == '__main__':
45+
main()

src/resources/generate-package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main():
4242
resource = data[name]
4343
resource_files.append({
4444
"filename": name+'.bin',
45-
"path": resource['target_path'] + name+'.bin'
45+
"path": resource['target_path'] + name + resource.get('extension', '.bin')
4646
})
4747

4848
path = name + '.bin'

0 commit comments

Comments
 (0)