Skip to content

Commit

Permalink
Merge pull request goplus#156 from luoliwoshang/demotest/deps
Browse files Browse the repository at this point in the history
llcppg:libxslt depend libxml
  • Loading branch information
tsingbx authored Jan 15, 2025
2 parents 61c90ac + 9510f73 commit 30a952d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions _llcppgtest/libxslt/demo/withdeplibxml/demo.go
Original file line number Diff line number Diff line change
@@ -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 :=
`<?xml version='1.0'?>
<root>
<person>
<name>Alice</name>
<age>25</age>
</person>
</root>`
xslt := `<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>个人信息</h1>
<p>姓名: <xsl:value-of select="root/person/name"/></p>
<p>年龄: <xsl:value-of select="root/person/age"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
`
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))
}
34 changes: 34 additions & 0 deletions _llcppgtest/libxslt/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 9 additions & 2 deletions cmd/gogensig/gogensig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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")
}

Expand Down

0 comments on commit 30a952d

Please sign in to comment.