diff --git a/installer/installer.go b/installer/installer.go index 89b64f276..82a6a9c21 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -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 { diff --git a/installer/installer_test.go b/installer/installer_test.go index 68fc5b1df..9806582ec 100644 --- a/installer/installer_test.go +++ b/installer/installer_test.go @@ -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