Skip to content

Commit

Permalink
feat: add native lib path function
Browse files Browse the repository at this point in the history
  • Loading branch information
becheran committed Feb 2, 2024
1 parent dc5ff3e commit f6eca29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 10 additions & 7 deletions installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import (
"github.com/spf13/afero"
)

// NativeLibPath returns the absolute path to the go package used to link to the native rust library
func NativeLibPath() string {
_, file, _, ok := runtime.Caller(0)
if !ok {
return ""
}
pactRoot := filepath.Dir(filepath.Dir(file))
return filepath.Join(pactRoot, "internal", "native")
}

// Installer is used to check the Pact Go installation is setup correctly, and can automatically install
// packages if required
type Installer struct {
Expand Down Expand Up @@ -135,13 +145,6 @@ func (i *Installer) getLibDir() string {
return env
}

if runtime.GOOS == "windows" {
if out, err := exec.Command("powershell", "-Command", "(Get-Command gcc).Source").Output(); err == nil && len(out) > 0 {
result := filepath.Dir(strings.TrimSpace(string(out)))
return result
}
}

return "/usr/local/lib"
}

Expand Down
11 changes: 11 additions & 0 deletions installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ package installer

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)

func TestNativeLibPath(t *testing.T) {
lib := NativeLibPath()

libFilePath := filepath.Join(lib, "lib.go")
file, err := os.ReadFile(libFilePath)
assert.NoError(t, err)
assert.Contains(t, string(file), "-lpact_ffi")
}

// 1. Be able to specify the path of the binary in advance
// 2. Check if the correct versions of the libs are present???
// 3. Download the appropriate libs
Expand Down

0 comments on commit f6eca29

Please sign in to comment.