FluxSharp Build Script - Dynamic Compilation Guide
Overview
The build.sh script has been enhanced to support dynamic compilation of any FluxSharp file.
Usage
Compile Default File (main.fsh)
./build.shThis compiles main.fsh in the project root and creates main executable.
Compile Specific File
./build.sh path/to/file.fshThe script automatically:
- Compiles the specified
.fshfile - Generates a binary with the same name (minus
.fsh) - Runs the compiled program
Examples
Hello World Example
./build.sh examples/hello.fshCreates: examples/hello executable Runs: ./examples/hello
Calculator Example
./build.sh examples/calculator.fshCreates: examples/calculator executable Runs: ./examples/calculator
Custom File
./build.sh my_program.fshCreates: my_program executable Runs: ./my_program
Subdirectory File
./build.sh src/utils/helper.fshCreates: src/utils/helper executable Runs: ./src/utils/helper
Output
For each build, the script displays:
๐ FluxSharp - Complete Build and Run
=======================================
๐ Input: /path/to/file.fsh
๐ฆ Output: /path/to/file
๐จ Step 1: Building Rust compiler...
๐ Step 2: Compiling FluxSharp โ Executable
๐ Step 3: Executing Program
[Program output here]
โ
Build complete!Automatic Features
The script automatically:
โ
Checks dependencies - Ensures cargo is installed โ
Builds compiler - Compiles Rust compiler (cached after first run) โ
Generates assembly - Creates .asm file โ
Assembles code - Generates .o object file โ
Links binary - Creates executable with runtime โ
Executes program - Runs the compiled binary โ
Cleanup - Intermediate files stored in source directory
File Organization
FluxSharp/
โโโ build.sh # Main build script
โโโ main.fsh # Default program
โโโ program # Executable (from main.fsh)
โโโ examples/
โ โโโ hello.fsh # Hello world example
โ โโโ hello # Hello executable
โ โโโ calculator.fsh # Calculator example
โ โโโ calculator # Calculator executable
โ โโโ arrays.fsh # Arrays example
โ โโโ arrays # Arrays executable
โโโ src/
โโโ [your files]Advanced Usage
Compile Multiple Files
./build.sh main.fsh # Build main program
./build.sh examples/hello.fsh # Build hello example
./build.sh examples/calc.fsh # Build calculatorBuild Without Execution
Build script always executes the compiled binary. To build without running:
bash -x build.sh file.fsh 2>&1 | grep "Executable created"Or modify the script to skip the execution step.
Clean Generated Files
Remove intermediate build files:
rm -f main.asm main.o main # For main.fsh
rm -f examples/hello.asm examples/hello.o examples/hello # For examplesError Handling
If compilation fails, the script displays:
โ Compilation failedCheck:
- Syntax errors - Verify FluxSharp syntax matches SYNTAX.md
- File path - Ensure file exists at specified path
- Compiler - Verify cargo is installed:
cargo --version
Performance
- First run: ~3 seconds (builds compiler)
- Subsequent runs: <1 second (cached compiler)
- Compilation: <1 second for typical files
- Total time: ~1 second (cached)
Examples in Repository
The examples/ folder contains ready-to-compile examples:
hello.fsh
Basic "Hello World" program demonstrating:
- Simple function calls
- String printing
./build.sh examples/hello.fshcalculator.fsh
Object-oriented programming example with:
- Class definition
- Constructor and methods
- Object instantiation with
new
./build.sh examples/calculator.fsharrays.fsh
Array usage example with:
- Array declaration
- Element assignment
- Element access
./build.sh examples/arrays.fshCustom Projects
To create your own FluxSharp project:
- Create file:
``bash cat > my_app.fsh << 'EOF' public static void Main() { print("My FluxSharp App"); return; } EOF `
- Build and run:
`bash ./build.sh my_app.fsh `
- Executable created:
`bash ./my_app # Run the compiled program `
Workflow
- Edit file:
`bash nano examples/my_program.fsh `
- Build and run:
`bash ./build.sh examples/my_program.fsh ``
- See output - Program runs automatically
- Iterate - Go back to step 1
Integration with Development Tools
Run in IDE
Most IDEs allow custom build commands:
./build.sh examples/my_file.fshMakefile Integration
Add to your Makefile:
%.run: %.fsh
./build.sh $<
test:
./build.sh examples/hello.fsh
./build.sh examples/calculator.fshRun with:
make my_file.run
make testThe build system is now fully dynamic and flexible! ๐