Skip to content

Commit 33702f0

Browse files
committed
scripts: template_setup_win: Add web-based toolchain installation
This commit adds the feature to download and install individual toolchains from the web release assets if not all toolchains are locally installed (e.g. minimal web install distribution archive). Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 0aff0c8 commit 33702f0

File tree

1 file changed

+143
-20
lines changed

1 file changed

+143
-20
lines changed

scripts/template_setup_win

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,53 @@ pushd %~dp0
77
setlocal ENABLEDELAYEDEXPANSION
88
set EXITCODE=0
99

10+
goto entry
11+
12+
REM # Check if command is available
13+
:check_command
14+
where %1 > nul 2>&1
15+
if [%ERRORLEVEL%] neq [0] (
16+
echo Zephyr SDK setup requires '%1' to be installed and available in the PATH.
17+
echo Please install '%1' and run this script again.
18+
19+
set EXITCODE=%2
20+
exit /b 1
21+
)
22+
exit /b 0
23+
24+
:entry
25+
26+
REM # Initialise toolchain list
27+
set TOOLCHAINS=
28+
set TOOLCHAINS=%TOOLCHAINS% aarch64-zephyr-elf
29+
set TOOLCHAINS=%TOOLCHAINS% arc64-zephyr-elf
30+
set TOOLCHAINS=%TOOLCHAINS% arc-zephyr-elf
31+
set TOOLCHAINS=%TOOLCHAINS% arm-zephyr-eabi
32+
set TOOLCHAINS=%TOOLCHAINS% mips-zephyr-elf
33+
set TOOLCHAINS=%TOOLCHAINS% nios2-zephyr-elf
34+
set TOOLCHAINS=%TOOLCHAINS% riscv64-zephyr-elf
35+
set TOOLCHAINS=%TOOLCHAINS% sparc-zephyr-elf
36+
set TOOLCHAINS=%TOOLCHAINS% x86_64-zephyr-elf
37+
set TOOLCHAINS=%TOOLCHAINS% xtensa-espressif_esp32_zephyr-elf
38+
set TOOLCHAINS=%TOOLCHAINS% xtensa-espressif_esp32s2_zephyr-elf
39+
set TOOLCHAINS=%TOOLCHAINS% xtensa-intel_apl_adsp_zephyr-elf
40+
set TOOLCHAINS=%TOOLCHAINS% xtensa-intel_bdw_adsp_zephyr-elf
41+
set TOOLCHAINS=%TOOLCHAINS% xtensa-intel_byt_adsp_zephyr-elf
42+
set TOOLCHAINS=%TOOLCHAINS% xtensa-intel_s1000_zephyr-elf
43+
set TOOLCHAINS=%TOOLCHAINS% xtensa-nxp_imx_adsp_zephyr-elf
44+
set TOOLCHAINS=%TOOLCHAINS% xtensa-nxp_imx8m_adsp_zephyr-elf
45+
set TOOLCHAINS=%TOOLCHAINS% xtensa-sample_controller_zephyr-elf
46+
47+
REM Initialise list of toolchains to install
48+
set INST_TOOLCHAINS=
49+
1050
REM # Read bundle version from file
1151
set /p VERSION=<sdk_version
1252

53+
REM # Resolve release download base URI
54+
set DL_REL_BASE=https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v%VERSION%
55+
set DL_TOOLCHAIN_FILENAME=toolchain_windows-x86_64_%%t.zip
56+
1357
REM # Print banner
1458
echo Zephyr SDK %VERSION% Setup
1559
echo.
@@ -20,14 +64,13 @@ if [%1] equ [] (
2064
)
2165

2266
REM # Check dependencies
23-
where cmake > nul 2>&1
24-
if [%ERRORLEVEL%] neq [0] (
25-
echo Zephyr SDK setup requires CMake to be installed and available in the PATH.
26-
echo Please install CMake and run this script again.
2767

28-
set EXITCODE=90
29-
goto end
30-
)
68+
call :check_command cmake 90
69+
if [%ERRORLEVEL%] neq [0] goto end
70+
call :check_command wget 91
71+
if [%ERRORLEVEL%] neq [0] goto end
72+
call :check_command unzip 92
73+
if [%ERRORLEVEL%] neq [0] goto end
3174

