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

llcppg: current package info #180

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
9 changes: 2 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,14 @@ jobs:
pkg-config --cflags --libs sqlite3
pkg-config --cflags --libs libxslt

llcppgtest -demos ./_llcppgtest
llcppgtest -demos ./_llcppgtest/macos

- name: Test demos with generated pkgs
if: startsWith(matrix.os, 'ubuntu')
run: |
# install demo's lib
sudo apt install liblua5.4-dev libsqlite3-dev libgmp-dev libgpg-error-dev zlib1g-dev -y
llcppgtest -demo ./_llcppgtest/cjson
llcppgtest -demo ./_llcppgtest/lua
llcppgtest -demo ./_llcppgtest/sqlite
llcppgtest -demo ./_llcppgtest/gmp
llcppgtest -demo ./_llcppgtest/gpgerror
llcppgtest -demo ./_llcppgtest/zlib
llcppgtest -demos ./_llcppgtest/linux


- name: Upload coverage reports to Codecov
Expand Down
12 changes: 12 additions & 0 deletions _llcppgtest/linux/cjson/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "cjson",
"cflags": "$(pkg-config --cflags libcjson)",
"libs": "$(pkg-config --libs libcjson libcjson_utils)",
"include": [
"cJSON.h",
"cJSON_Utils.h"
],
"trimPrefixes": ["cJSON_", "cJSONUtils_"],
"cplusplus": false,
"mix":true
}
File renamed without changes.
12 changes: 12 additions & 0 deletions _llcppgtest/linux/gmp/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "gmp",
"cflags": "$(pkg-config --cflags gmp)",
"libs": "$(pkg-config --libs gmp)",
"include": [
"gmp.h",
"gmpxx.h"
],
"trimPrefixes": ["__"],
"cplusplus": false,
"mix":true
}
12 changes: 12 additions & 0 deletions _llcppgtest/linux/gpgerror/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "gpgerror",
"cflags": "$(pkg-config --cflags gpg-error)",
"libs": "$(pkg-config --libs gpg-error)",
"include": [
"gpgrt.h",
"gpg-error.h"
],
"trimPrefixes": ["gpg_err_","gpgrt_set_","gpg_","GPG_ERR_"],
"cplusplus": false,
"mix":true
}
14 changes: 14 additions & 0 deletions _llcppgtest/linux/lua/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "lua",
"cflags": "$(pkg-config --cflags lua)",
"libs": "$(pkg-config --libs lua)",
"include": [
"lua.h",
"luaconf.h",
"lualib.h",
"lauxlib.h"
],
"trimPrefixes": ["lua_", "luaopen_", "luaL_", "LUA_T", "LUA_"],
"cplusplus": false,
"mix":true
}
Binary file added _llcppgtest/linux/sqlite/demo/hello/test.db
Binary file not shown.
12 changes: 12 additions & 0 deletions _llcppgtest/linux/sqlite/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "sqlite",
"cflags": "$(pkg-config --cflags sqlite3)",
"libs": "$(pkg-config --libs sqlite3)",
"include": [
"sqlite3ext.h",
"sqlite3.h"
],
"trimPrefixes": ["sqlite3_","SQLITE_"],
"cplusplus": false,
"mix":true
}
12 changes: 12 additions & 0 deletions _llcppgtest/linux/zlib/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "zlib",
"cflags": "$(pkg-config --cflags zlib)",
"libs": "$(pkg-config --libs zlib)",
"include": [
"zconf.h",
"zlib.h"
],
"trimPrefixes": ["Z_"],
"cplusplus": false,
"mix":true
}
49 changes: 49 additions & 0 deletions _llcppgtest/macos/cjson/demo/hello/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"cjson"
"unsafe"

"github.com/goplus/llgo/c"
)

func main() {
mod := cjson.Object()
mod.SetItem(c.Str("name"), cjson.String(c.Str("math")))

syms := cjson.Array()

fn := cjson.Object()
fn.SetItem(c.Str("name"), cjson.String(c.Str("sqrt")))
fn.SetItem(c.Str("sig"), cjson.String(c.Str("(x, /)")))
syms.AddItem(fn)

v := cjson.Object()
v.SetItem(c.Str("name"), cjson.String(c.Str("pi")))
syms.AddItem(v)

mod.SetItem(c.Str("items"), syms)

cstr := mod.CStr()
str := c.GoString(cstr)
c.Printf(c.Str("%s\n"), cstr)
cjson.FreeCStr(unsafe.Pointer(cstr))

mod.Delete()

cjsonLoad(str)
}

func cjsonLoad(str string) {
mod := ParseString(str)

cstr := mod.Print()
c.Printf(c.Str("%s\n"), cstr)
cjson.FreeCStr(unsafe.Pointer(cstr))

mod.Delete()
}

