klippa-app / go-pdfium

Easy to use PDF library using Go and PDFium
MIT License
195 stars 16 forks source link

Web assembly implementation build error after v1.12.0 upgrade #169

Closed kvdbergh closed 5 months ago

kvdbergh commented 5 months ago

Web assembly implementation no longer builds after upgrade to go-pdfium v1.12.0

Results in the following error:

# github.com/klippa-app/go-pdfium/webassembly
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:515:27: i.worker.Instance.FPDFAnnot_AddFileAttachment undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_AddFileAttachment)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:529:27: i.worker.Instance.FPDFAnnot_AddInkStroke undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_AddInkStroke)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:543:27: i.worker.Instance.FPDFAnnot_AppendAttachmentPoints undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_AppendAttachmentPoints)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:557:27: i.worker.Instance.FPDFAnnot_AppendObject undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_AppendObject)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:571:27: i.worker.Instance.FPDFAnnot_CountAttachmentPoints undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_CountAttachmentPoints)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:585:27: i.worker.Instance.FPDFAnnot_GetAP undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_GetAP)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:599:27: i.worker.Instance.FPDFAnnot_GetAttachmentPoints undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_GetAttachmentPoints)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:613:27: i.worker.Instance.FPDFAnnot_GetBorder undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_GetBorder)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:627:27: i.worker.Instance.FPDFAnnot_GetColor undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_GetColor)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:641:27: i.worker.Instance.FPDFAnnot_GetFileAttachment undefined (type *implementation_webassembly.PdfiumImplementation has no field or method FPDFAnnot_GetFileAttachment)
../../go/pkg/mod/github.com/klippa-app/go-pdfium@v1.12.0/webassembly/generated.go:641:27: too many errors

I've used the example from the readme documentation:

main.go

package renderer

import (
        "log"

        "github.com/klippa-app/go-pdfium"
        "github.com/klippa-app/go-pdfium/webassembly"
)

// Be sure to close pools/instances when you're done with them.
var pool pdfium.Pool
var instance pdfium.Pdfium

func init() {
        // Init the PDFium library and return the instance to open documents.
        // You can tweak these configs to your need. Be aware that workers can use quite some memory.
        pool, err = webassembly.Init(webassembly.Config{
                MinIdle:  1, // Makes sure that at least x workers are always available
                MaxIdle:  1, // Makes sure that at most x workers are ever available
                MaxTotal: 1, // Maxium amount of workers in total, allows the amount of workers to grow when needed, items between total max and idle max are automatically cleaned up, while idle workers are kept alive so they can be used directly.
        })

        var err error
        instance, err = pool.GetInstance(time.Second * 30)
        if err != nil {
                log.Fatal(err)
        }
}

go.mod

module pdfium-webassembly-test

go 1.22

require github.com/klippa-app/go-pdfium v1.12.0

require (
        github.com/google/uuid v1.6.0 // indirect
        github.com/jolestar/go-commons-pool/v2 v2.1.2 // indirect
        github.com/tetratelabs/wazero v1.7.1 // indirect
        golang.org/x/net v0.24.0 // indirect
        golang.org/x/text v0.14.0 // indirect
)
jerbob92 commented 5 months ago

That's odd, FPDFAnnot_AddInkStroke for example has been included for a long time now. Something else must be going on, will look into it!

jerbob92 commented 5 months ago

This was a really dumb issue, sometimes I copy code from the CGO implementation to the WebAssembly implementation and then Goland also copies the import "C", but it doesn't automatically remove it when you don't do any CGO calls. When you then have no CGO available in your environment, the build fails. I have added some extra steps to catch this in the CI process next time.

jerbob92 commented 5 months ago

@kvdbergh fixed in v1.12.1!

kvdbergh commented 5 months ago

Thanks @jerbob92 for fixing this issue!