Files
openchamber-android-native/third_party/mygo/internal/gpu/metal/gen.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

61 lines
2.0 KiB
Go

//go:build ignore
// Gen compiles shader.metal into a Metal library with Xcode's metal tools
// and writes shaderlib.go, so that renderers start without compiling the
// shader, which takes over 100 ms until Metal has cached it. It runs on
// macOS with Xcode: go generate ./internal/gpu/metal
package main
import (
"bytes"
"fmt"
"go/format"
"log"
"os"
"github.com/egoist/mygo/internal/gpu"
"github.com/egoist/mygo/internal/gpu/metal"
)
func main() {
src, err := os.ReadFile("shader.metal")
if err != nil {
log.Fatal(err)
}
sum := gpu.SourceSum(string(src))
compile := func(sdk, min string) []byte {
code, err := metal.CompileLibraryFor(string(src), sdk, min)
if err != nil {
log.Fatal(err)
}
return code
}
// macOS 12 and iOS 17 are the oldest MyGo runs on.
write("shaderlib.go", "darwin && !ios", sum, map[string][]byte{"shaderLibrary": compile("macosx", "-mmacosx-version-min=12.0")})
// A library loads only on its platform: iOS devices' and the
// simulator's differ, and the app takes its own (shaderlib_ios.go).
write("shaderlib_ios_gen.go", "ios", sum, map[string][]byte{
"shaderLibraryDevice": compile("iphoneos", "-mios-version-min=17.0"),
"shaderLibrarySimulator": compile("iphonesimulator", "-mios-simulator-version-min=17.0"),
})
}
func write(file, constraint, sum string, libs map[string][]byte) {
var b bytes.Buffer
fmt.Fprintf(&b, "// Code generated by gen.go from shader.metal; DO NOT EDIT.\n\n//go:build %s\n\npackage metal\n\n", constraint)
fmt.Fprintf(&b, "// shaderLibrarySum is the SHA-256 of the shader.metal the libraries were\n// compiled from.\nconst shaderLibrarySum = %q\n\n", sum)
for _, name := range []string{"shaderLibrary", "shaderLibraryDevice", "shaderLibrarySimulator"} {
if code, ok := libs[name]; ok {
b.WriteString(gpu.GoBytes(name, code))
b.WriteString("\n")
}
}
out, err := format.Source(b.Bytes())
if err != nil {
log.Fatal(err)
}
if err := os.WriteFile(file, out, 0o644); err != nil {
log.Fatal(err)
}
}