Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/vendor/github.com/ebitengine/purego
renovate[bot] 319bb0f132
fix(deps): update module github.com/shirou/gopsutil/v4 to v4.25.1 (main) (#16049)
4 months ago
..
internal fix(deps): update module github.com/shirou/gopsutil/v4 to v4.25.1 (main) (#16049) 4 months ago
.gitignore chore: upgrade gopsutil (#14542) 7 months ago
LICENSE chore: upgrade gopsutil (#14542) 7 months ago
README.md chore: upgrade gopsutil (#14542) 7 months ago
abi_amd64.h chore: upgrade gopsutil (#14542) 7 months ago
abi_arm64.h chore: upgrade gopsutil (#14542) 7 months ago
cgo.go chore: upgrade gopsutil (#14542) 7 months ago
dlerror.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_android.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_darwin.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_freebsd.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_linux.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_nocgo_freebsd.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_nocgo_linux.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_playground.go chore: upgrade gopsutil (#14542) 7 months ago
dlfcn_stubs.s chore: upgrade gopsutil (#14542) 7 months ago
func.go chore: upgrade gopsutil (#14542) 7 months ago
go_runtime.go chore: upgrade gopsutil (#14542) 7 months ago
is_ios.go chore: upgrade gopsutil (#14542) 7 months ago
nocgo.go chore: upgrade gopsutil (#14542) 7 months ago
struct_amd64.go fix(deps): update module github.com/shirou/gopsutil/v4 to v4.24.10 (#14719) 7 months ago
struct_arm64.go chore: upgrade gopsutil (#14542) 7 months ago
struct_other.go chore: upgrade gopsutil (#14542) 7 months ago
sys_amd64.s chore: upgrade gopsutil (#14542) 7 months ago
sys_arm64.s chore: upgrade gopsutil (#14542) 7 months ago
sys_unix_arm64.s chore: upgrade gopsutil (#14542) 7 months ago
syscall.go chore: upgrade gopsutil (#14542) 7 months ago
syscall_cgo_linux.go chore: upgrade gopsutil (#14542) 7 months ago
syscall_sysv.go chore: upgrade gopsutil (#14542) 7 months ago
syscall_windows.go chore: upgrade gopsutil (#14542) 7 months ago
zcallback_amd64.s chore: upgrade gopsutil (#14542) 7 months ago
zcallback_arm64.s chore: upgrade gopsutil (#14542) 7 months ago

README.md

purego

Go Reference

A library for calling C functions from Go without Cgo.

This is beta software so expect bugs and potentially API breaking changes but each release will be tagged to avoid breaking people's code. Bug reports are encouraged.

Motivation

The Ebitengine game engine was ported to use only Go on Windows. This enabled cross-compiling to Windows from any other operating system simply by setting GOOS=windows. The purego project was born to bring that same vision to the other platforms supported by Ebitengine.

Benefits

  • Simple Cross-Compilation: No C means you can build for other platforms easily without a C compiler.
  • Faster Compilation: Efficiently cache your entirely Go builds.
  • Smaller Binaries: Using Cgo generates a C wrapper function for each C function called. Purego doesn't!
  • Dynamic Linking: Load symbols at runtime and use it as a plugin system.
  • Foreign Function Interface: Call into other languages that are compiled into shared objects.
  • Cgo Fallback: Works even with CGO_ENABLED=1 so incremental porting is possible. This also means unsupported GOARCHs (freebsd/riscv64, linux/mips, etc.) will still work except for float arguments and return values.

Supported Platforms

  • FreeBSD: amd64, arm64
  • Linux: amd64, arm64
  • macOS / iOS: amd64, arm64
  • Windows: 386*, amd64, arm*, arm64

* These architectures only support SyscallN and NewCallback

Example

The example below only showcases purego use for macOS and Linux. The other platforms require special handling which can be seen in the complete example at examples/libc which supports Windows and FreeBSD.

package main

import (
	"fmt"
	"runtime"

	"github.com/ebitengine/purego"
)

func getSystemLibrary() string {
	switch runtime.GOOS {
	case "darwin":
		return "/usr/lib/libSystem.B.dylib"
	case "linux":
		return "libc.so.6"
	default:
		panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS))
	}
}

func main() {
	libc, err := purego.Dlopen(getSystemLibrary(), purego.RTLD_NOW|purego.RTLD_GLOBAL)
	if err != nil {
		panic(err)
	}
	var puts func(string)
	purego.RegisterLibFunc(&puts, libc, "puts")
	puts("Calling C from Go without Cgo!")
}

Then to run: CGO_ENABLED=0 go run main.go

Questions

If you have questions about how to incorporate purego in your project or want to discuss how it works join the Discord!

External Code

Purego uses code that originates from the Go runtime. These files are under the BSD-3 License that can be found in the Go Source. This is a list of the copied files:

  • abi_*.h from package runtime/cgo
  • zcallback_darwin_*.s from package runtime
  • internal/fakecgo/abi_*.h from package runtime/cgo
  • internal/fakecgo/asm_GOARCH.s from package runtime/cgo
  • internal/fakecgo/callbacks.go from package runtime/cgo
  • internal/fakecgo/go_GOOS_GOARCH.go from package runtime/cgo
  • internal/fakecgo/iscgo.go from package runtime/cgo
  • internal/fakecgo/setenv.go from package runtime/cgo
  • internal/fakecgo/freebsd.go from package runtime/cgo

The files abi_*.h and internal/fakecgo/abi_*.h are the same because Bazel does not support cross-package use of #include so we need each one once per package. (cf. issue)