runmain.go 686 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-License-Identifier: Unlicense OR MIT
  2. //go:build android || (darwin && ios)
  3. // +build android darwin,ios
  4. package app
  5. // Android only supports non-Java programs as c-shared libraries.
  6. // Unfortunately, Go does not run a program's main function in
  7. // library mode. To make Gio programs simpler and uniform, we'll
  8. // link to the main function here and call it from Java.
  9. import (
  10. "sync"
  11. _ "unsafe" // for go:linkname
  12. )
  13. //go:linkname mainMain main.main
  14. func mainMain()
  15. var runMainOnce sync.Once
  16. func runMain() {
  17. runMainOnce.Do(func() {
  18. // Indirect call, since the linker does not know the address of main when
  19. // laying down this package.
  20. fn := mainMain
  21. fn()
  22. })
  23. }