Skip to content

Commit f5654c8

Browse files
authored
[bug] fix downloader for go binary (#1797)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Fix downloader for Go binaries by updating library filename format and handling OS/architecture specifics in `lib.go`. > > - **Behavior**: > - Update `getTargetLibFilename()` in `lib.go` to use `libbaml_cffi` and format filenames with `targetTriple` for different OS and architectures. > - Add `isMusl()` function in `lib.go` to determine musl libc usage (not yet implemented). > - Modify error message in `downloadBamlLibrary()` in `lib.go` to include 'v' prefix in version tag for 404 errors. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 0e7c34b. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 1cf28bb commit f5654c8

File tree

1 file changed

+34
-13
lines changed
  • engine/language_client_go/baml_go

1 file changed

+34
-13
lines changed

engine/language_client_go/baml_go/lib.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,29 +334,50 @@ func getCacheDir() (string, error) {
334334

335335
func getTargetLibFilename() (string, error) {
336336
goos, goarch := runtime.GOOS, runtime.GOARCH
337-
libName, tag := "libbaml", "v"+VERSION
338-
var ext, arch string
337+
libName := "libbaml_cffi"
338+
var ext, targetTriple string
339339
switch goos {
340340
case "linux":
341341
ext = "so"
342+
if isMusl() {
343+
if goarch == "amd64" {
344+
targetTriple = "x86_64-unknown-linux-musl"
345+
} else if goarch == "arm64" {
346+
targetTriple = "aarch64-unknown-linux-musl"
347+
} else {
348+
return "", fmt.Errorf("%w: unsupported architecture %s", ErrNotSupportedPlatform, goarch)
349+
}
350+
} else {
351+
if goarch == "amd64" {
352+
targetTriple = "x86_64-unknown-linux-gnu"
353+
} else if goarch == "arm64" {
354+
targetTriple = "aarch64-unknown-linux-gnu"
355+
} else {
356+
return "", fmt.Errorf("%w: unsupported architecture %s", ErrNotSupportedPlatform, goarch)
357+
}
358+
}
342359
case "darwin":
343360
ext = "dylib"
361+
if goarch == "amd64" {
362+
targetTriple = "x86_64-apple-darwin"
363+
} else if goarch == "arm64" {
364+
targetTriple = "aarch64-apple-darwin"
365+
} else {
366+
return "", fmt.Errorf("%w: unsupported architecture %s", ErrNotSupportedPlatform, goarch)
367+
}
344368
default:
345369
return "", fmt.Errorf("%w: unsupported OS %s", ErrNotSupportedPlatform, goos)
346370
}
347-
switch goarch {
348-
case "amd64":
349-
arch = "x86_64"
350-
case "arm64":
351-
arch = "aarch64"
352-
default:
353-
return "", fmt.Errorf("%w: unsupported architecture %s", ErrNotSupportedPlatform, goarch)
354-
}
355-
return fmt.Sprintf("%s-%s-%s-%s.%s", libName, tag, goos, arch, ext), nil
371+
return fmt.Sprintf("%s-%s.%s", libName, targetTriple, ext), nil
372+
}
373+
374+
func isMusl() bool {
375+
// TODO: Implement this
376+
return false
356377
}
357378

358379
func downloadBamlLibrary(destDir string, filename string) error {
359-
tag := "v" + VERSION
380+
tag := VERSION
360381
downloadURL := fmt.Sprintf("https://github.com/%s/releases/download/%s/%s", githubRepo, tag, filename)
361382
checksumURL := fmt.Sprintf("https://github.com/%s/releases/download/%s/%s.sha256", githubRepo, tag, filename)
362383
destPath := filepath.Join(destDir, filename)
@@ -388,7 +409,7 @@ func downloadBamlLibrary(destDir string, filename string) error {
388409
if resp.StatusCode != http.StatusOK {
389410
bodyBytes, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
390411
if resp.StatusCode == http.StatusNotFound {
391-
return fmt.Errorf("%w: library file not found at %s (HTTP 404). Check release tag '%s' and filename '%s'", ErrDownloadFailed, downloadURL, tag, filename)
412+
return fmt.Errorf("%w: library file not found at %s (HTTP 404). Check release tag 'v%s' and filename '%s'", ErrDownloadFailed, downloadURL, tag, filename)
392413
}
393414
return fmt.Errorf("%w: unexpected HTTP status %d fetching %s. Server response: %s", ErrDownloadFailed, resp.StatusCode, downloadURL, string(bodyBytes))
394415
}

0 commit comments

Comments
 (0)