3275
REM # Enter interactive mode if enabled
3376
if [%INTERACTIVE%] neq [] (
@@ -36,10 +79,25 @@ if [%INTERACTIVE%] neq [] (
3679

3780
REM # Parse arguments if specified
3881
:parsearg
39-
if /i [%1] equ [/c] (
40-
set DO_CMAKE_PKG=y
41-
) else if /i [%1] equ [/t] (
82+
if /i [%1] equ [/t] (
83+
if [%2] equ [all] (
84+
set INST_TOOLCHAINS=%TOOLCHAINS%
85+
) else (
86+
set IS_VALID=
87+
for %%t in (%TOOLCHAINS%) do if [%%t] equ [%2] set IS_VALID=y
88+
if [!IS_VALID!] equ [y] (
89+
set INST_TOOLCHAINS=!INST_TOOLCHAINS! %2
90+
) else (
91+
echo ERROR: Unknown toolchain '%2'
92+
set EXITCODE=2
93+
goto end
94+
)
95+
)
96+
shift
97+
) else if /i [%1] equ [/h] (
4298
set DO_HOSTTOOLS=y
99+
) else if /i [%1] equ [/c] (
100+
set DO_CMAKE_PKG=y
43101
) else (
44102
goto usage
45103
)
@@ -58,21 +116,67 @@ echo You only need to run this script once after extracting the Zephyr SDK
58116
echo distribution bundle archive.
59117
echo.
60118

119+
REM # Check installation type
120+
for %%t in (%TOOLCHAINS%) do (
121+
if not exist %%t\ (
122+
set IS_PARTIAL_SDK=y
123+
)
124+
)
125+
61126
REM # Ask user for set-up choices
62-
choice /c:yn /m:"Register Zephyr SDK CMake package"
63-
if [%ERRORLEVEL%] equ [1] set DO_CMAKE_PKG=y
127+
if [%IS_PARTIAL_SDK%] neq [] (
128+
choice /c:yn /m:"Install toolchains for all targets"
129+
if [!ERRORLEVEL!] equ [1] (
130+
set INST_TOOLCHAINS=%TOOLCHAINS%
131+
) else (
132+
for %%t in (%TOOLCHAINS%) do (
133+
if not exist %%t\ (
134+
choice /c:yn /m:"Install '%%t' toolchain"
135+
if [!ERRORLEVEL!] equ [1] (
136+
set INST_TOOLCHAINS=!INST_TOOLCHAINS! %%t
137+
)
138+
)
139+
)
140+
)
141+
)
64142

65143
choice /c:yn /m:"Install host tools"
66144
if [%ERRORLEVEL%] equ [1] set DO_HOSTTOOLS=y
67145

146+
choice /c:yn /m:"Register Zephyr SDK CMake package"
147+
if [%ERRORLEVEL%] equ [1] set DO_CMAKE_PKG=y
148+
68149
echo.
69150

70151
:process
71-
REM # Register Zephyr SDK CMake package
72-
if [%DO_CMAKE_PKG%] neq [] (
73-
echo Registering Zephyr SDK CMake package ...
74-
cmake -P cmake\zephyr_sdk_export.cmake
75-
echo.
152+
REM # Install toolchains
153+
for %%t in (%INST_TOOLCHAINS%) do (
154+
set TOOLCHAIN_FILENAME=%DL_TOOLCHAIN_FILENAME%
155+
set TOOLCHAIN_URI=%DL_REL_BASE%/!TOOLCHAIN_FILENAME!
156+
157+
if not exist %%t\ (
158+
echo Installing '%%t' toolchain ...
159+
160+
REM # Download toolchain archive
161+
wget -q --show-progress -N -O !TOOLCHAIN_FILENAME! !TOOLCHAIN_URI!
162+
if [!ERRORLEVEL!] neq [0] (
163+
del /q !TOOLCHAIN_FILENAME!
164+
echo ERROR: Toolchain download failed
165+
set EXITCODE=20
166+
goto end
167+
)
168+
169+
REM # Extract archive
170+
unzip -q !TOOLCHAIN_FILENAME!
171+
if [!ERRORLEVEL!] neq [0] (
172+
echo ERROR: Toolchain archive extraction failed
173+
set EXITCODE=21
174+
goto end
175+
)
176+
177+
REM # Remove archive
178+
del /q !TOOLCHAIN_FILENAME!
179+
)
76180
)
77181

78182
REM # Install host tools
@@ -82,15 +186,34 @@ if [%DO_HOSTTOOLS%] neq [] (
82186
echo.
83187
)
84188

189+
REM # Register Zephyr SDK CMake package
190+
if [%DO_CMAKE_PKG%] neq [] (
191+
echo Registering Zephyr SDK CMake package ...
192+
cmake -P cmake\zephyr_sdk_export.cmake
193+
if [!ERRORLEVEL!] neq [0] (
194+
set EXITCODE=40
195+
goto end
196+
)
197+
echo.
198+
)
199+
85200
echo All done.
86201
goto end
87202

88203
REM # Print scripting mode usage
89204
:usage
90-
echo %~n0 [/c] [/t]
205+
echo %~n0 [/t ^<toolchain^>] [/h] [/c]
206+
echo.
207+
echo /t ^<toolchain^> Install specified toolchain
208+
echo all Install all toolchains
209+
echo /h Install host tools
210+
echo /c Register Zephyr SDK CMake package
91211
echo.
92-
echo /c Register Zephyr SDK CMake package
93-
echo /t Install host tools
212+
echo Supported Toolchains:
213+
echo.
214+
for %%t in (%TOOLCHAINS%) do (
215+
echo %%t
216+
)
94217
echo.
95218
echo When no arguments are specified, the setup script runs in the interactive
96219
echo mode asking for user inputs.

0 commit comments

Comments
 (0)