Skip to content

Commit f83bea2

Browse files
committed
Updated Windows build script
1 parent 92d70f5 commit f83bea2

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

scripts/build-app.cmd

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
:: Windows script to build Rust application hosted on Mynewt OS
22

3+
:: TODO: STM32L4
4+
set mynewt_build_app=stm32l4_my_sensor
5+
set rust_build_target=thumbv7em-none-eabihf
6+
copy /y .vscode\launch-stm32l4.json .vscode\launch.json
7+
8+
:: TODO: STM32 Blue Pill
9+
:: set mynewt_build_app=bluepill_my_sensor
10+
:: ser rust_build_target=%rust_build_target%
11+
:: copy /y .vscode\launch-bluepill.json .vscode\launch.json
12+
313
@echo "----- Building Rust app and Mynewt OS..."
414

515
:: Rust build profile: debug or release
6-
:: set rust_build_profile=debug
7-
set rust_build_profile=release
16+
set rust_build_profile=debug
17+
:: set rust_build_profile=release
818

919
:: Location of the compiled ROM image. We will remove this to force relinking the Rust app with Mynewt OS.
10-
set app_build=%cd%\bin\targets\bluepill_my_sensor\app\apps\my_sensor_app\my_sensor_app.elf
20+
set app_build=%cd%\bin\targets\%mynewt_build_app%\app\apps\my_sensor_app\my_sensor_app.elf
1121

1222
:: Location of the compiled Rust app and external libraries. The Rust compiler generates a *.rlib archive for the Rust app and each external Rust library here.
13-
set rust_build_dir=%cd%\target\thumbv7m-none-eabi\%rust_build_profile%\deps
23+
set rust_build_dir=%cd%\target\%rust_build_target%\%rust_build_profile%\deps
1424

1525
:: Location of the libs\rust_app stub library built by Mynewt. We will replace this stub by the Rust app and external libraries.
16-
set rust_app_dir=%cd%\bin\targets\bluepill_my_sensor\app\libs\rust_app
26+
set rust_app_dir=%cd%\bin\targets\%mynewt_build_app%\app\libs\rust_app
1727
set rust_app_dest=%rust_app_dir%\libs_rust_app.a
1828

1929
:: Location of the libs\rust_libcore stub library built by Mynewt. We will replace this stub by the Rust core library libcore.
20-
set rust_libcore_dir=%cd%\bin\targets\bluepill_my_sensor\app\libs\rust_libcore
30+
set rust_libcore_dir=%cd%\bin\targets\%mynewt_build_app%\app\libs\rust_libcore
2131
set rust_libcore_dest=%rust_libcore_dir%\libs_rust_libcore.a
2232

2333
if %rust_build_profile%==release (
@@ -31,7 +41,7 @@ if %rust_build_profile%==release (
3141
:: If this is the very first build, do the Mynewt build to generate the rust_app and rust_libcore stubs. This build will not link successfully but it's OK.
3242
if not exist %rust_app_dest% (
3343
@echo "----- Build Mynewt stubs for Rust app and Rust libcore (ignore error)"
34-
newt\newt.exe build bluepill_my_sensor
44+
newt\newt.exe build %mynewt_build_app%
3545
)
3646

3747
:: Delete the compiled ROM image to force the Mynewt build to relink the Rust app with Mynewt OS.
@@ -101,7 +111,7 @@ popd
101111
:: Copy Rust libcore to libs_rust_libcore.a, which is originally generated by libs\rust_libcore.
102112
@echo "----- Copy Rust libcore"
103113
:: Get the Rust compiler sysroot e.g. C:\Users\guppy\.rustup\toolchains\nightly-x86_64-pc-windows-msvc
104-
for /f %%l in ('rustc --print sysroot --target thumbv7m-none-eabi') do set rust_sysroot=%%l
114+
for /f %%l in ('rustc --print sysroot --target %rust_build_target%') do set rust_sysroot=%%l
105115
:: Copy libcore to the Mynewt build folder.
106116
if not exist %rust_libcore_dir% (
107117
mkdir %rust_libcore_dir%
@@ -113,24 +123,24 @@ if exist %rust_libcore_dest% (
113123
)
114124
:: Get the Rust compiler sysroot e.g. C:\Users\guppy\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\thumbv7m-none-eabi\lib\libcore-6ea1de1c8a090cbc.rlib
115125
:: Overwrite our custom libs_rust_libcore.a to inject Rust libcore into the build.
116-
for %%f in (%rust_sysroot%\lib\rustlib\thumbv7m-none-eabi\lib\libcore-*.rlib) do copy %%f %rust_libcore_dest%
126+
for %%f in (%rust_sysroot%\lib\rustlib\%rust_build_target\lib\libcore-*.rlib) do copy %%f %rust_libcore_dest%
117127
if errorlevel 1 goto :EOF
118128

119129
:: Update the timestamp on libs_rust_libcore.a so that Mynewt build won't overwrite the Rust libcore we have copied.
120130
arm-none-eabi-ar s %rust_libcore_dest%
121131
if errorlevel 1 goto :EOF
122132

123133
:: Dump the ELF and disassembly for the compiled Rust application.
124-
arm-none-eabi-readelf -a --wide target\thumbv7m-none-eabi\%rust_build_profile%\libapp.rlib >logs\libapp.elf 2>&1
125-
arm-none-eabi-objdump -t -S --line-numbers --wide target\thumbv7m-none-eabi\%rust_build_profile%\libapp.rlib >logs\libapp.S 2>&1
126-
arm-none-eabi-objdump -t -S --demangle --line-numbers --wide target\thumbv7m-none-eabi\%rust_build_profile%\libapp.rlib >logs\libapp-demangle.S 2>&1
134+
arm-none-eabi-readelf -a --wide target\%rust_build_target%\%rust_build_profile%\libapp.rlib >logs\libapp.elf 2>&1
135+
arm-none-eabi-objdump -t -S --line-numbers --wide target\%rust_build_target%\%rust_build_profile%\libapp.rlib >logs\libapp.S 2>&1
136+
arm-none-eabi-objdump -t -S --demangle --line-numbers --wide target\%rust_build_target%\%rust_build_profile%\libapp.rlib >logs\libapp-demangle.S 2>&1
127137

128138
:: Run the Mynewt build, which will link with the Rust app, Rust libraries and libcore.
129-
:: For verbose build: newt build -v -p bluepill_my_sensor
139+
:: For verbose build: newt build -v -p %mynewt_build_app%
130140
@echo "----- Build and link Mynewt with Rust app"
131-
newt\newt.exe build bluepill_my_sensor
141+
newt\newt.exe build %mynewt_build_app%
132142
if errorlevel 1 goto :EOF
133143

134144
:: Display the image size.
135-
newt\newt.exe size -v bluepill_my_sensor
145+
newt\newt.exe size -v %mynewt_build_app%
136146
if errorlevel 1 goto :EOF

0 commit comments

Comments
 (0)