Giter Site home page Giter Site logo

onlygo's Introduction

This project is not maintained. My effort has moved towards ebitengine/purego. It supports features that this project doesn't like Objective-C runtime bindings and callbacks that can be called from C.

onlygo

OnlyGo generates go assembly wrappers into dynamically linked C code without the use of CGO.

Install

Install OnlyGo using the following command:

go install github.com/totallygamerjet/onlygo@latest

Usage

Create a go file that will hold the function stubs. First, create a comment that tells onlygo what dynamic libray it should be linking to. This comment should peferably be near the top of the go file for easy discovery. The format of this comment starts with onlygo:open then followed by the os, architecture and library name. Do this comment for each OS and arch combo you want to be generated.

//onlygo:open darwin arm64 libSystem.dylib

Next, write stub functions for each C function you want to call. You MUST match the signature exactly so that onlygo can call the C function properly. Then above the function add a comment starting with //onlygo:linkname that will give the C name of the function as found in the dynamic library. This directive is only needed if the go function name doesn't match the C function.

//onlygo:linkname malloc
func Malloc(size uintptr) unsafe.Pointer

Finally, just call onlygo with a list of go files you want to generate wrappers for. You may also wish to use a go:generate comment to make this process easier.

//go:generate onlygo libc.go

OnlyGo will generate a file ending in *_init.go. This file contains a function with the signature func Init() error that MUST be called before calling any of the dynamically linked to functions. This function links the go function to the C function.

If you want OnlyGo to resolve the functions at execution time instead of requiring a call to an init function use the directive: //onlygo:resolve_with_cgo. NOTE: using the directive does NOT hinder the cross-complication benefits of using OnlyGo. The reason this is not the default is that it is likely to be more unstable.

Type Guide

TODO:

Support

Currently only a few OSs and Architectures are partially supported but it should be easy enough to add more. Look at the implementations.

  • MacOS
    • AMD64
    • ARM64
  • iOS
    • ARM64
  • Linux
    • AMD64
    • ARM64
  • Windows
    • AMD64
    • ARM64

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.