Skip to content

Commit

Permalink
go: windows support for purego + macos-14 set go version
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 29, 2024
1 parent bda532f commit bfcc713
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ jobs:
run: rm 'C:\Windows\System32\bash.exe'
name: 'remove wsl bash'
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: brew install protobuf
if: matrix.os == 'macos-14'
- run: make get_pact_ffi
Expand All @@ -583,6 +585,8 @@ jobs:
run: rm 'C:\Windows\System32\bash.exe'
name: 'remove wsl bash'
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: brew install protobuf
if: matrix.os == 'macos-14'
- run: make get_pact_ffi
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,11 @@ alpine_go:
alpine_go_purego:
docker run --platform=${DOCKER_DEFAULT_PLATFORM} -v ${PWD}:/app --rm alpine sh -c 'apk add make go && cd /app && CGO_ENABLED=0 make go_purego'
go_hello_ffi:
cd go && $(GO_CMD) build helloFfi.go
$(LOAD_PATH) go/helloFfi
cd go/cgo && $(GO_CMD) build helloFfi.go
$(LOAD_PATH) go/cgo/helloFfi
go_purego_hello_ffi:
cd go && $(GO_CMD) build helloFfiPureGo.go
$(LOAD_PATH) go/helloFfiPureGo
cd go/purego && $(GO_CMD) build
$(LOAD_PATH) go/purego/hello_ffi

go_purego: go_purego_hello_ffi
go: go_hello_ffi
Expand Down
9 changes: 4 additions & 5 deletions go/helloFfi.go → go/cgo/helloFfi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

// #cgo CFLAGS: -g -I./..
// #cgo LDFLAGS: -lpact_ffi -L./..
// #include "../pact.h"
// #cgo CFLAGS: -g -I./../..
// #cgo LDFLAGS: -lpact_ffi -L./../..
// #include "../../pact.h"
import "C"
import (
"fmt"
Expand All @@ -17,10 +17,9 @@ func main() {
C.pactffi_log_message(C.CString("pact-go-ffi"), C.CString("INFO"), C.CString(fmt.Sprintf("hello from ffi version: %s", C.GoString(version))))
}


// https://github.com/golang/go/issues/51007

// * Executing task: cd go; go build
// * Executing task: cd go; go build

// # github.com/you54f/hello_ffi
// C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
Expand Down
File renamed without changes.
File renamed without changes.
583 changes: 583 additions & 0 deletions go/purego/lib.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions go/purego/lib_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build darwin || linux

package main

import "github.com/ebitengine/purego"

func openLibrary(name string) (uintptr, error) {
return purego.Dlopen(name, purego.RTLD_NOW|purego.RTLD_GLOBAL)
}
10 changes: 10 additions & 0 deletions go/purego/lib_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build windows

package main

import "golang.org/x/sys/windows"

func openLibrary(name string) (uintptr, error) {
handle, err := windows.LoadLibrary(name)
return uintptr(handle), err
}
19 changes: 19 additions & 0 deletions go/purego/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build darwin || linux || windows

package main

func main() {

print(pactffi_version())
pactffi_log_to_stdout(4)
// pactffi_log_to_file("pact.log", 5)

var verifier_handle = pactffi_verifier_new_for_application("pact-purego", "0.0.1")
pactffi_verifier_set_provider_info(verifier_handle, "grpc-provider", "http", "localhost", 1234, "/")
pactffi_verifier_add_file_source(verifier_handle, "no_pact.json")
// pactffi_verifier_add_file_source(verifier_handle, "pact.json")
// pactffi_verifier_add_file_source(verifier_handle, "../pacts/Consumer-Alice Service.json")
// pactffi_verifier_add_file_source(verifier_handle, "../pacts/grpc-consumer-perl-area-calculator-provider.json")
pactffi_verifier_execute(verifier_handle)
pactffi_verifier_shutdown(verifier_handle)
}

0 comments on commit bfcc713

Please sign in to comment.