From 371fa0d8ca52a1adcb24477f06493b04862a376f Mon Sep 17 00:00:00 2001 From: Osinachi Chukwujama Date: Thu, 4 Sep 2025 00:04:46 +0000 Subject: [PATCH 1/3] chore: add runfiles.sh for running the files from a bash script --- runfiles.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 runfiles.sh diff --git a/runfiles.sh b/runfiles.sh new file mode 100644 index 0000000..6af3935 --- /dev/null +++ b/runfiles.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +function rust_run(){ + filepath=$(mktemp /tmp/mainXXXXXX) + rustc "$1" -o "$filepath" + "$filepath" + rm "$filepath" +} + + +shopt -s globstar + +declare -A file_paths + +echo "Available files" +rust_files=(day*/**/main.rs) +for index in "${!rust_files[@]}"; do + echo "$((index+1)). ${rust_files[$1]}" +done + + +echo -e "\n" + +max_index=${#rust_files[@]} + +while true; do + read -p "Which file do you want to execute (1 - $max_index): " file_index_to_execute + + if [[ $file_index_to_execute =~ ^[0-9]+$ ]] && (( file_index_to_execute >= 1 && file_index_to_execute <= max_index )); then + rust_run "${rust_files[$((file_index_to_execute - 1))]}" + break + else + echo "Invalid input. Please enter a number between 1 and $max_index." + fi +done + + From b7b8d6acbaf118233bba5beb502fdd187cab1389 Mon Sep 17 00:00:00 2001 From: Osinachi Chukwujama Date: Thu, 4 Sep 2025 00:25:31 +0000 Subject: [PATCH 2/3] docs: add readme section on running the files --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index b995b54..9216649 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,19 @@ This repo is the "home page" for the Rust Africa Embedded * [Portland State Embedded Code](https://github.com/pdx-cs-rust-embedded) * [Exercism Rust Track](https://exercism.org/tracks/rust) * [Rustlings](https://rustlings.rust-lang.org/) + + +## Running the files + +Before attempting to run the Rust files in this repo, ensure that you already [installed Rust for your operating system](https://www.rust-lang.org/tools/install) and have at least `cargo` or `rustc` available on your path (system or user). + +To run the files in this course, navigate to the directory of the particular lesson and run the `cargo run` command. An example is shown below: + +```sh +cd day-1/rust-basics +cargo run +``` + +If you wish to build a binary which you can run at a later time, you can use the `cargo build --release` command for an optimized release or the `cargo build` for an unoptimized release (debug release). + +If you'd rather not navigate into directories to run files, you can utilize the `runfiles.sh` script on the root directory. It gives you an overview of all the `main.rs` files in the course and allows you run them iteractively. It uses `rustc` which Cargo also uses under the hood. \ No newline at end of file From 090f74a5cf2e227940f98bb933dfb7ca975652c1 Mon Sep 17 00:00:00 2001 From: Osinachi Chukwujama Date: Thu, 4 Sep 2025 00:25:55 +0000 Subject: [PATCH 3/3] fix: issue with file indexing --- runfiles.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runfiles.sh b/runfiles.sh index 6af3935..07a8c15 100644 --- a/runfiles.sh +++ b/runfiles.sh @@ -15,7 +15,7 @@ declare -A file_paths echo "Available files" rust_files=(day*/**/main.rs) for index in "${!rust_files[@]}"; do - echo "$((index+1)). ${rust_files[$1]}" + echo "$((index+1)). ${rust_files[$index]}" done