Skip to content
Draft
4 changes: 3 additions & 1 deletion _xtool/llcppsymg/internal/symg/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestGenDylibPaths(t *testing.T) {
}

if err != nil {
t.Fatalf("expected no error, got %w", err)
t.Fatalf("expected no error, got %v", err)
}

if !reflect.DeepEqual(notFounds, tc.wantNotFound) {
Expand All @@ -188,3 +188,5 @@ func TestGenDylibPaths(t *testing.T) {

}
}


Comment thread
luoliwoshang marked this conversation as resolved.
Outdated
4 changes: 2 additions & 2 deletions _xtool/llcppsymg/internal/symg/symg.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type Config struct {
TrimPrefixes []string
SymMap map[string]string
IsCpp bool
libMode LibMode
LibMode LibMode
}

func Do(conf *Config) (symbolTable []*llcppg.SymbolInfo, err error) {
symbols, err := fetchSymbols(conf.Libs, conf.libMode)
symbols, err := fetchSymbols(conf.Libs, conf.LibMode)
if err != nil {
return
}
Expand Down
7 changes: 7 additions & 0 deletions _xtool/llcppsymg/llcppsymg.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"

"github.com/goplus/llcppg/_xtool/internal/symbol"
"github.com/goplus/llcppg/_xtool/llcppsymg/internal/symg"
llcppg "github.com/goplus/llcppg/config"
args "github.com/goplus/llcppg/internal/arg"
Expand Down Expand Up @@ -64,6 +65,11 @@ func main() {
fmt.Fprintln(os.Stderr, "Failed to parse config file:", ags.CfgFile)
}

libMode := symbol.ModeDynamic
if conf.LibStatic {
libMode = symbol.ModeStatic
}
Comment thread
luoliwoshang marked this conversation as resolved.

symbolTable, err := symg.Do(&symg.Config{
Libs: conf.Libs,
CFlags: conf.CFlags,
Expand All @@ -72,6 +78,7 @@ func main() {
TrimPrefixes: conf.TrimPrefixes,
SymMap: conf.SymMap,
IsCpp: conf.Cplusplus,
LibMode: libMode,
})
check(err)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
Mix bool `json:"mix,omitempty"`
SymMap map[string]string `json:"symMap,omitempty"`
TypeMap map[string]string `json:"typeMap,omitempty"`
LibStatic bool `json:"libstatic,omitempty"`
}

func NewDefault() *Config {
Expand Down
19 changes: 19 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ func TestGetConfByByte(t *testing.T) {
mode: useStdin,
},

{
name: "Static library configuration",
input: `{
"name": "mylib",
"cflags": "-I/opt/homebrew/include",
"include": ["mylib.h"],
"libs": "-L/opt/homebrew/lib -lmylib",
"libstatic": true
}`,
expect: llconfig.Config{
Name: "mylib",
CFlags: "-I/opt/homebrew/include",
Include: []string{"mylib.h"},
Libs: "-L/opt/homebrew/lib -lmylib",
LibStatic: true,
},
mode: useFile,
},

{
name: "Invalid JSON",
input: `{invalid json}`,
Expand Down
Loading