Skip to content

Releases: goplus/llcppg

v0.6.0

17 Jun 12:23
0ff435d

Choose a tag to compare

What's Changed

llcppsigfetch

llcppsymg

cl

docs

ci

deps

test

Full Changelog: v0.5.1...v0.6.0

Function pointer

C function pointer types are converted to Go function types with corresponding parameter and return type mappings,And llgo need to add llgo:type C tag to the function type.

typedef int (*CallBack)(void *L);
// llgo:type C
type CallBack func(c.Pointer) c.Int

For function pointer types referenced in function signatures & struct fields, the type is replaced with the converted Go function type.

void exec(void *L, CallBack cb);
// llgo:type C
func Exec(L c.Pointer, cb CallBack)
typedef struct Stream {
    CallBack cb;
} Stream;
type Stream struct {
	Cb CallBack
}

v0.5.1

04 Jun 07:50
d68480a

Choose a tag to compare

What's Changed

parser & ast:

llcppsymg:

gogensig & cl:

e2e test:

unit test:

deps & ci:

docs:

changes:

Full Changelog: v0.5.0...v0.5.1

v0.5.0

24 May 17:13
5ac9af4

Choose a tag to compare

What's Changed

parser & ast:

compiler:

llcppg/tool:

unit test:

deps & ci:

Full Changelog: v0.4.0...v0.5.0

v0.4.0

17 May 13:58
a36855d

Choose a tag to compare

What's Changed

parser:

cl:

llcppg/tool:

refactor:

cmd/llclang:

deps:

  • chore(deps): bump github.com/goplus/mod from 0.16.0 to 0.16.1 by @dependabot in #301
  • chore(deps): bump github.com/qiniu/x from 1.14.0 to 1.14.6 by @dependabot in #332
  • chore(deps): bump github.com/goplus/gogen 1.18.1 by @dependabot in #330

Full Changelog: v0.3.1...v0.4.0

v0.3.1

07 May 10:54
c0c3bc2

Choose a tag to compare

What's Changed

feat:

deps:

  • chore(deps): bump github.com/goplus/gogen from 1.17.2 to 1.17.3 by @dependabot in #284

changes:

Full Changelog: v0.3.0...v0.3.1

v0.3.0

25 Apr 11:02
d6ee940

Choose a tag to compare

What's Changed

features:

ci/deps:

test:

readme:

changes:

New Contributors

Full Changelog: v0.2.1...v0.3.0

Customizing Bindings

Function Customization

After execution, you can directly see the mapped functions in the result.

//go:linkname CreateObject C.cJSON_CreateObject
func CreateObject() *CJSON
// llgo:link (*CJSON).AddItemToObject C.cJSON_AddItemToObject
func (recv_ *CJSON) AddItemToObject(string *c.Char, item *CJSON) Bool {
	return 0
}
/* Render a cJSON entity to text for transfer/storage without any formatting. */
// llgo:link (*CJSON).PrintUnformatted C.cJSON_PrintUnformatted
func (recv_ *CJSON) PrintUnformatted() *c.Char {
	return nil
}

You can specify function mapping behavior in llcppg.cfg by config the symMap field:

{
    "symMap":{
        "mangle":"<goFuncName> | <.goMethodName> | -"
    }
}

