Skip to content

go4ml/dyl

Repository files navigation

CircleCI Maintainability Test Coverage Go Report Card License

/*

int function(int);

#define DEFINE_JUMPER(x) \
        void *_dyl_##x = (void*)0; \
        __asm__(".global "#x"\n\t"#x":\n\tmovq _dyl_"#x"(%rip),%rax\n\tjmp *%rax\n")
  
DEFINE_JUMPER(function);

*/
import "C"

import (
	"go4ml.xyz/dyl"
	"runtime"
	"unsafe"
)

func init() {
    urlbase := "https://github.com/go4ml/nativelibs/releases/download/files/"
    if runtime.GOOS == "linux" && runtime.GOARCH == "amd64"{
        so := dyl.Load(
            dyl.Cache("go4ml/dyl/libfunction.so"),
            dyl.LzmaExternal(urlbase+"libfunction_lin64.xz"))
    } else if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
        so := dyl.Load(
            dyl.Cache("go4ml/dyl/function.dll"),
            dyl.LzmaExternal(urlbase+"libfunction_win64.xz"))
    }
    so.Bind("function",unsafe.Pointer(&C._dyl_function))
}

func main() {
    C.function(0)
}

Releases

No releases published

Packages

No packages published