Skip to content

Commit

Permalink
fixup! Make Go bridge work on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Jul 28, 2024
1 parent e02517e commit 87cc6b2
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions go/sppark.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ package sppark
// #ifndef GO_CGO_EXPORT_PROLOGUE_H
// #ifdef _WIN32
// # include <windows.h>
// # include <stdio.h>
// static char hex_from_nibble(unsigned char nibble)
// {
// int mask = (9 - (nibble &= 0xf)) >> 31;
// return (char)(nibble + ((('a'-10) & mask) | ('0' & ~mask)));
// }
// #else
// # include <dlfcn.h>
// # include <errno.h>
Expand Down Expand Up @@ -87,17 +91,31 @@ package sppark
// break;
// }
// #ifdef __SPPARK_CGO_DEBUG__
// printf("%p %s\n", sym->value, sym->name);
// fprintf(stderr, "%p %s\n", sym->value, sym->name);
// #endif
// }
// }
// }
//
// if (h == NULL) {
// #ifdef _WIN32
// static char buf[24];
// snprintf(buf, sizeof(buf), "WIN32 Error #0x%x", GetLastError());
// toGoString(err, buf);
// char *msg = NULL;
// unsigned int win_err = GetLastError();
// if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER,
// NULL, win_err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// (char *)&msg, 0, NULL)) {
// toGoString(err, msg);
// LocalFree(msg);
// } else {
// static char buf[24] = "WIN32 Error #0x";
// msg = buf + 15;
// do {
// *msg++ = hex_from_nibble(win_err>>4);
// *msg++ = hex_from_nibble(win_err);
// } while (win_err >>= 8);
// *msg = '\0';
// toGoString(err, buf);
// }
// if (hmod) FreeLibrary(hmod);
// #else
// toGoString(err, dlerror());
Expand Down Expand Up @@ -136,6 +154,11 @@ func init() {
}

func Load(baseName string, options ...string) {
goArch := runtime.GOARCH
if goArch != "amd64" && goArch != "arm64" {
log.Panicf("%s: unsupported GOARCH", goArch)
}

baseName = strings.TrimSuffix(baseName, filepath.Ext(baseName))

var dst, src string
Expand Down Expand Up @@ -207,6 +230,9 @@ func build(dst string, src string, custom_args ...string) bool {
args = append(args, filepath.Join(SrcRoot, "util", "all_gpus.cpp"))
args = append(args, "assembly.o", "cpuid.o")
if runtime.GOOS != "windows" {
if cxx, ok := os.LookupEnv("CXX"); ok {
args = append(args, "-ccbin", cxx)
}
args = append(args, "-Xcompiler", "-fPIC,-fvisibility=hidden")
args = append(args, "-Xlinker", "-Bsymbolic")
}
Expand Down

0 comments on commit 87cc6b2

Please sign in to comment.