func ParseString(value string) *cjson.JSON {
return cjson.ParseWithLength((*c.Char)(unsafe.Pointer(unsafe.StringData(value))), uintptr(len(value)))
}
File renamed without changes.
1 change: 1 addition & 0 deletions _llcppgtest/macos/cjson/llcppg.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cJSON JSON
42 changes: 42 additions & 0 deletions _llcppgtest/macos/cjson/llcppg.symb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"mangle": "cJSON_PrintUnformatted",
"c++": "cJSON_PrintUnformatted(const cJSON *)",
"go": "(*CJSON).CStr"
},
{
"mangle": "cJSON_CreateObject",
"c++": "cJSON_CreateObject()",
"go": "Object"
},
{
"mangle": "cJSON_CreateArray",
"c++": "cJSON_free()",
"go": "Array"
},
{
"mangle": "cJSON_CreateString",
"c++": "cJSON_CreateString(const char *)",
"go": "String"
},
{
"mangle": "cJSON_free",
"c++": "cJSON_free(void *)",
"go": "FreeCStr"
},
{
"mangle": "cJSON_AddItemToArray",
"c++": "cJSON_AddItemToArray(cJSON *, cJSON *)",
"go": "(*CJSON).AddItem"
},
{
"mangle": "cJSON_AddItemToObject",
"c++": "cJSON_AddItemToObject(cJSON *, const char *, cJSON *)",
"go": "(*CJSON).SetItem"
},
{
"mangle": "cJSON_free",
"c++": "cJSON_free(void *)",
"go": "FreeCStr"
}
]
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions _llcppgtest/macos/gmp/demo/isPrime/demo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
. "gmp"
"strconv"

"github.com/goplus/llgo/c"
)

var primes = []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}

func main() {
n := &MpzStruct{}
// mpz_init is a alias for __gmpz_init
GmpzInit((MpzPtr)(n))

for _, prime := range primes {
GmpzSetStr((MpzPtr)(n), c.AllocaCStr(strconv.Itoa(prime)), 0)

if GmpzProbabPrimeP((MpzSrcptr)(n), 25) <= 1 {
fmt.Errorf("unexpected prime result: %d", prime)
}
}
fmt.Println("all prime tests passed.")
}
File renamed without changes.
27 changes: 27 additions & 0 deletions _llcppgtest/macos/gpgerror/demo/keyerror/keyerror.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"gpgerror"

"github.com/goplus/llgo/c"
)

var SOURCEMASK = gpgerror.SOURCEDIM - 1
var CODEMASK = gpgerror.CODEDIM - 1

func ErrMake(source gpgerror.SourceT, code gpgerror.CodeT) gpgerror.ErrorT {
if code == gpgerror.NOERROR {
return gpgerror.ErrorT(gpgerror.NOERROR)
}

return gpgerror.ErrorT(((c.Int(source) & c.Int(SOURCEMASK)) << gpgerror.SOURCE_SHIFT) | (c.Int(code) & c.Int(CODEMASK)))
}

func main() {
gpgerror.Init()
err := ErrMake(gpgerror.SOURCEUSER1, gpgerror.BADKEY)
errStr := err.Strerror()
source := err.Strsource()
c.Printf(c.Str("Error: %s\n"), errStr)
c.Printf(c.Str("Source: %s\n"), source)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions _llcppgtest/macos/libxslt/demo/withdeplibxml/output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html><body>
<h1>个人信息</h1>
<p>姓名: Alice</p>
<p>年龄: 25</p>
</body></html>
File renamed without changes.
20 changes: 20 additions & 0 deletions _llcppgtest/macos/lua/demo/hello/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"lua"

"github.com/goplus/llgo/c"
)

func main() {
L := lua.Newstate__1()
defer L.Close()
L.Openlibs()
if res := L.Loadstring(c.Str("print('hello world')")); res != lua.OK {
panic("error")
}
// MULTRET -> -1
if res := L.Pcallk(c.Int(0), c.Int(-1), c.Int(0), 0, nil); res != 0 {
panic("error")
}
}
27 changes: 27 additions & 0 deletions _llcppgtest/macos/lua/demo/loadcall/loadcall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
_ "unsafe"

"lua"

"github.com/goplus/llgo/c"
)

func main() {
L := lua.Newstate__1()
defer L.Close()

L.Openlibs()
if res := L.Loadstring(c.Str("print('hello world')")); res != lua.OK {
println("error")
}
if res := L.Pcallk(0, 0, 0, 0, nil); res != lua.OK {
println("error")
}

}

/* Expected output:
hello world
*/
Loading
Loading