From 777cae35dbc9d2c49f7bc2f8024c7ba810918fd4 Mon Sep 17 00:00:00 2001
From: luoliwoshang <2643523683@qq.com>
Date: Tue, 14 Jan 2025 11:36:53 +0800
Subject: [PATCH 1/2] gogensig:prepare deps load
---
cmd/gogensig/gogensig.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/cmd/gogensig/gogensig.go b/cmd/gogensig/gogensig.go
index 1109c78b..4000dd5b 100644
--- a/cmd/gogensig/gogensig.go
+++ b/cmd/gogensig/gogensig.go
@@ -69,7 +69,7 @@ func main() {
wd, err := os.Getwd()
check(err)
- err = runGoCmds(wd, conf.Name)
+ err = prepareEnv(wd, conf.Name, conf.Deps)
check(err)
p, _, err := basic.ConvertProcesser(&basic.Config{
@@ -95,7 +95,7 @@ func check(err error) {
}
}
-func runGoCmds(wd, pkg string) error {
+func prepareEnv(wd, pkg string, deps []string) error {
dir := filepath.Join(wd, pkg)
err := os.MkdirAll(dir, 0744)
@@ -113,6 +113,13 @@ func runGoCmds(wd, pkg string) error {
return err
}
+ for _, dep := range deps {
+ err := config.RunCommand(dir, "go", "get", dep)
+ if err != nil {
+ return err
+ }
+ }
+
return config.RunCommand(dir, "go", "get", "github.com/goplus/llgo@main")
}
From 9510f73520c0184a9a6fb5960b334ce9b02eb3f1 Mon Sep 17 00:00:00 2001
From: luoliwoshang <2643523683@qq.com>
Date: Tue, 14 Jan 2025 11:37:40 +0800
Subject: [PATCH 2/2] demo test:libxslt dep libxml
---
.github/workflows/go.yml | 8 ++-
.../libxslt/demo/withdeplibxml/demo.go | 68 +++++++++++++++++++
_llcppgtest/libxslt/llcppg.cfg | 34 ++++++++++
3 files changed, 107 insertions(+), 3 deletions(-)
create mode 100644 _llcppgtest/libxslt/demo/withdeplibxml/demo.go
create mode 100644 _llcppgtest/libxslt/llcppg.cfg
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 85fc8fd8..e810c295 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -115,12 +115,14 @@ jobs:
if: startsWith(matrix.os, 'macos')
run: |
# install demo's lib
- brew install lua zlib isl libgpg-error raylib z3 sqlite3 gmp
+ brew install lua zlib isl libgpg-error raylib z3 sqlite3 gmp libxml2 libxslt
export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"
- export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig:/opt/homebrew/opt/zlib/lib/pkgconfig:$PKG_CONFIG_PATH"
-
+ export PKG_CONFIG_PATH="/opt/homebrew/opt/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH"
+ export PKG_CONFIG_PATH="/opt/homebrew/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH"
+ export PKG_CONFIG_PATH="/opt/homebrew/opt/libxslt/lib/pkgconfig:$PKG_CONFIG_PATH"
pkg-config --cflags --libs sqlite3
+ pkg-config --cflags --libs libxslt
llcppgtest -demos ./_llcppgtest
diff --git a/_llcppgtest/libxslt/demo/withdeplibxml/demo.go b/_llcppgtest/libxslt/demo/withdeplibxml/demo.go
new file mode 100644
index 00000000..0fda39c8
--- /dev/null
+++ b/_llcppgtest/libxslt/demo/withdeplibxml/demo.go
@@ -0,0 +1,68 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "unsafe"
+
+ "libxslt"
+
+ "github.com/goplus/llgo/c"
+ libxml2 "github.com/luoliwoshang/llcppg-libxml"
+)
+
+func main() {
+ libxml2.XmlInitParser()
+
+ xml :=
+ `
+
+
+ Alice
+ 25
+
+ `
+ xslt := `
+
+
+
+
+ 个人信息
+ 姓名:
+ 年龄:
+
+
+
+
+ `
+ xmlDoc := libxml2.XmlReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xml))), c.Int(len(xml)), nil, nil, 0)
+ xsltDoc := libxml2.XmlReadMemory((*int8)(unsafe.Pointer(unsafe.StringData(xslt))), c.Int(len(xslt)), nil, nil, 0)
+
+ if xmlDoc == nil || xsltDoc == nil {
+ panic("cant read xml or xslt")
+ }
+
+ stylesheet := libxslt.XsltParseStylesheetDoc(xsltDoc)
+ if stylesheet == nil {
+ panic("cant parse xslt")
+ }
+ result := libxslt.XsltApplyStylesheet(stylesheet, xmlDoc, (**int8)(unsafe.Pointer(uintptr(0))))
+ if result == nil {
+ panic("cant apply xslt")
+ }
+
+ libxslt.XsltSaveResultToFilename(c.Str("output.html"), result, stylesheet, 0)
+
+ libxml2.XmlFreeDoc(xmlDoc)
+ libxml2.XmlFreeDoc(result)
+ libxslt.XsltFreeStylesheet(stylesheet)
+
+ libxslt.XsltCleanupGlobals()
+ libxml2.XmlCleanupParser()
+
+ buf, err := os.ReadFile("./output.html")
+ if err != nil {
+ panic(err)
+ }
+ fmt.Println(string(buf))
+}
diff --git a/_llcppgtest/libxslt/llcppg.cfg b/_llcppgtest/libxslt/llcppg.cfg
new file mode 100644
index 00000000..8b071e9e
--- /dev/null
+++ b/_llcppgtest/libxslt/llcppg.cfg
@@ -0,0 +1,34 @@
+{
+ "name": "libxslt",
+ "cflags": "$(pkg-config --cflags libxslt)",
+ "libs": "$(pkg-config --libs libxslt)",
+ "include": [
+ "libxslt/variables.h",
+ "libxslt/functions.h",
+ "libxslt/xsltutils.h",
+ "libxslt/templates.h",
+ "libxslt/pattern.h",
+ "libxslt/preproc.h",
+ "libxslt/extra.h",
+ "libxslt/documents.h",
+ "libxslt/imports.h",
+ "libxslt/keys.h",
+ "libxslt/transform.h",
+ "libxslt/attributes.h",
+ "libxslt/security.h",
+ "libxslt/extensions.h",
+ "libxslt/xsltInternals.h",
+ "libexslt/exslt.h",
+ "libxslt/numbersInternals.h",
+ "libxslt/namespaces.h",
+ "libxslt/xslt.h",
+ "libxslt/xsltlocale.h",
+ "libexslt/exsltexports.h",
+ "libxslt/xsltconfig.h",
+ "libxslt/xsltexports.h",
+ "libexslt/exsltconfig.h"
+ ],
+ "deps": ["github.com/luoliwoshang/llcppg-libxml"],
+ "trimPrefixes": [],
+ "cplusplus": false
+}