Skip to content

Commit

Permalink
fix(rust-training-esp32c3): broken builder #56
Browse files Browse the repository at this point in the history
This should fix the builder and will make esp-rs/std-training#168 simpler
  • Loading branch information
SergioGasquez authored Nov 9, 2023
1 parent 810fd42 commit 28a25f3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
21 changes: 10 additions & 11 deletions rust-training-esp32c3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# Base image
FROM espressif/rust-std-training

USER esp
ENV USER=esp

RUN git clone https://github.com/ferrous-systems/espressif-trainings.git espressif-trainings \
&& rm -rf espressif-trainings/book \
&& rm espressif-trainings/intro/hardware-check/Cargo.toml
&& rm -rf espressif-trainings/book

ENV IDF_TOOLS_PATH=/home/esp/.espressif
RUN echo "source /home/esp/.espressif/frameworks/esp-idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
ENV PATH=${PATH}:/home/esp/.cargo/bin

COPY Cargo.toml espressif-trainings/intro/hardware-check/Cargo.toml
COPY sdkconfig.defaults espressif-trainings/intro/hardware-check/sdkconfig.defaults
COPY cfg.toml espressif-trainings/intro/hardware-check/cfg.toml

# Fetch
COPY fetch.sh /home/esp/
RUN bash fetch.sh

# Copy compilation script
COPY sdkconfig.defaults /home/esp/
COPY cfg.toml /home/esp/
COPY compile.sh /home/esp/

RUN mkdir -p /home/esp/build-in /home/esp/build-out

ENV HEXI_SRC_DIR="/home/esp/build-in"
ENV HEXI_SRC_FILES="*.rs"
ENV HEXI_BUILD_CMD="bash /home/esp/compile.sh"
ENV HEXI_OUT_HEX="/home/esp/build-out/project.bin"
ENV HEXI_OUT_ELF="/home/esp/build-out/project.elf"

EXPOSE 8080
COPY --from=wokwi/mini-hexi /wokwi-hexi /wokwi-hexi
CMD /wokwi-hexi
53 changes: 43 additions & 10 deletions rust-training-esp32c3/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,51 @@

set -e

cd espressif-trainings/intro/hardware-check
if [ -f ${HOME}/build-in/main.rs ]; then
cat ${HOME}/build-in/main.rs >src/main.rs
export IDF_TOOLS_PATH=/home/esp/.espressif
. /home/esp/.espressif/frameworks/esp-idf/export.sh
export ESP_IDF_TOOLS_INSTALL_DIR=fromenv

if [ -f ${HOME}/build-in/Cargo.toml ]; then
PROJECT_NAME=$(awk -F= '/name/ {gsub(/^[[:space:]]+|['\''"]|[[:space:]]+$/,"",$2); print $2}' ${HOME}/build-in/Cargo.toml)
case ${PROJECT_NAME} in
"button-interrupt")
PROJECT_PATH="advanced/button-interrupt"
;;
"i2c-driver")
PROJECT_PATH="advanced/i2c-driver"
;;
"i2c-sensor-reading")
PROJECT_PATH="advanced/i2c-sensor-reading"
;;
"hardware-check")
PROJECT_PATH="intro/hardware-check"
;;
"http-client")
PROJECT_PATH="intro/http-client"
;;
"http-server")
PROJECT_PATH="intro/http-server"
;;
"mqtt")
PROJECT_PATH="intro/mqtt/exercise"
;;
*)
echo "Missing or invalid Cargo.toml file"
exit 1
;;
esac
cd espressif-trainings/${PROJECT_PATH}
cp ${HOME}/build-in/Cargo.toml Cargo.toml
fi

if [ -f ${HOME}/build-in/lib.rs ]; then
cat ${HOME}/build-in/lib.rs >src/lib.rs
if [[ ${PROJECT_PATH} == *"intro"* ]]; then
cp /home/esp/cfg.toml .
fi

if [ -f ${HOME}/build-in/imc42670p.rs ]; then
cat ${HOME}/build-in/imc42670p.rs >src/imc42670p.rs
if [ "$(find ${HOME}/build-in -name '*.rs')" ]; then
cp ${HOME}/build-in/*.rs src
fi
cargo build --offline --release
espflash save-image --chip esp32c3 --flash-size 4mb target/riscv32imc-esp-espidf/release/hardware-check ${HOME}/build-out/project.bin
cp target/riscv32imc-esp-espidf/release/hardware-check ${HOME}/build-out/project.elf

cargo build --release
espflash save-image --chip esp32c3 --flash-size 4mb target/riscv32imc-esp-espidf/release/${PROJECT_NAME} ${HOME}/build-out/project.bin
cp target/riscv32imc-esp-espidf/release/${PROJECT_NAME} ${HOME}/build-out/project.elf
8 changes: 0 additions & 8 deletions rust-training-esp32c3/fetch.sh

This file was deleted.

0 comments on commit 28a25f3

Please sign in to comment.