mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
4a26bdad5d
The `gogio` tool adds the `-fmodules -fobjc-arc` flags to the Cgo C flags. Unfortunately, that masks problems where Cgo packages accidentally didn't have the flags in their #cgo directives such as package log. Move the flags so they're only explicitly mentioned when `gogio` invokes the host compiler to build the `main.m` shim. Fix package log to include the missing flags. While we're here, silence OpenGL ES deprecation warnings on iOS, just as we do for macOS. The warnings are normally not visible because the gogio tool suppress output from the go tool. Signed-off-by: Elias Naur <mail@eliasnaur.com>
48 lines
855 B
Go
48 lines
855 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
// +build darwin,ios
|
|
|
|
package log
|
|
|
|
/*
|
|
#cgo CFLAGS: -fmodules -fobjc-arc -x objective-c
|
|
|
|
#include "log_ios.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"log"
|
|
"unsafe"
|
|
)
|
|
|
|
func init() {
|
|
// macOS Console already includes timstamps.
|
|
log.SetFlags(log.Flags() &^ log.LstdFlags)
|
|
log.SetOutput(newNSLogWriter())
|
|
}
|
|
|
|
func newNSLogWriter() io.Writer {
|
|
r, w := io.Pipe()
|
|
go func() {
|
|
// 1024 is an arbitrary truncation limit, taken from Android's
|
|
// log buffer size.
|
|
lineBuf := bufio.NewReaderSize(r, 1024)
|
|
// The buffer to pass to C, including the terminating '\0'.
|
|
buf := make([]byte, lineBuf.Size()+1)
|
|
cbuf := (*C.char)(unsafe.Pointer(&buf[0]))
|
|
for {
|
|
line, _, err := lineBuf.ReadLine()
|
|
if err != nil {
|
|
break
|
|
}
|
|
copy(buf, line)
|
|
buf[len(line)] = 0
|
|
C.nslog(cbuf)
|
|
}
|
|
}()
|
|
return w
|
|
}
|