Build the Tentacle SDK without cgo

The SDK reaches internal/datetime through settings validation, and that
package had only a cgo strftime implementation, so statically linked
Tentacle packages could not build. Split the locale-aware cgo formatter
into its own file and add a C-locale fallback for builds without cgo.
The reader itself still uses the cgo implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chase CichorzandClaude Opus 5.5 committed 2026-11-06 16:06:38 -05:00
1 parent cb4d98545f
commit 8e0ac3b258
4 files changed
+153 -36

No files matched your search

+1 -36
View File
@@ -4,17 +4,7 @@
package datetime
/*
#include <locale.h>
#include <stdlib.h>
#include <time.h>
*/
import "C"
import (
"time"
"unsafe"
)
import "time"
type Option struct {
Value string
@@ -56,12 +46,6 @@ var dateFormats = []struct {
{"abbreviated-ymd", "%Y. %b %-d, %a"},
}
func init() {
locale := C.CString("")
defer C.free(unsafe.Pointer(locale))
C.setlocale(C.LC_TIME, locale)
}
func TimeOptions(now time.Time) []Option {
return options(timeFormats, now)
}
@@ -133,22 +117,3 @@ func valid(formats []struct {
}
return false
}
func format(now time.Time, spec string) string {
cSpec := C.CString(spec)
defer C.free(unsafe.Pointer(cSpec))
tm := C.struct_tm{
tm_year: C.int(now.Year() - 1900),
tm_mon: C.int(int(now.Month()) - 1),
tm_mday: C.int(now.Day()),
tm_hour: C.int(now.Hour()),
tm_min: C.int(now.Minute()),
tm_sec: C.int(now.Second()),
tm_wday: C.int(int(now.Weekday())),
tm_yday: C.int(now.YearDay() - 1),
tm_isdst: -1,
}
buffer := make([]C.char, 512)
length := C.strftime(&buffer[0], C.size_t(len(buffer)), cSpec, &tm)
return C.GoStringN(&buffer[0], C.int(length))
}