Skip to content

Commit 929014f

Browse files
Build modules
1 parent 51d9610 commit 929014f

File tree

2 files changed

+266
-0
lines changed

2 files changed

+266
-0
lines changed

.github/workflows/companion.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,40 @@ on:
2222
workflow_dispatch:
2323

2424
jobs:
25+
build-modules:
26+
name: WASM Modules
27+
runs-on: ubuntu-latest
28+
29+
container:
30+
image: ghcr.io/edgetx/edgetx-wasi:pr-37
31+
volumes:
32+
- ${{ github.workspace }}:/src
33+
34+
steps:
35+
- name: Check out the repo
36+
uses: actions/checkout@v4
37+
with:
38+
submodules: recursive
39+
40+
- name: Build modules
41+
shell: bash
42+
env:
43+
CMAKE_BUILD_TYPE: 'Release'
44+
run: |
45+
mkdir output && \
46+
tools/build-wasm-modules.sh "$(pwd)" "$(pwd)/output/"
47+
48+
- name: Compose artifact name
49+
run: echo "artifact_name=edgetx-modules-${GITHUB_REF##*/}" >> $GITHUB_ENV
50+
shell: bash
51+
52+
- name: Archive production artifacts
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: "${{ env.artifact_name }}"
56+
path: ${{github.workspace}}/output
57+
retention-days: 15
58+
2559
build-linux:
2660
name: Linux Companion
2761
runs-on: ubuntu-latest

