wasi-module-sdk-go/exec/lookup.go

44 lines
902 B
Go
Raw Normal View History

package exec
import (
"errors"
"fmt"
2023-08-15 20:10:30 +00:00
2023-08-17 15:04:58 +00:00
rpcv1 "code.icb4dc0.de/buildr/api/generated/rpc/v1"
2023-08-15 20:10:30 +00:00
"code.icb4dc0.de/buildr/wasi-module-sdk-go/mem"
)
func LookPath(file string) (string, error) {
lookupPathReq := &rpcv1.LookupPathRequest{
Command: file,
}
data, err := lookupPathReq.MarshalVT()
if err != nil {
return "", err
}
result := _lookPath(mem.DataToManagedPtr(data))
if result == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
resultPtr := uint32(result >> 32)
resultSize := uint32(result)
if resultSize == 0 {
return "", fmt.Errorf("failed to lookup in path: %s", file)
}
lookupPathResp := new(rpcv1.LookupPathResponse)
if err := lookupPathResp.UnmarshalVT(mem.PtrToData(resultPtr, resultSize)); err != nil {
return "", err
}
if len(lookupPathResp.Error) > 0 {
return "", errors.New(lookupPathResp.Error)
}
return lookupPathResp.Path, nil
}