Skip to content

Commit 5f70823

Browse files
BujSetZephyrUserGithub Executorch
authored
Arm Zephyr cmake Preset (#11923)
### Summary This change adds a cmake preset for Arm Zephyr RTOS toolchain. This requires the toolchain cmake compilation target to be added to `PATH` (see #12077 for more details). This change includes update to CI flows, modifying the CI `build_size_test` to run the test using either arm bare metal or Zephyr toolchains. Additionally, the CI for building presets is updated to target the new cmake Zephyr preset. ### Test plan Tested with `test/build_size_test.sh` to determine the correct threshold for running the size test for the arm zephyr toolchain. When the CI runs the size test for the arm zephyr toolchain, the new cmake preset is used directly. The following commands are run by the CI, and can be manually invoked to confirm functionality: ``` CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0" cmake --preset zephyr -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_OPTIMIZE_SIZE=ON -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out . cmake --build cmake-out -j9 --target install --config Release CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0" cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$(realpath examples/zephyr/arm-x86-64-eabi-gcc.cmake) -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test cmake --build cmake-out/test -j9 --config Release arm-zephyr-eabi-strip cmake-out/test/size_test ls -la cmake-out/test/size_test ``` Output should corroborate CI test threshold, reporting a resultant `size_test` binary size of ~125Kb (threshold set to 130KB toin CI test tolerate variability). --------- Co-authored-by: ZephyrUser <zephyruser@gmail.com> Co-authored-by: Github Executorch <github_executorch@arm.com>
1 parent 29858b4 commit 5f70823

File tree

7 files changed

+234
-13
lines changed

7 files changed

+234
-13
lines changed

.ci/scripts/setup-arm-baremetal-tools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
# Setup arm example environment (including TOSA tools)
99
git config --global user.email "github_executorch@arm.com"
1010
git config --global user.name "Github Executorch"
11-
bash examples/arm/setup.sh --i-agree-to-the-contained-eula
11+
bash examples/arm/setup.sh --i-agree-to-the-contained-eula ${@:-}

.github/workflows/build-presets.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,45 @@ jobs:
3434
${CONDA_RUN} cmake --preset ${{ matrix.preset }}
3535
${CONDA_RUN} cmake --build cmake-out -j$(( $(sysctl -n hw.ncpu) - 1 ))
3636
37+
zephyr:
38+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
preset: [zephyr]
43+
with:
44+
job-name: build
45+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
46+
runner: linux.2xlarge
47+
docker-image: executorch-ubuntu-22.04-arm-sdk
48+
submodules: recursive
49+
timeout: 90
50+
script: |
51+
set -eux
52+
# The generic Linux job chooses to use base env, not the one setup by the image
53+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
54+
conda activate "${CONDA_ENV}"
55+
56+
./install_requirements.sh > /dev/null
57+
58+
# Download toolchain
59+
toolchain_url="https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.2/toolchain_linux-x86_64_arm-zephyr-eabi.tar.xz"
60+
toolchain_dir="arm-zephyr-eabi"
61+
curl --output "${toolchain_dir}.tar.xz" -L "${toolchain_url}"
62+
63+
# Verify download
64+
echo "93128be0235cf5cf5f1ee561aa6eac5f ${toolchain_dir}.tar.xz" > arm-zephyr-eabi.md5
65+
md5sum -c --strict arm-zephyr-eabi.md5
66+
67+
# Extract and install to PATH
68+
tar xf "${toolchain_dir}.tar.xz"
69+
rm -f "${toolchain_dir}.tar.xz"
70+
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)"
71+
export PATH=$PATH:${toolchain_bin_path}
72+
73+
# Build Arm Zephyr Preset
74+
cmake --preset ${{ matrix.preset }}
75+
cmake --build cmake-out -j$(( $(nproc) - 1 ))
3776
linux:
3877
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
3978
strategy:

.github/workflows/trunk.yml

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ jobs:
223223
permissions:
224224
id-token: write
225225
contents: read
226+
strategy:
227+
matrix:
228+
os: [bare_metal, zephyr-preset]
229+
fail-fast: false
226230
with:
227231
runner: linux.2xlarge
228232
docker-image: executorch-ubuntu-22.04-arm-sdk
@@ -234,35 +238,62 @@ jobs:
234238
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
235239
conda activate "${CONDA_ENV}"
236240
241+
cxx_flags="-fno-exceptions -fno-rtti -Wall -Werror -Wno-int-in-bool-context -DET_HAVE_PREAD=0"
242+
setup_script_args=""
243+
if [[ ${{ matrix.os}} == "bare_metal" ]]; then
244+
toolchain_prefix=arm-none-eabi-
245+
threshold="103268" # ~100KiB
246+
toolchain_cmake=examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
247+
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then
248+
setup_script_args="--target-toolchain zephyr"
249+
toolchain_prefix=arm-zephyr-eabi-
250+
threshold="133120" # should be ~125KB, set threshold to 130KB
251+
toolchain_cmake=examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
252+
else
253+
echo "Fail unsupport OS selection ${{ matrix.os }}"
254+
exit 1
255+
fi
256+
237257
source .ci/scripts/utils.sh
238258
install_executorch "--use-pt-pinned-commit"
239-
.ci/scripts/setup-arm-baremetal-tools.sh
259+
.ci/scripts/setup-arm-baremetal-tools.sh ${setup_script_args}
240260
source examples/arm/ethos-u-scratch/setup_path.sh
241261
242-
# User baremetal toolchain
243-
arm-none-eabi-c++ --version
244-
toolchain_cmake=examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
262+
# User toolchain
263+
${toolchain_prefix}c++ --version
264+
265+
# Setup cmake target to desired toolchain
245266
toolchain_cmake=$(realpath ${toolchain_cmake})
246267
247-
# Build and test size test
248-
bash test/build_size_test.sh "-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON"
268+
# Build and run size test
269+
if [[ ${{ matrix.os}} == "bare_metal" ]]; then
270+
bash test/build_size_test.sh "-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON"
271+
elif [[ ${{ matrix.os}} == "zephyr-preset" ]]; then
272+
CXXFLAGS=${cxx_flags} cmake --preset zephyr -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_OPTIMIZE_SIZE=ON -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out .
273+
cmake --build cmake-out -j9 --target install --config Release
274+
CXXFLAGS=${cxx_flags} cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test
275+
cmake --build cmake-out/test -j9 --config Release
276+
else
277+
echo "Fail unsupport OS selection ${{ matrix.os }}"
278+
exit 1
279+
fi
280+
249281
elf="cmake-out/test/size_test"
250282
251283
# Dump basic info
252284
ls -al ${elf}
253-
arm-none-eabi-size ${elf}
285+
${toolchain_prefix}size ${elf}
254286
255-
# Dump symbols
287+
# Dump symbol
256288
python .github/scripts/run_nm.py -e ${elf}
257-
python .github/scripts/run_nm.py -e ${elf} -f "executorch" -p "arm-none-eabi-"
258-
python .github/scripts/run_nm.py -e ${elf} -f "executorch_text" -p "arm-none-eabi-"
289+
python .github/scripts/run_nm.py -e ${elf} -f "executorch" -p "${toolchain_prefix}"
290+
python .github/scripts/run_nm.py -e ${elf} -f "executorch_text" -p "${toolchain_prefix}"
259291
260292
# Add basic guard - TODO: refine this!
261-
arm-none-eabi-strip ${elf}
293+
${toolchain_prefix}strip ${elf}
262294
output=$(ls -la ${elf})
263295
arr=($output)
264296
size=${arr[4]}
265-
threshold="103268" # ~100KiB
266297
echo "size: $size, threshold: $threshold"
267298
if [[ "$size" -le "$threshold" ]]; then
268299
echo "Success $size <= $threshold"

CMakePresets.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@
104104
"Windows"
105105
]
106106
}
107+
},
108+
{
109+
"name": "zephyr",
110+
"displayName": "Build everything buildable on Zephyr RTOS",
111+
"inherits": [
112+
"common"
113+
],
114+
"cacheVariables": {
115+
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/zephyr.cmake",
116+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake"
117+
}
107118
}
108119
]
109120
}

