add go support (#59)
This commit is contained in:
parent
8ea0754e3f
commit
f40a34c04b
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@ -55,6 +55,12 @@ jobs:
|
|||||||
cd erlang
|
cd erlang
|
||||||
rebar3 compile
|
rebar3 compile
|
||||||
rebar3 eunit
|
rebar3 eunit
|
||||||
|
- name: build-test-golang
|
||||||
|
run: |
|
||||||
|
cd go
|
||||||
|
go build -o ruapu-go
|
||||||
|
./ruapu-go
|
||||||
|
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
@ -79,6 +85,11 @@ jobs:
|
|||||||
cd rust
|
cd rust
|
||||||
cargo build --verbose
|
cargo build --verbose
|
||||||
cargo test --verbose
|
cargo test --verbose
|
||||||
|
- name: build-test-golang
|
||||||
|
run: |
|
||||||
|
cd go
|
||||||
|
go build -o ruapu-go
|
||||||
|
./ruapu-go
|
||||||
|
|
||||||
macos-arm64:
|
macos-arm64:
|
||||||
runs-on: macos-14
|
runs-on: macos-14
|
||||||
@ -103,6 +114,14 @@ jobs:
|
|||||||
cd rust
|
cd rust
|
||||||
cargo build --verbose
|
cargo build --verbose
|
||||||
cargo test --verbose
|
cargo test --verbose
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.21.x
|
||||||
|
- name: build-test-golang
|
||||||
|
run: |
|
||||||
|
cd go
|
||||||
|
go build -o ruapu-go
|
||||||
|
./ruapu-go
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
@ -142,6 +161,11 @@ jobs:
|
|||||||
cd erlang
|
cd erlang
|
||||||
rebar3 compile
|
rebar3 compile
|
||||||
rebar3 eunit
|
rebar3 eunit
|
||||||
|
- name: build-test-golang
|
||||||
|
run: |
|
||||||
|
cd go
|
||||||
|
go build -o ruapu-go.exe
|
||||||
|
./ruapu-go.exe
|
||||||
|
|
||||||
qemu:
|
qemu:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
40
README.md
40
README.md
@ -264,6 +264,46 @@ end program main
|
|||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
### ruapu with Golang
|
||||||
|
|
||||||
|
<table>
|
||||||
|
|
||||||
|
|
||||||
|
<tr><td>
|
||||||
|
|
||||||
|
Compile ruapu library
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd go
|
||||||
|
go build -o ruapu-go
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Use ruapu in Golang
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"ruapu-go/ruapu"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ruapu.Init()
|
||||||
|
avx2Status := ruapu.Supports("avx2")
|
||||||
|
fmt.Println("avx2:" + strconv.Itoa(avx2Status))
|
||||||
|
rua := ruapu.Rua()
|
||||||
|
fmt.Println(rua)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Github-hosted runner result (Linux)</summary>
|
<summary>Github-hosted runner result (Linux)</summary>
|
||||||
|
|
||||||
|
15
go/main.go
Normal file
15
go/main.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"ruapu-go/ruapu"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ruapu.Init()
|
||||||
|
avx2Status := ruapu.Supports("avx2")
|
||||||
|
fmt.Println("avx2:" + strconv.Itoa(avx2Status))
|
||||||
|
rua := ruapu.Rua()
|
||||||
|
fmt.Println(rua)
|
||||||
|
}
|
36
go/ruapu/ruapu-binding.go
Normal file
36
go/ruapu/ruapu-binding.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package ruapu
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo CFLAGS: -I ../../
|
||||||
|
#define RUAPU_IMPLEMENTATION
|
||||||
|
#include "ruapu.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
C.ruapu_init()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Supports(isa string) int {
|
||||||
|
ptr := C.CString(isa)
|
||||||
|
defer C.free(unsafe.Pointer(ptr))
|
||||||
|
result := int(C.ruapu_supports(ptr))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rua() []string {
|
||||||
|
p := unsafe.Pointer(C.ruapu_rua())
|
||||||
|
s := make([]string, 0, 1)
|
||||||
|
for i := 0; ; i++ {
|
||||||
|
q := *(*unsafe.Pointer)(unsafe.Pointer(uintptr(p) + uintptr(i)*unsafe.Sizeof(p)))
|
||||||
|
if q == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
s = append(s, C.GoString((*C.char)(q)))
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user