mangle is the symbol name of the function. For the value of mangle, you can customize it as:

  1. goFuncName - generates a regular function named goFuncName
  2. .goMethodName - generates a method named goMethodName (if it doesn't meet the rules for generating a method, it will be generated as a regular function)
  3. - - completely ignore this function

For example, to convert (*CJSON).PrintUnformatted from a method to a function, you can use follow config:

{
  "symMap":{
    "cJSON_PrintUnformatted":"PrintUnformatted"
  }
}

This will generate a function instead of a method in the Go code:

//go:linkname PrintUnformatted C.cJSON_PrintUnformatted
func PrintUnformatted(item *CJSON) *c.Char

You can also run llcppsymg separately. To do this, use the command:

llcppg -symbgen

If you only want to generate Go code using an already generated symbol table, execute:

llcppg -codegen

Type Customization

You can customize type name mappings to better suit your needs.

For instance, if you prefer to use JSON instead of cJSON as the Go type name, simply config the typeMap field of llcppg.cfg as follows:

{
  "typeMap": {
    "cJSON": "JSON"
  }
}

After running llcppg again, all generated code will use the new type name. The struct definition and its methods will be automatically updated:

type JSON struct {
  // .....
}
// llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered
func (recv_ *JSON) PrintBuffered(prebuffer c.Int, fmt Bool) *int8 {
	return nil
}

More demo projects and configuration files can be found under _llcppgtest directory.

v0.2.1

03 Apr 02:13
b74c0e8

Choose a tag to compare

Function Customization

When you run llcppg directly with the above configuration, it will generate function names according to the configuration. After execution, you'll find a llcppg.symb.json file in the current directory.

[
  {
    "mangle": "cJSON_CreateObject",
    "c++": "cJSON_CreateObject()",
    "go": "CreateObject"
  },
  {
    "mangle": "cJSON_AddItemToObject",
    "c++": "cJSON_AddItemToObject(cJSON *, const char *, cJSON *)",
    "go": "(*CJSON).AddItemToObject"
  },
  {
    "mangle": "cJSON_PrintUnformatted",
    "c++": "cJSON_PrintUnformatted(const cJSON *)",
    "go": "(*CJSON).PrintUnformatted"
  },
]
  • mangle field contains the symbol name of function

  • c++ field shows the function prototype from the header file

  • go field displays the function name that will be generated in LLGo binding.

    You can customize this field to:

    1. Change function names (e.g. "CreateObject" to "Object" for simplicity)
    2. Remove the method receiver prefix to generate a function instead of a method
    3. Set it to "-" to completely ignore this function

What's Changed

Full Changelog: v0.2.0...v0.2.1

v0.2.0

27 Mar 06:00
47cda66

Choose a tag to compare

What's Changed

features:

docs:

changes:

Full Changelog: v0.1.0...v0.2.0

Usage

After creating the configuration file, run:

llcppg llcppg.cfg

If you're not in a Go module or want to create a separate module, you can use the -mod flag to create a new Go module for the generated package:

llcppg -mod github.com/author/cjson llcppg.cfg

After execution,LLGo Binding will be generated in a directory named after the config name (which is also the package name). For example, with the cjson configuration above, you'll see:

cjson/
├── cJSON.go
├── cJSON_Utils.go
├── cjson_autogen_link.go
├── llcppg.pub
├── go.mod  # Contains: module github.com/author/cjson (only when using -mod flag)
└── go.sum  # Contains dependency checksums (only when using -mod flag)

v0.1.0

13 Mar 15:35
f1d4db5

Choose a tag to compare

What's Changed

llcppg

llcppsymg (c symbol info generate component)

llcppsigfetch (c ast info fetch component)

  • llcppsigfetch:abs include path & system header & config mode 's include flags by @luoliwoshang in #6
  • llcppsigfetch:fix unexpect typedef decl when forward decl implement by @luoliwoshang in #40
  • llcppsigfetch:support elaborate functype in funcdecl by @luoliwoshang in #49
  • llcppsigfetch:recursive resolve typedefs to get underlying func type by @luoliwoshang in #52
  • fix llcppgsigfetch: lost receiver by @tsingbx in #89
  • llcppsigfetch:remove redundant case for param collect by @luoliwoshang in #129
  • llcppsigfetch:get normal comment by -fparse-all-comments by @luoliwoshang in #210

gogensig (go code generate component)

llcppgcfg (auto generate llcppg.cfg)

  • add llcppcfg by @tsingbx in #29
  • llcppcfg: support to sort header files by dependencies by @tsingbx in #130
  • modify cfg := NewRunConfig(runPkgMode(appMode)... to cfg := NewRunCon… by @tsingbx in #170
  • llcppcfg print clang command error & fix llcppgtest liblzma fail by @tsingbx in #199

llcppgtest (tools for test local c libraries)

ci

Read more