mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
45963441c1
When Gio is embedded (such as on Android and iOS), we pretend that the Go library is the main program by running Go main on the main thread. To avoid deadlock, `app.Main` returns immediately to relinquish control of the main thread. This behaviour is suprising (what if something else runs after `app.Main`?) and more importantly is not compatible with app global events received by the main goroutine. Something had to give, and this change starts a new goroutine for calling Go's main. Signed-off-by: inkeliz <inkeliz@inkeliz.com> Signed-off-by: Elias Naur <mail@eliasnaur.com>
31 lines
689 B
Go
31 lines
689 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
//go:build android || (darwin && ios)
|
|
// +build android darwin,ios
|
|
|
|
package app
|
|
|
|
// Android only supports non-Java programs as c-shared libraries.
|
|
// Unfortunately, Go does not run a program's main function in
|
|
// library mode. To make Gio programs simpler and uniform, we'll
|
|
// link to the main function here and call it from Java.
|
|
|
|
import (
|
|
"sync"
|
|
_ "unsafe" // for go:linkname
|
|
)
|
|
|
|
//go:linkname mainMain main.main
|
|
func mainMain()
|
|
|
|
var runMainOnce sync.Once
|
|
|
|
func runMain() {
|
|
runMainOnce.Do(func() {
|
|
// Indirect call, since the linker does not know the address of main when
|
|
// laying down this package.
|
|
fn := mainMain
|
|
go fn()
|
|
})
|
|
}
|