qoriq: add kernel 6.1 support
[openwrt/openwrt.git] / .github / workflows / build.yml
1 name: Build sub target
2
3 on:
4 workflow_call:
5 inputs:
6 target:
7 required: true
8 type: string
9 testing:
10 type: boolean
11 build_toolchain:
12 type: boolean
13 include_feeds:
14 type: boolean
15 build_full:
16 type: boolean
17 build_kernel:
18 type: boolean
19 build_all_modules:
20 type: boolean
21 build_all_kmods:
22 type: boolean
23 build_all_boards:
24 type: boolean
25 use_openwrt_container:
26 type: boolean
27 default: true
28
29 permissions:
30 contents: read
31
32 jobs:
33 setup_build:
34 name: Setup build ${{ inputs.target }}
35 runs-on: ubuntu-latest
36 outputs:
37 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
38 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
39 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
40
41 steps:
42 - name: Checkout
43 uses: actions/checkout@v3
44
45 - name: Set lower case owner name
46 id: lower_owner
47 run: |
48 OWNER_LC=$(echo "${{ github.repository_owner }}" \
49 | tr '[:upper:]' '[:lower:]')
50
51 if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
52 OWNER_LC=openwrt
53 fi
54
55 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
56
57 - name: Generate ccache hash
58 id: ccache_hash
59 run: |
60 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
61 | md5sum | awk '{ print $1 }')
62 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
63
64 # Per branch tools container tag
65 # By default stick to latest
66 # For official test targetting openwrt stable branch
67 # Get the branch or parse the tag and push dedicated tools containers
68 # For local test to use the correct container for stable release testing
69 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
70 - name: Determine tools container tag
71 id: determine_tools_container
72 run: |
73 CONTAINER_TAG=latest
74 if [ -n "${{ github.base_ref }}" ]; then
75 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
76 CONTAINER_TAG="${{ github.base_ref }}"
77 fi
78 elif [ ${{ github.ref_type }} == "branch" ]; then
79 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
80 CONTAINER_TAG=${{ github.ref_name }}
81 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
82 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
83 fi
84 elif [ ${{ github.ref_type }} == "tag" ]; then
85 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
86 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
87 fi
88 fi
89 echo "Tools container to use tools:$CONTAINER_TAG"
90 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
91
92 build:
93 name: Build ${{ inputs.target }}
94 needs: setup_build
95 runs-on: ubuntu-latest
96
97 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
98
99 permissions:
100 contents: read
101 packages: read
102
103 steps:
104 - name: Checkout master directory
105 uses: actions/checkout@v3
106 with:
107 path: openwrt
108
109 - name: Checkout packages feed
110 if: inputs.include_feeds == true
111 uses: actions/checkout@v3
112 with:
113 repository: openwrt/packages
114 path: openwrt/feeds/packages
115
116 - name: Checkout luci feed
117 if: inputs.include_feeds == true
118 uses: actions/checkout@v3
119 with:
120 repository: openwrt/luci
121 path: openwrt/feeds/luci
122
123 - name: Checkout routing feed
124 if: inputs.include_feeds == true
125 uses: actions/checkout@v3
126 with:
127 repository: openwrt/routing
128 path: openwrt/feeds/routing
129
130 - name: Checkout telephony feed
131 if: inputs.include_feeds == true
132 uses: actions/checkout@v3
133 with:
134 repository: openwrt/telephony
135 path: openwrt/feeds/telephony
136
137 - name: Fix permission
138 run: |
139 chown -R buildbot:buildbot openwrt
140
141 - name: Initialization environment
142 run: |
143 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
144 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
145 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
146 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
147
148 - name: Prepare prebuilt tools
149 shell: su buildbot -c "sh -e {0}"
150 working-directory: openwrt
151 run: |
152 mkdir -p staging_dir build_dir
153 ln -s /prebuilt_tools/staging_dir/host staging_dir/host
154 ln -s /prebuilt_tools/build_dir/host build_dir/host
155
156 ./scripts/ext-tools.sh --refresh
157
158 - name: Update & Install feeds
159 if: inputs.include_feeds == true
160 shell: su buildbot -c "sh -e {0}"
161 working-directory: openwrt
162 run: |
163 ./scripts/feeds update -a
164 ./scripts/feeds install -a
165
166 - name: Parse toolchain file
167 if: inputs.build_toolchain == false
168 id: parse-toolchain
169 working-directory: openwrt
170 run: |
171 TOOLCHAIN_PATH=snapshots
172
173 if [ -n "${{ github.base_ref }}" ]; then
174 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
175 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
176 fi
177 elif [ "${{ github.ref_type }}" = "branch" ]; then
178 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
179 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
180 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
181 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
182 fi
183 elif [ "${{ github.ref_type }}" = "tag" ]; then
184 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
185 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
186 fi
187 fi
188
189 if [ -n "$major_ver" ]; then
190 git fetch --tags -f
191 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
192 if [ -n "$latest_tag" ]; then
193 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
194 fi
195 fi
196
197 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
198 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
199 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
200 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
201
202 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
203 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
204 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
205 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
206
207 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
208 else
209 echo "toolchain-type=internal" >> $GITHUB_OUTPUT
210 fi
211
212 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
213 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
214
215 - name: Cache ccache
216 uses: actions/cache@v3
217 with:
218 path: openwrt/.ccache
219 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
220 restore-keys: |
221 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
222
223 - name: Download external toolchain/sdk
224 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal'
225 shell: su buildbot -c "sh -e {0}"
226 working-directory: openwrt
227 run: |
228 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
229 | tar --xz -xf -
230
231 - name: Configure testing kernel
232 if: inputs.testing == true
233 shell: su buildbot -c "sh -e {0}"
234 working-directory: openwrt
235 run: |
236 echo CONFIG_TESTING_KERNEL=y >> .config
237
238 - name: Configure all kernel modules
239 if: inputs.build_all_kmods == true
240 shell: su buildbot -c "sh -e {0}"
241 working-directory: openwrt
242 run: |
243 echo CONFIG_ALL_KMODS=y >> .config
244
245 - name: Configure all modules
246 if: inputs.build_all_modules == true
247 shell: su buildbot -c "sh -e {0}"
248 working-directory: openwrt
249 run: |
250 echo CONFIG_ALL=y >> .config
251
252 - name: Configure all boards
253 if: inputs.build_all_boards == true
254 shell: su buildbot -c "sh -e {0}"
255 working-directory: openwrt
256 run: |
257 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
258 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
259 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
260
261 - name: Configure external toolchain
262 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
263 shell: su buildbot -c "sh -e {0}"
264 working-directory: openwrt
265 run: |
266 echo CONFIG_DEVEL=y >> .config
267 echo CONFIG_AUTOREMOVE=y >> .config
268 echo CONFIG_CCACHE=y >> .config
269
270 ./scripts/ext-toolchain.sh \
271 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
272 --overwrite-config \
273 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
274
275 - name: Adapt external sdk to external toolchain format
276 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
277 shell: su buildbot -c "sh -e {0}"
278 working-directory: openwrt
279 run: |
280 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
281 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
282 OPENWRT_DIR=$(pwd)
283
284 # Find target name from toolchain info.mk
285 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
286
287 cd $TOOLCHAIN_BIN
288
289 # Revert sdk wrapper scripts applied to all the bins
290 for app in $(find . -name "*.bin"); do
291 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
292 rm $TARGET_APP
293 mv .$TARGET_APP.bin $TARGET_APP
294 done
295
296 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
297 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
298 for app in cc gcc g++ c++ cpp ld as ; do
299 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
300 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
301 done
302
303 - name: Configure external toolchain with sdk
304 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
305 shell: su buildbot -c "sh -e {0}"
306 working-directory: openwrt
307 run: |
308 echo CONFIG_DEVEL=y >> .config
309 echo CONFIG_AUTOREMOVE=y >> .config
310 echo CONFIG_CCACHE=y >> .config
311
312 ./scripts/ext-toolchain.sh \
313 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
314 --overwrite-config \
315 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
316
317 - name: Configure internal toolchain
318 if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
319 shell: su buildbot -c "sh -e {0}"
320 working-directory: openwrt
321 run: |
322 echo CONFIG_DEVEL=y >> .config
323 echo CONFIG_AUTOREMOVE=y >> .config
324 echo CONFIG_CCACHE=y >> .config
325
326 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
327 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
328
329 make defconfig
330
331 - name: Show configuration
332 shell: su buildbot -c "sh -e {0}"
333 working-directory: openwrt
334 run: ./scripts/diffconfig.sh
335
336 - name: Build tools
337 shell: su buildbot -c "sh -e {0}"
338 working-directory: openwrt
339 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
340
341 - name: Build toolchain
342 shell: su buildbot -c "sh -e {0}"
343 working-directory: openwrt
344 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
345
346 - name: Build Kernel
347 if: inputs.build_kernel == true
348 shell: su buildbot -c "sh -e {0}"
349 working-directory: openwrt
350 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
351
352 - name: Build Kernel Kmods
353 if: inputs.build_kernel == true
354 shell: su buildbot -c "sh -e {0}"
355 working-directory: openwrt
356 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
357
358 - name: Build everything
359 if: inputs.build_full == true
360 shell: su buildbot -c "sh -e {0}"
361 working-directory: openwrt
362 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
363
364 - name: Upload logs
365 if: failure()
366 uses: actions/upload-artifact@v3
367 with:
368 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
369 path: "openwrt/logs"