The tinygo flash command currently doesn't support the -o flag to save the built binary to a specified output file, while the tinygo build command does. This inconsistency makes it inconvenient when users want to both flash a device and save the binary file for later use or distribution.
Current Behavior
tinygo build -o firmware.hex -target arduino main.go # Works - saves to firmware.hex
tinygo flash -o firmware.hex -target arduino main.go # Doesn't work - error message to stop.
Expected Behavior
tinygo flash -o firmware.hex -target arduino main.go # Should flash device AND save to firmware.hex
Proposed Implementation
I believe there are two possible approaches:
Approach 1: Minimal Change (Immediate Solution)
- Modify
Flash function to copy the built binary to the specified output path after successful build
- Pass
outpath as an additional parameter to the Flash function
- Pros: Minimal risk, easy to review, maintains backward compatibility
- Cons: Duplicates output logic between
build and flash commands, inconsistent parameter handling
Approach 2: Refactor Build Function (Better Long-term Solution)
- Modify
Build function in main.go to use compileopts.Options instead of separate outpath parameter
- This would unify the output handling logic between
build and flash commands
- Pros: Cleaner architecture, consistent design, eliminates code duplication
- Cons: Larger change, requires more careful testing
Personal Preference: I lean toward Approach 2 (refactoring the Build function) as it creates a more consistent and maintainable codebase. However, I understand that Approach 1 might be preferred for minimizing change scope.
Would appreciate feedback on which approach the maintainers prefer before submitting a pull request.
The
tinygo flashcommand currently doesn't support the-oflag to save the built binary to a specified output file, while thetinygo buildcommand does. This inconsistency makes it inconvenient when users want to both flash a device and save the binary file for later use or distribution.Current Behavior
Expected Behavior
tinygo flash -o firmware.hex -target arduino main.go # Should flash device AND save to firmware.hexProposed Implementation
I believe there are two possible approaches:
Approach 1: Minimal Change (Immediate Solution)
Flashfunction to copy the built binary to the specified output path after successful buildoutpathas an additional parameter to the Flash functionbuildandflashcommands, inconsistent parameter handlingApproach 2: Refactor Build Function (Better Long-term Solution)
Buildfunction inmain.goto usecompileopts.Optionsinstead of separateoutpathparameterbuildandflashcommandsPersonal Preference: I lean toward Approach 2 (refactoring the Build function) as it creates a more consistent and maintainable codebase. However, I understand that Approach 1 might be preferred for minimizing change scope.
Would appreciate feedback on which approach the maintainers prefer before submitting a pull request.