diff --git a/bin/build-esp-plant-dev-tools.sh b/bin/build-esp-plant-dev-tools.sh new file mode 100755 index 0000000..35b0a2e --- /dev/null +++ b/bin/build-esp-plant-dev-tools.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +CONTAINER_NAME="localhost/esp-plant-dev-tools:latest" +CONTAINER_TOOLS_BASEDIR="$(dirname "$(readlink -f "$0")")" + +pushd "$CONTAINER_TOOLS_BASEDIR" +podman build -t "$CONTAINER_NAME" -f "esp-plant-dev-tools.Containerfile" . +popd diff --git a/bin/esp-plant-dev-tools.Containerfile b/bin/esp-plant-dev-tools.Containerfile new file mode 100644 index 0000000..541cbec --- /dev/null +++ b/bin/esp-plant-dev-tools.Containerfile @@ -0,0 +1,14 @@ +FROM debian:latest + +RUN apt update -y && apt upgrade -y && apt install unzip curl xz-utils -y + +RUN cd /root && \ + curl -L -o xpack-riscv-toolchain.tar.gz "https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v14.2.0-3/xpack-riscv-none-elf-gcc-14.2.0-3-linux-x64.tar.gz" && \ + mkdir xpack-toolchain && \ + tar -xvf xpack-riscv-toolchain.tar.gz -C xpack-toolchain --strip-components=1 && \ + mv xpack-toolchain/bin/* /usr/local/bin && \ + mv xpack-toolchain/lib/ /usr/local && \ + mv xpack-toolchain/lib64/ /usr/local && \ + mv xpack-toolchain/libexec /usr/local && \ + mv xpack-toolchain/riscv-none-elf /usr/local && \ + rm -rf xpack-toolchain xpack-riscv-toolchain.tar.gz diff --git a/bin/riscv32-unknown-elf-gcc b/bin/riscv32-unknown-elf-gcc new file mode 100755 index 0000000..8998516 --- /dev/null +++ b/bin/riscv32-unknown-elf-gcc @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +CONTAINER_IMAGE="localhost/esp-plant-dev-tools:latest" +CONTAINER_TOOLS_BASEDIR="$(dirname "$(readlink -f "$0")")" +PLANTCTL_PROJECT_DIR="$(readlink -f "$CONTAINER_TOOLS_BASEDIR/..")" + +function _fatal { + echo -e "\e[31mERROR\e[0m $(&2 + exit 1 +} + +declare -a PODMAN_ARGS=( + "--rm" "-i" "--log-driver=none" + "-v" "$PLANTCTL_PROJECT_DIR:$PLANTCTL_PROJECT_DIR:rw" + "-v" "$PWD:$PWD:rw" + "-w" "$PWD" +) + +[[ -t 1 ]] && PODMAN_ARGS+=("-t") + +if ! podman image exists "$CONTAINER_IMAGE"; then + #attempt to build container + "$CONTAINER_TOOLS_BASEDIR/build-esp-plant-dev-tools.sh" 1>&2 || + _fatal "faild to build local image, cannot continue! … please ensure you have an internet connection" +fi + +podman run "${PODMAN_ARGS[@]}" --entrypoint riscv-none-elf-gcc "$CONTAINER_IMAGE" "$@"