fetch_ml/internal/worker/native_bridge_libs.go
Jeremie Fraeys 96a8e139d5
refactor(internal): update native bridge and queue integration
- Improve native queue integration in protocol layer
- Update native bridge library loading
- Clean up queue native implementation
2026-02-18 12:45:59 -05:00

60 lines
1.5 KiB
Go

//go:build cgo && native_libs
// +build cgo,native_libs
package worker
// #cgo LDFLAGS: -L${SRCDIR}/../../native/build -Wl,-rpath,${SRCDIR}/../../native/build -ldataset_hash
// #include "../../native/dataset_hash/dataset_hash.h"
// #include <stdlib.h>
import "C"
import (
"errors"
"unsafe"
"github.com/jfraeys/fetch_ml/internal/manifest"
)
// dirOverallSHA256HexNative implementation with native library.
func dirOverallSHA256HexNative(root string) (string, error) {
ctx := C.fh_init(0) // 0 = auto-detect threads
if ctx == nil {
return "", errors.New("failed to initialize native hash context")
}
defer C.fh_cleanup(ctx)
croot := C.CString(root)
defer C.free(unsafe.Pointer(croot))
result := C.fh_hash_directory_combined(ctx, croot)
if result == nil {
err := C.fh_last_error(ctx)
if err != nil {
return "", errors.New(C.GoString(err))
}
return "", errors.New("native hash failed")
}
defer C.fh_free_string(result)
return C.GoString(result), nil
}
// GetSIMDImplName returns the native SHA256 implementation name.
func GetSIMDImplName() string {
return C.GoString(C.fh_get_simd_impl_name())
}
// HasSIMDSHA256 returns true if SIMD SHA256 is available.
func HasSIMDSHA256() bool {
return C.fh_has_simd_sha256() == 1
}
// ScanArtifactsNative falls back to Go implementation.
func ScanArtifactsNative(runDir string) (*manifest.Artifacts, error) {
return ScanArtifacts(runDir)
}
// ExtractTarGzNative falls back to Go implementation.
func ExtractTarGzNative(archivePath, dstDir string) error {
return ExtractTarGz(archivePath, dstDir)
}