puregogen

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 2 Imported by: 2 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

purego-gen

purego-gen is a tool to generate pure Go function wrappers to syscalls thanks to purego and jen.

This is a big work in progress, and also an experiment.

Description

This tool uses https://github.com/ebitengine/purego to generate wrappers to C functions using purego.SyscallN.

Installation

go install github.com/Zyko0/purego-gen/cmd/purego-gen

Usage

The input file must declare all go functions definitions and the necesssary types. There are a few custom directives starting with //puregogen: such as:

  • //puregogen:library path=opencl path:windows=opencl32.dll alias=cl
    • path:<os> specifies the path to the library based on the operating system
      • path can also be used
    • alias is the library alias for variables naming, if none specified it might be inferred from the library name.
  • //puregogen:function symbol=clCreateDevice
    • symbol allows to set the symbol for the function below it if it is not named after the symbol already

There is a partial example about opencl in the examples directory, examples/functions.go is the input file. And the examples/functions_impl.go is generated via go run cmd/purego-gen --input ./examples/functions.go

Usage of purego-gen:
  --dry
        Outputs the generated code to stdout instead of a file
  --embed-loaders
        Generate a single file by linking unexported loading methods from ebitengine/purego
  --input string
        The input .go file to parse
  --extra string
        An optional list of comma separated .go files to parse for definitions
  --no-warnings
        Prevent printing warnings to sderr
  --platforms string
        A list of comma separated platforms supported for library loading (defaults to: "windows,linux,darwin,freebsd")

TBD

  • Support the --embed-loaders flag (or the non flag actually, to output multiple _os.go files for libraries loading)
  • Support additional types
    • floats
    • structs
    • functions returned

Note: floats and structs are supported using purego.RegisterLibFunc as a fallback.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToUintptr

func BoolToUintptr(b bool) uintptr

func BytePtrFromString

func BytePtrFromString(s string) *byte

func BytePtrToString

func BytePtrToString(p *byte) string

func ByteSliceFromString

func ByteSliceFromString(s string) []byte

func ByteSliceToString

func ByteSliceToString(s []byte) string

func CloseLibrary

func CloseLibrary(lib uintptr) error

func OpenLibrary

func OpenLibrary(name string) (uintptr, error)

func OpenSymbol

func OpenSymbol(lib uintptr, name string) (uintptr, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
purego-gen command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址