Skip to content

Commit

Permalink
Add some nice build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gryhyphen committed Nov 16, 2024
1 parent f21f27f commit 8f76e9b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Debian Rust Dev Env",
// Based off https://github.com/devcontainers/images/blob/main/src/base-debian/.devcontainer/devcontainer.json
"build": {
"dockerfile": "./Dockerfile",
"dockerfile": "./dockerfile",
"context": "."
},
//"image": "mcr.microsoft.com/devcontainers/base:bookworm",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/base:1.0.9-bookworm
FROM mcr.microsoft.com/devcontainers/base:bookworm

# Install latest keyring
#RUN apt-get update \
Expand Down
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Build and Deploy",
// Using node terminal as it lets me run the code without expecting
// me to do anything.
"type": "node-terminal",
"request": "launch",
"command": "${workspaceFolder}/build.zsh",
"cwd": "${workspaceFolder}"
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run build.zsh to build and flash the pico
53 changes: 53 additions & 0 deletions build.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/zsh

# Build the thing
cargo build

if [ $? -eq 0 ]; then
echo "Build succeeded, flashing the binary to the board..."
else
echo "Build failed, please check the errors and try again."
exit 1
fi

# Get the current directory
current_dir=$(pwd)

# Read the Cargo.toml file
cargo_toml="$current_dir/Cargo.toml"
if [[ ! -f "$cargo_toml" ]]; then
echo "Failed to find Cargo.toml"
exit 1
fi

cargo_toml_content=$(cat "$cargo_toml")

# Extract the package name from Cargo.toml
package_name=$(echo "$cargo_toml_content" | grep '^name =' | sed 's/name = "\(.*\)"/\1/')
if [[ -z "$package_name" ]]; then
echo "Failed to find package name in Cargo.toml"
exit 1
fi

# Construct the path to the build binary
build_path="$current_dir/target/thumbv6m-none-eabi/debug/$package_name"

# Define the openocd command and arguments
openocd_command="sudo"
openocd_args=(
"openocd"
"-s" "tcl"
"-f" "interface/cmsis-dap.cfg"
"-f" "target/rp2040.cfg"
"-c" "adapter speed 5000"
"-c" "program $build_path verify reset exit"
)

# Execute the openocd command
$openocd_command "${openocd_args[@]}"
status=$?

if [[ $status -ne 0 ]]; then
echo "openocd command failed with status: $status"
exit 1
fi
14 changes: 11 additions & 3 deletions build.rs → buildOLD.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ use std::fs;
use std::path::PathBuf;
use std::process::Command;

// Unable to use this build script as
// 1. The binary is compiled at the end of the build script, meaning that we don't
// have access to the binary until the script completes. This means we are always
// viewing the old binary
// 2. The build script is randomly triggered by the linting tools and so code
// was being flashed to the pico when it wasn't intended to.
fn main() {
/* *
// Get the current directory
let current_dir = env::current_dir().expect("Failed to get current directory");
Expand All @@ -26,15 +33,16 @@ fn main() {
.join(package_name);
// Define the openocd command and arguments
let openocd_command = "openocd";
let openocd_command = "sudo";
let openocd_args = [
"openocd",
"-s", "tcl",
"-f", "interface/cmsis-dap.cfg",
"-f", "target/rp2040.cfg",
"-c", "adapter speed 5000",
"-c", &format!("program {} verify reset exit", build_path.display()),
];

// Execute the openocd command
let status = Command::new(openocd_command)
.args(&openocd_args)
Expand All @@ -43,5 +51,5 @@ fn main() {
if !status.success() {
panic!("openocd command failed with status: {}", status);
}
}*/
}

0 comments on commit 8f76e9b

Please sign in to comment.