gorules / zen-go

Open-source business rules engine for Go
https://gorules.io
MIT License
76 stars 8 forks source link

Getting Linker Issues on Debian 12 / amd64 #2

Closed egandro closed 7 months ago

egandro commented 1 year ago

I created a simple go/no-go test in my framework.

package checker

import (
    "os"
    "path"
    "testing"

    "github.com/gorules/zen-go"
)

// ideas from here https://github.com/gorules/zen-go/blob/master/zen_engine_test.go

func readTestFile(key string) ([]byte, error) {
    filePath := path.Join("testdata", key)
    return os.ReadFile(filePath)
}

func TestReadTestFile(t *testing.T) {
    bytes, err := readTestFile("function.json")

    if err != nil {
        t.Errorf("read json file failed: %v", err)
        return
    }

    if len(bytes) < 1 {
        t.Errorf("json file is empty")
        return
    }
}

func TestZenEngine(t *testing.T) {
    zenEngine := zen.NewEngine(readTestFile)
    defer zenEngine.Dispose()

    if zenEngine == nil {
        t.Errorf("can't create engine")
        return
    }

    fileData, err := readTestFile("function.json")

    if err != nil {
        t.Errorf("read json file failed: %v", err)
        return
    }

    if fileData == nil {
        t.Errorf("json file is empty")
        return
    }

    decision, err := zenEngine.CreateDecision(fileData)
    defer decision.Dispose()
    if err != nil {
        t.Errorf("read json file failed: %v", err)
        return
    }

    inputJson := `{"input":5}`
    outputJson := `{"output":0}`

    result, err := zenEngine.Evaluate(inputJson, nil)
    if err != nil {
        t.Errorf("evaluation failed: %v", err)
        return
    }

    if string(result.Result) != outputJson {
        t.Errorf("expected: %v - got: %v", outputJson, result.Result)
        return
    }

}

I am getting this results:

 go test -v ./pkg/checker            
# example.com/pkg/checker.test
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lzen_ffi: No such file or directory
collect2: error: ld returned 1 exit status

The file is in $HOME/go/pkg/mod/github.com/gorules/zen-go@v0.0.2/deps/linux_amd64

(edit fixed error)

egandro commented 1 year ago

Willing to provide a Repo/Dockerfile for testing.

egandro commented 1 year ago

This repo shows the issue.

https://github.com/egandro/zen-go-issue

egandro commented 1 year ago

The .a file contains the wrong CPU / data

cd deps/linux_amd64 
/usr/bin/ar x *.a
file *.o | head -10
abort_message.o:                                                                            Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
abstract-code.o:                                                                            Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
absvdi2.o:                                                                                  Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
absvsi2.o:                                                                                  Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
absvti2.o:                                                                                  Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
access-builder.o:                                                                           Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
access-info.o:                                                                              Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
accessors.o:                                                                                Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
accounting-allocator.o:                                                                     Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
active-system-pages.o:                                                                      Mach-O 64-bit arm64 object, flags:<|SUBSECTIONS_VIA_SYMBOLS>
egandro commented 1 year ago

That is what I get from my own builds.

➜  release git:(experiments/ffi) /usr/bin/ar x *.a
➜  release git:(experiments/ffi) file *.o | head -10
abort_message.o:                                                                            ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
abstract-code.o:                                                                            ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
absvdi2.o:                                                                                  ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
absvsi2.o:                                                                                  ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
absvti2.o:                                                                                  ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
access-builder.o:                                                                           ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
access-info.o:                                                                              ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
accessors.o:                                                                                ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
accounting-allocator.o:                                                                     ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
active-system-pages.o:                                                                      ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
egandro commented 1 year ago

I also need "-lm" on Debian.

egandro commented 1 year ago

I fixed the issue.

https://github.com/gorules/zen-go/compare/master...egandro:zen-go:master

egandro commented 1 year ago

it doesn't work :/ we have to go with either a dynamic library or a deb/rpm installer

ivanmiletic commented 7 months ago

Closing, we will be releasing GoLang support in upcoming weeks