github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/app/internal/wm/runmain.go (about)

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