fix wasi-libc caching path
This commit is contained in:
@@ -180,14 +180,8 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
|
|||||||
// If not exists in LLGoROOT, download and use cached wasiSdkRoot
|
// If not exists in LLGoROOT, download and use cached wasiSdkRoot
|
||||||
if _, err = os.Stat(wasiSdkRoot); err != nil {
|
if _, err = os.Stat(wasiSdkRoot); err != nil {
|
||||||
sdkDir := filepath.Join(cacheDir(), llvm.GetTargetTriple(goos, goarch))
|
sdkDir := filepath.Join(cacheDir(), llvm.GetTargetTriple(goos, goarch))
|
||||||
if _, err = os.Stat(sdkDir); err != nil {
|
if wasiSdkRoot, err = checkDownloadAndExtract(wasiSdkUrl, sdkDir); err != nil {
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if wasiSdkRoot, err = downloadAndExtract(wasiSdkUrl, sdkDir); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// WASI-SDK configuration
|
// WASI-SDK configuration
|
||||||
|
|||||||
@@ -12,36 +12,36 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func downloadAndExtract(url, dir string) (wasiSdkRoot string, err error) {
|
func checkDownloadAndExtract(url, dir string) (wasiSdkRoot string, err error) {
|
||||||
if _, err = os.Stat(dir); err == nil {
|
if _, err = os.Stat(dir); err != nil {
|
||||||
os.RemoveAll(dir)
|
os.RemoveAll(dir)
|
||||||
}
|
tempDir := dir + ".temp"
|
||||||
tempDir := dir + ".temp"
|
os.RemoveAll(tempDir)
|
||||||
os.RemoveAll(tempDir)
|
if err := os.MkdirAll(tempDir, 0755); err != nil {
|
||||||
if err := os.MkdirAll(tempDir, 0755); err != nil {
|
return "", fmt.Errorf("failed to create temporary directory: %w", err)
|
||||||
return "", fmt.Errorf("failed to create temporary directory: %w", err)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
urlPath := strings.Split(url, "/")
|
urlPath := strings.Split(url, "/")
|
||||||
filename := urlPath[len(urlPath)-1]
|
filename := urlPath[len(urlPath)-1]
|
||||||
localFile := filepath.Join(tempDir, filename)
|
localFile := filepath.Join(tempDir, filename)
|
||||||
if err = downloadFile(url, localFile); err != nil {
|
if err = downloadFile(url, localFile); err != nil {
|
||||||
return "", fmt.Errorf("failed to download file: %w", err)
|
return "", fmt.Errorf("failed to download file: %w", err)
|
||||||
}
|
}
|
||||||
defer os.Remove(localFile)
|
defer os.Remove(localFile)
|
||||||
|
|
||||||
if strings.HasSuffix(filename, ".tar.gz") || strings.HasSuffix(filename, ".tgz") {
|
if strings.HasSuffix(filename, ".tar.gz") || strings.HasSuffix(filename, ".tgz") {
|
||||||
err = extractTarGz(localFile, tempDir)
|
err = extractTarGz(localFile, tempDir)
|
||||||
} else if strings.HasSuffix(filename, ".tar.xz") {
|
} else if strings.HasSuffix(filename, ".tar.xz") {
|
||||||
err = extractTarXz(localFile, tempDir)
|
err = extractTarXz(localFile, tempDir)
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("unsupported archive format: %s", filename)
|
return "", fmt.Errorf("unsupported archive format: %s", filename)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to extract archive: %w", err)
|
return "", fmt.Errorf("failed to extract archive: %w", err)
|
||||||
}
|
}
|
||||||
if err = os.Rename(tempDir, dir); err != nil {
|
if err = os.Rename(tempDir, dir); err != nil {
|
||||||
return "", fmt.Errorf("failed to rename directory: %w", err)
|
return "", fmt.Errorf("failed to rename directory: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wasiSdkRoot = filepath.Join(dir, "wasi-sdk-25.0-x86_64-macos")
|
wasiSdkRoot = filepath.Join(dir, "wasi-sdk-25.0-x86_64-macos")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user