diff --git a/.gitignore b/.gitignore index 2feaf34..209914f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,15 @@ target Cargo.lock node_modules/ rust/src/webserver/bundle.js +rust/src/webserver/bundle.js.gz rust/src/webserver/index.html +rust/src/webserver/index.html.gz +rust/src_webpack/bundle.js +rust/src_webpack/bundle.js.gz +rust/src_webpack/index.html +rust/src_webpack/index.html.gz rust/build/ rust/image.bin +rust/target/ +rust/Cargo.lock +rust/src_webpack/node_modules/ diff --git a/rust/all.sh b/rust/all.sh new file mode 100755 index 0000000..befcff7 --- /dev/null +++ b/rust/all.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +"${SCRIPT_DIR}/build_website.sh" + +cargo build --release +espflash save-image \ + --bootloader "${SCRIPT_DIR}/bootloader.bin" \ + --partition-table "${SCRIPT_DIR}/partitions.csv" \ + --chip esp32c6 \ + target/riscv32imac-unknown-none-elf/release/plant-ctrl2 \ + "${SCRIPT_DIR}/image.bin" + +espflash flash --monitor \ + --bootloader "${SCRIPT_DIR}/bootloader.bin" \ + --chip esp32c6 \ + --baud 921600 \ + --partition-table "${SCRIPT_DIR}/partitions.csv" \ + target/riscv32imac-unknown-none-elf/release/plant-ctrl2 diff --git a/rust/build.rs b/rust/build.rs index 05b5381..ec20e04 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -1,5 +1,3 @@ -use std::process::Command; - use vergen::EmitBuilder; fn linker_be_nice() { @@ -50,72 +48,9 @@ fn linker_be_nice() { } fn main() { - webpack(); linker_be_nice(); + // Non-existent path causes Cargo to always re-run this script, + // keeping VERGEN_BUILD_TIMESTAMP fresh on every build. + println!("cargo:rerun-if-changed=ALWAYS_REBUILD_SENTINEL"); let _ = EmitBuilder::builder().all_git().all_build().emit(); } - -fn webpack() { - //println!("cargo:rerun-if-changed=./src/src_webpack"); - Command::new("rm") - .arg("./src/webserver/bundle.js.gz") - .output() - .unwrap(); - - match Command::new("cmd").spawn() { - Ok(_) => { - println!("Assuming build on windows"); - let output = Command::new("cmd") - .arg("/K") - .arg("npx") - .arg("webpack") - .current_dir("./src_webpack") - .output() - .unwrap(); - println!("status: {}", output.status); - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); - assert!(output.status.success()); - - // move webpack results to rust webserver src - let _ = Command::new("cmd") - .arg("/K") - .arg("move") - .arg("./src_webpack/bundle.js.gz") - .arg("./src/webserver") - .output() - .unwrap(); - let _ = Command::new("cmd") - .arg("/K") - .arg("move") - .arg("./src_webpack/index.html.gz") - .arg("./src/webserver") - .output() - .unwrap(); - } - Err(_) => { - println!("Assuming build on linux"); - let output = Command::new("npx") - .arg("webpack") - .current_dir("./src_webpack") - .output() - .unwrap(); - println!("status: {}", output.status); - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); - assert!(output.status.success()); - - // move webpack results to rust webserver src - let _ = Command::new("mv") - .arg("./src_webpack/bundle.js.gz") - .arg("./src/webserver") - .output() - .unwrap(); - let _ = Command::new("mv") - .arg("./src_webpack/index.html.gz") - .arg("./src/webserver") - .output() - .unwrap(); - } - } -} diff --git a/rust/build_website.sh b/rust/build_website.sh new file mode 100755 index 0000000..c198aef --- /dev/null +++ b/rust/build_website.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +WEBPACK_DIR="${SCRIPT_DIR}/src_webpack" +WEBSERVER_DIR="${SCRIPT_DIR}/src/webserver" + +rm -f "${WEBSERVER_DIR}/index.html.gz" +rm -f "${WEBSERVER_DIR}/bundle.js.gz" +rm -f "${WEBPACK_DIR}/index.html.gz" +rm -f "${WEBPACK_DIR}/bundle.js.gz" +rm -f "${WEBPACK_DIR}/index.html" +rm -f "${WEBPACK_DIR}/bundle.js" + +pushd "${WEBPACK_DIR}" +npm install +npx webpack build +cp index.html.gz "${WEBSERVER_DIR}/index.html.gz" +cp bundle.js.gz "${WEBSERVER_DIR}/bundle.js.gz" +popd diff --git a/rust/erase_ota.sh b/rust/erase_ota.sh new file mode 100755 index 0000000..079ce36 --- /dev/null +++ b/rust/erase_ota.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +cargo espflash erase-parts otadata --partition-table "${SCRIPT_DIR}/partitions.csv" diff --git a/rust/flash.sh b/rust/flash.sh new file mode 100755 index 0000000..67ad0ac --- /dev/null +++ b/rust/flash.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +"${SCRIPT_DIR}/build_website.sh" + +cargo build --release +espflash flash --monitor \ + --bootloader "${SCRIPT_DIR}/bootloader.bin" \ + --chip esp32c6 \ + --baud 921600 \ + --partition-table "${SCRIPT_DIR}/partitions.csv" \ + target/riscv32imac-unknown-none-elf/release/plant-ctrl2 diff --git a/rust/image_build.sh b/rust/image_build.sh new file mode 100755 index 0000000..d4e0175 --- /dev/null +++ b/rust/image_build.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +rm -f "${SCRIPT_DIR}/image.bin" + +"${SCRIPT_DIR}/build_website.sh" + +cargo build --release +espflash save-image \ + --bootloader "${SCRIPT_DIR}/bootloader.bin" \ + --partition-table "${SCRIPT_DIR}/partitions.csv" \ + --chip esp32c6 \ + target/riscv32imac-unknown-none-elf/release/plant-ctrl2 \ + "${SCRIPT_DIR}/image.bin"