examples/arm/setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function select_toolchain() {
242242
fi
243243
echo "[main] Info selected ${toolchain_dir} for ${ARCH} - ${OS} platform"
244244
}
245+
245246
function setup_toolchain() {
246247
# Download and install the arm toolchain (default is arm-none-eabi)
247248
# setting --target-toolchain to zephyr sets this to arm-zephyr-eabi
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#
2+
# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the License); you may
7+
# not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And
20+
# modified to align better with cs300 platform
21+
22+
set(TARGET_CPU
23+
"cortex-m55"
24+
CACHE STRING "Target CPU"
25+
)
26+
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
27+
28+
set(CMAKE_SYSTEM_NAME Generic)
29+
set(CMAKE_C_COMPILER "arm-zephyr-eabi-gcc")
30+
set(CMAKE_CXX_COMPILER "arm-zephyr-eabi-g++")
31+
set(CMAKE_ASM_COMPILER "arm-zephyr-eabi-gcc")
32+
set(CMAKE_LINKER "arm-zephyr-eabi-ld")
33+
34+
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
35+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
36+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
37+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
38+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
39+
40+
# Select C/C++ version
41+
set(CMAKE_C_STANDARD 11)
42+
set(CMAKE_CXX_STANDARD 17)
43+
44+
set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
45+
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})
46+
47+
# Compile options
48+
add_compile_options(
49+
-mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>"
50+
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
51+
-fdata-sections -ffunction-sections
52+
)
53+
54+
# Compile defines
55+
add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
56+
57+
# Link options
58+
add_link_options(-mcpu=${GCC_CPU} -mthumb)
59+
60+
if(SEMIHOSTING)
61+
add_link_options(--specs=rdimon.specs)
62+
else()
63+
add_link_options(--specs=nosys.specs)
64+
endif()
65+
66+
# Set floating point unit
67+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
68+
set(FLOAT hard)
69+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
70+
set(FLOAT soft)
71+
elseif(
72+
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)"
73+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)"
74+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)"
75+
)
76+
set(FLOAT hard)
77+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)"
78+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)"
79+
)
80+
set(FLOAT hard)
81+
set(FPU_CONFIG "fpv4-sp-d16")
82+
add_compile_options(-mfpu=${FPU_CONFIG})
83+
add_link_options(-mfpu=${FPU_CONFIG})
84+
else()
85+
set(FLOAT soft)
86+
endif()
87+
88+
if(FLOAT)
89+
add_compile_options(-mfloat-abi=${FLOAT})
90+
add_link_options(-mfloat-abi=${FLOAT})
91+
endif()
92+
93+
add_link_options(LINKER:--nmagic,--gc-sections)
94+
95+
# Compilation warnings
96+
add_compile_options(
97+
# -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat
98+
# -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow
99+
# -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls
100+
-Wno-stringop-overread
101+
-Wno-error=format=
102+
-Wno-error=maybe-uninitialized
103+
-Wno-error=deprecated-declarations
104+
-Wno-error=shift-count-overflow
105+
-Wno-psabi
106+
)

tools/cmake/preset/zephyr.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set_overridable_option(EXECUTORCH_BUILD_COREML OFF)
9+
set_overridable_option(EXECUTORCH_ENABLE_EVENT_TRACER OFF)
10+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM OFF)
11+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT OFF)
12+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER OFF)
13+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR OFF)
14+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_LLM OFF)
15+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE OFF)
16+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TRAINING OFF)
17+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE OFF)
18+
set_overridable_option(EXECUTORCH_BUILD_MPS OFF)
19+
set_overridable_option(EXECUTORCH_BUILD_NEURON OFF)
20+
set_overridable_option(EXECUTORCH_BUILD_OPENVINO OFF)
21+
set_overridable_option(EXECUTORCH_BUILD_PYBIND OFF)
22+
set_overridable_option(EXECUTORCH_BUILD_QNN OFF)
23+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED OFF)
24+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED OFF)
25+
set_overridable_option(EXECUTORCH_BUILD_DEVTOOLS OFF)
26+
set_overridable_option(EXECUTORCH_BUILD_TESTS OFF)
27+
set_overridable_option(EXECUTORCH_BUILD_XNNPACK OFF)
28+
set_overridable_option(EXECUTORCH_BUILD_VULKAN OFF)
29+
set_overridable_option(EXECUTORCH_BUILD_PORTABLE_OPS ON)
30+
set_overridable_option(EXECUTORCH_BUILD_CADENCE OFF)
31+
set_overridable_option(EXECUTORCH_BUILD_PTHREADPOOL OFF)
32+
set_overridable_option(EXECUTORCH_BUILD_CPUINFO OFF)
33+
set_overridable_option(EXECUTORCH_USE_CPP_CODE_COVERAGE OFF)

0 commit comments

Comments
 (0)