Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add purego support for unix #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ require (
)

require (
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa // indirect
golang.org/x/sys v0.14.0 // indirect
github.com/ebitengine/purego v0.6.1 // indirect
golang.org/x/sys v0.18.0 // indirect
)
8 changes: 4 additions & 4 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa h1:Ik7QikRgeH+bFOfAcMpttCbs6XxWXxCLXMm4awxtOXk=
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/ebitengine/purego v0.6.1 h1:sjN8rfzbhXQ59/pE+wInswbU9aMDHiwlup4p/a07Mkg=
github.com/ebitengine/purego v0.6.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI=
github.com/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b h1:+67TGbwfgeB5o03Rx+ZBW44zAQ+wUujcwdRA0p9CbJI=
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b/go.mod h1:kvKwD9codtns5mvpA53V3vLnqFb/Ahcu8zgkGM0SIbI=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4 changes: 2 additions & 2 deletions raylib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/gen2brain/raylib-go/raylib
go 1.21

require (
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa
golang.org/x/sys v0.14.0
github.com/ebitengine/purego v0.6.1
golang.org/x/sys v0.18.0
)
8 changes: 4 additions & 4 deletions raylib/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa h1:Ik7QikRgeH+bFOfAcMpttCbs6XxWXxCLXMm4awxtOXk=
github.com/ebitengine/purego v0.6.0-alpha.1.0.20231122024802-192c5e846faa/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/ebitengine/purego v0.6.1 h1:sjN8rfzbhXQ59/pE+wInswbU9aMDHiwlup4p/a07Mkg=
github.com/ebitengine/purego v0.6.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
8 changes: 8 additions & 0 deletions raylib/purego.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !cgo
// +build !cgo

package rl

const (
requiredVersion = "5.0"
)
45 changes: 45 additions & 0 deletions raylib/purego_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//go:build !cgo && (darwin || openbsd || freebsd || linux)

package rl

import (
"fmt"
"runtime"
"unsafe"

"github.com/ebitengine/purego"
"golang.org/x/sys/unix"
)

// loadLibrary loads the raylib dll and panics on error
func loadLibrary() uintptr {
libname := "raylib.so"
switch runtime.GOOS {
case "darwin":
libname = "raylib.dylib"
}

handle, err := purego.Dlopen(libname, purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
panic(fmt.Errorf("cannot load library %s: %w", libname, err))
}

proc, err := purego.Dlsym(handle, "raylib_version")
if err != nil {
panic(err)
}

version := unix.BytePtrToString(**(***byte)(unsafe.Pointer(&proc)))
if version != requiredVersion {
panic(fmt.Errorf("version %s of %s doesn't match the required version %s", version, libname, requiredVersion))
}

return uintptr(handle)
}

func traceLogCallbackWrapper(fn TraceLogCallbackFun) uintptr {
return purego.NewCallback(func(logLevel int32, text *byte) uintptr {
fn(int(logLevel), unix.BytePtrToString(text))
return 0
})
}
3 changes: 1 addition & 2 deletions raylib/purego_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
)

const (
libname = "raylib.dll"
requiredVersion = "5.0"
libname = "raylib.dll"
)

// loadLibrary loads the raylib dll and panics on error
Expand Down
4 changes: 2 additions & 2 deletions raylib/raylib_purego.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !cgo && windows
// +build !cgo,windows
//go:build !cgo
// +build !cgo

package rl

Expand Down
4 changes: 2 additions & 2 deletions raylib/rlgl_purego.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !cgo && windows
// +build !cgo,windows
//go:build !cgo
// +build !cgo

package rl

Expand Down
Loading