tools/build-wasm-modules.sh

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
4+
. "$SCRIPT_DIR/build-common.sh"
5+
6+
SRCDIR=$1
7+
OUTDIR=$2
8+
9+
if [[ -z ${SRCDIR} ]]; then
10+
SRCDIR="$(pwd)"
11+
fi
12+
13+
if [[ -z ${OUTDIR} ]]; then
14+
OUTDIR="$(pwd)/output"
15+
fi
16+
17+
if [[ ! -d "${OUTDIR}" ]]; then
18+
mkdir -p "${OUTDIR}"
19+
fi
20+
21+
QUIET_FLAGS=""
22+
if [[ "$CMAKE_GENERATOR" == "Ninja" ]]; then
23+
QUIET_FLAGS="-- --quiet"
24+
else
25+
# Assume Makefile generator for non-Ninja builds
26+
COMMON_OPTIONS="-DCMAKE_RULE_MESSAGES=OFF"
27+
fi
28+
29+
COMMON_OPTIONS+=" -DCMAKE_BUILD_TYPE=Release -DCMAKE_MESSAGE_LOG_LEVEL=WARNING -Wno-dev"
30+
COMMON_OPTIONS+=" -DCMAKE_MODULE_PATH=/opt/wasi-sdk/share/cmake/"
31+
COMMON_OPTIONS+=" -DEdgeTX_SUPERBUILD:BOOL=0 -DNATIVE_BUILD:BOOL=1 -DDISABLE_COMPANION:BOOL=1"
32+
33+
# Generate EDGETX_VERSION_SUFFIX if not already set
34+
if [[ -z ${EDGETX_VERSION_SUFFIX} ]]; then
35+
gh_type=$(echo "$GITHUB_REF" | awk -F / '{print $2}') #heads|tags|pull
36+
if [[ $gh_type = "tags" ]]; then
37+
# tags: refs/tags/<tag_name>
38+
gh_tag=${GITHUB_REF##*/}
39+
export EDGETX_VERSION_TAG=$gh_tag
40+
elif [[ $gh_type = "pull" ]]; then
41+
# pull: refs/pull/<pr_number>/merge
42+
gh_pull_number=PR$(echo "$GITHUB_REF" | awk -F / '{print $3}')
43+
export EDGETX_VERSION_SUFFIX=$gh_pull_number
44+
elif [[ $gh_type = "heads" ]]; then
45+
# heads: refs/heads/<branch_name>
46+
gh_branch=${GITHUB_REF##*/}
47+
export EDGETX_VERSION_SUFFIX=$gh_branch
48+
fi
49+
fi
50+
51+
if [ "$(uname)" = "Linux" ] && [ -n "$GITHUB_ACTIONS" ]; then
52+
MAX_JOBS=3
53+
fi
54+
55+
rm -rf build && mkdir build && cd build
56+
57+
# Function to output error logs (works in both GitHub Actions and terminal)
58+
output_error_log() {
59+
local log_file="$1"
60+
local context="$2"
61+
62+
if [[ -f "$log_file" ]]; then
63+
echo "------------------------------------------"
64+
echo " Full error output from $log_file:"
65+
echo "------------------------------------------"
66+
cat "$log_file"
67+
else
68+
echo "⚠️ Warning: Log file $log_file not found for $context"
69+
fi
70+
}
71+
72+
# Function to show last N lines of a log file for warnings
73+
show_log_summary() {
74+
local log_file="$1"
75+
local lines="${2:-50}"
76+
local context="$3"
77+
78+
if [[ -f "$log_file" ]]; then
79+
echo "------------------------------------------"
80+
echo "Last $lines lines from $log_file:"
81+
echo "------------------------------------------"
82+
tail -n "$lines" "$log_file"
83+
fi
84+
}
85+
86+
run_pipeline() {
87+
local log_file="${1:-/dev/null}"
88+
local context="$2"
89+
local show_details="${3:-false}"
90+
local cmake_opts="--parallel ${MAX_JOBS} ${QUIET_FLAGS}"
91+
local wasi_toolchain="/opt/wasi-sdk/share/cmake/wasi-sdk-pthread.cmake"
92+
93+
clean_build
94+
if ! execute_with_output "🔧 Final config" "cmake -S ${SRCDIR} -B wasm --toolchain ${wasi_toolchain} ${BUILD_OPTIONS}" "$log_file" "$show_details"; then
95+
output_error_log "$log_file" "$context (Configuration)"
96+
return 1
97+
fi
98+
if ! execute_with_output "📦 Building WASM module" "cmake --build wasm --target wasi-module ${cmake_opts}" "$log_file" "$show_details"; then
99+
output_error_log "$log_file" "$context (Library Build)"
100+
return 1
101+
fi
102+
103+
return 0
104+
}
105+
106+
execute_with_output() {
107+
local description="$1"
108+
local command="$2"
109+
local log_file="$3"
110+
local show_output="${4:-false}"
111+
112+
if [[ "$show_output" == "true" && "$log_file" != "/dev/null" ]]; then
113+
echo " $description..."
114+
fi
115+
116+
eval "$command" >> "$log_file" 2>&1
117+
}
118+
119+
clean_build() {
120+
rm -f CMakeCache.txt native/CMakeCache.txt
121+
}
122+
123+
# Enhanced plugin builder with better error handling
124+
build_plugin() {
125+
local plugin="$1"
126+
local log_file="build_${plugin}.log"
127+
local verbose="${2:-false}"
128+
129+
BUILD_OPTIONS="${COMMON_OPTIONS} "
130+
131+
if ! get_target_build_options "$plugin" >> "$log_file" 2>&1; then
132+
if [[ -n "$GITHUB_ACTIONS" ]]; then
133+
echo "::error::Failed to get build options for $plugin"
134+
fi
135+
output_error_log "$log_file" "$plugin (Build Options)"
136+
return 1
137+
fi
138+
139+
# Only show detailed output in GitHub Actions or if verbose is requested
140+
local show_details="false"
141+
if [[ -n "$GITHUB_ACTIONS" || "$verbose" == "true" ]]; then
142+
show_details="true"
143+
fi
144+
145+
if ! run_pipeline "$log_file" "$plugin" "$show_details"; then
146+
return 1
147+
fi
148+
149+
if [[ -f "wasm/wasi-module.wasm" ]]; then
150+
cp "wasm/wasi-module.wasm" "${OUTDIR}/${plugin}.wasm" 2>/dev/null
151+
fi
152+
153+
# Check for warnings and show summary if found
154+
if grep -q -i "warning" "$log_file"; then
155+
echo " ⚠️ $plugin completed with warnings"
156+
if [[ "$show_details" == "true" ]]; then
157+
show_log_summary "$log_file" 50 "$plugin (Warnings)"
158+
fi
159+
return 0
160+
fi
161+
162+
echo "$plugin completed successfully"
163+
return 0
164+
}
165+
166+
declare -a simulator_plugins=(
167+
# x9lite x9lites x9d x9dp x9dp2019 x9e
168+
# x7 x7access
169+
# t8 t12 t12max tx12 tx12mk2 t15 t16 t18 t20 t20v2
170+
xlite xlites
171+
x10 x10express x12s
172+
zorro tx16s tx15
173+
commando8 boxer pocket mt12 gx12
174+
tlite tpro tprov2 tpros bumblebee lr3pro t14
175+
nv14 el18 pl18 pl18ev pl18u st16 pa01
176+
f16 v14 v16
177+
)
178+
179+
TOTAL=${#simulator_plugins[@]}
180+
FAILED_PLUGINS=()
181+
182+
echo "🔨 Building $TOTAL Plugins for $PACKAGE_NAME"
183+
184+
for i in "${!simulator_plugins[@]}"; do
185+
plugin="${simulator_plugins[$i]}"
186+
current=$((i + 1))
187+
percent=$((current * 100 / TOTAL))
188+
189+
# For terminal output, put each plugin on its own line for cleaner display
190+
if [[ -n "$GITHUB_ACTIONS" ]]; then
191+
printf "::group::📦 %-12s [%2d/%2d] %3d%%\n" "$plugin" "$current" "$TOTAL" "$percent"
192+
else
193+
echo "🔨 [$current/$TOTAL] ($percent%) Building $plugin..."
194+
fi
195+
196+
error_status=0
197+
if ! build_plugin "$plugin"; then
198+
FAILED_PLUGINS+=("$plugin")
199+
error_status=1
200+
fi
201+
202+
if [[ -n "$GITHUB_ACTIONS" ]]; then
203+
echo "::endgroup::"
204+
fi
205+
206+
if [ $error_status -ne 0 ]; then
207+
# TODO: if not '--build-all' used
208+
exit 1
209+
fi
210+
done
211+
212+
# Show summary of any failures (if using continue-on-error approach)
213+
if [ ${#FAILED_PLUGINS[@]} -gt 0 ]; then
214+
if [[ -n "$GITHUB_ACTIONS" ]]; then
215+
echo "::group::❌ Build Failures Summary"
216+
else
217+
echo "❌ Build Failures Summary"
218+
echo "=========================================="
219+
fi
220+
221+
echo "The following plugins failed to build:"
222+
for failed_plugin in "${FAILED_PLUGINS[@]}"; do
223+
echo "$failed_plugin"
224+
done
225+
226+
if [[ -n "$GITHUB_ACTIONS" ]]; then
227+
echo "::endgroup::"
228+
else
229+
echo "=========================================="
230+
fi
231+
exit 1
232+
fi

0 commit comments

Comments
 (0)