From ad544a55283a17d748ed6d2d19074c0cb6e6b6cc Mon Sep 17 00:00:00 2001 From: Charles KWON OhJun Date: Sun, 12 Apr 2026 12:23:10 +0900 Subject: [PATCH] fix: Windows cross-compilation support (GOOS=windows) - debugcli.go/debugtui.go: add //go:build !windows tag - debugcli_windows.go/debugtui_windows.go: no-op stubs - cdx/cdx.go: extract mmap to platform-specific files - cdx/mmap_posix.go: syscall.Mmap/Munmap - cdx/mmap_windows.go: no-op (falls back to read) - ntx/ntx.go, ntx/build.go: same mmap extraction - ntx/mmap_posix.go, ntx/mmap_windows.go: platform split Builds verified: linux/amd64, windows/amd64, darwin/arm64, darwin/amd64 Co-Authored-By: Claude Opus 4.6 (1M context) --- hbrdd/cdx/cdx.go | 8 +++----- hbrdd/cdx/mmap_posix.go | 16 ++++++++++++++++ hbrdd/cdx/mmap_windows.go | 17 +++++++++++++++++ hbrdd/ntx/build.go | 3 +-- hbrdd/ntx/mmap_posix.go | 16 ++++++++++++++++ hbrdd/ntx/mmap_windows.go | 16 ++++++++++++++++ hbrdd/ntx/ntx.go | 8 +++----- hbrt/debugcli.go | 2 ++ hbrt/debugcli_windows.go | 13 +++++++++++++ hbrt/debugtui.go | 2 ++ hbrt/debugtui_windows.go | 13 +++++++++++++ 11 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 hbrdd/cdx/mmap_posix.go create mode 100644 hbrdd/cdx/mmap_windows.go create mode 100644 hbrdd/ntx/mmap_posix.go create mode 100644 hbrdd/ntx/mmap_windows.go create mode 100644 hbrt/debugcli_windows.go create mode 100644 hbrt/debugtui_windows.go diff --git a/hbrdd/cdx/cdx.go b/hbrdd/cdx/cdx.go index 39cdfc1..ea9dcbc 100644 --- a/hbrdd/cdx/cdx.go +++ b/hbrdd/cdx/cdx.go @@ -24,7 +24,6 @@ import ( "os" "sort" "strings" - "syscall" ) // CDX constants — matching Harbour. @@ -357,10 +356,9 @@ func OpenIndex(path string) (*Index, error) { idx := &Index{file: f} - // mmap for zero-copy reads + // mmap for zero-copy reads (platform-specific, no-op on Windows) if fi, err2 := f.Stat(); err2 == nil && fi.Size() > 0 { - if data, err2 := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()), - syscall.PROT_READ, syscall.MAP_SHARED); err2 == nil { + if data, err2 := mmapFile(f, int(fi.Size())); err2 == nil { idx.mmapData = data } } @@ -420,7 +418,7 @@ func OpenIndex(path string) (*Index, error) { // Close closes the CDX file. func (idx *Index) Close() error { if idx.mmapData != nil { - syscall.Munmap(idx.mmapData) + munmapFile(idx.mmapData) idx.mmapData = nil } return idx.file.Close() diff --git a/hbrdd/cdx/mmap_posix.go b/hbrdd/cdx/mmap_posix.go new file mode 100644 index 0000000..875d66e --- /dev/null +++ b/hbrdd/cdx/mmap_posix.go @@ -0,0 +1,16 @@ +//go:build !windows + +package cdx + +import ( + "os" + "syscall" +) + +func mmapFile(f *os.File, size int) ([]byte, error) { + return syscall.Mmap(int(f.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED) +} + +func munmapFile(data []byte) error { + return syscall.Munmap(data) +} diff --git a/hbrdd/cdx/mmap_windows.go b/hbrdd/cdx/mmap_windows.go new file mode 100644 index 0000000..902f9f1 --- /dev/null +++ b/hbrdd/cdx/mmap_windows.go @@ -0,0 +1,17 @@ +//go:build windows + +package cdx + +import ( + "errors" + "os" +) + +// Windows: mmap not implemented — fallback to read() path. +func mmapFile(f *os.File, size int) ([]byte, error) { + return nil, errors.New("mmap not supported on Windows") +} + +func munmapFile(data []byte) error { + return nil +} diff --git a/hbrdd/ntx/build.go b/hbrdd/ntx/build.go index c4e74c2..f3c9844 100644 --- a/hbrdd/ntx/build.go +++ b/hbrdd/ntx/build.go @@ -9,7 +9,6 @@ import ( "fmt" "os" "sort" - "syscall" ) // KeyRecord pairs a key value with its record number for sorting. @@ -487,7 +486,7 @@ func encodeInternalPage(children []*buildPage, keyLen, itemSize, maxItem int, of func (idx *Index) insertKeyBTree(key []byte, recNo uint32) error { // Disable mmap during insertion (file grows, mmap stale) if idx.mmapData != nil { - syscall.Munmap(idx.mmapData) + munmapFile(idx.mmapData) idx.mmapData = nil } // Search for insertion position diff --git a/hbrdd/ntx/mmap_posix.go b/hbrdd/ntx/mmap_posix.go new file mode 100644 index 0000000..32d1b81 --- /dev/null +++ b/hbrdd/ntx/mmap_posix.go @@ -0,0 +1,16 @@ +//go:build !windows + +package ntx + +import ( + "os" + "syscall" +) + +func mmapFile(f *os.File, size int) ([]byte, error) { + return syscall.Mmap(int(f.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED) +} + +func munmapFile(data []byte) error { + return syscall.Munmap(data) +} diff --git a/hbrdd/ntx/mmap_windows.go b/hbrdd/ntx/mmap_windows.go new file mode 100644 index 0000000..3c665bf --- /dev/null +++ b/hbrdd/ntx/mmap_windows.go @@ -0,0 +1,16 @@ +//go:build windows + +package ntx + +import ( + "errors" + "os" +) + +func mmapFile(f *os.File, size int) ([]byte, error) { + return nil, errors.New("mmap not supported on Windows") +} + +func munmapFile(data []byte) error { + return nil +} diff --git a/hbrdd/ntx/ntx.go b/hbrdd/ntx/ntx.go index 740d75f..1b4412c 100644 --- a/hbrdd/ntx/ntx.go +++ b/hbrdd/ntx/ntx.go @@ -16,7 +16,6 @@ import ( "fmt" "os" "strings" - "syscall" ) // NTX constants — matching Harbour exactly. @@ -268,8 +267,7 @@ func (idx *Index) mmapFile() { if err != nil || fi.Size() < HeaderSize { return } - data, err := syscall.Mmap(int(idx.file.Fd()), 0, int(fi.Size()), - syscall.PROT_READ, syscall.MAP_SHARED) + data, err := mmapFile(idx.file, int(fi.Size())) if err != nil { return // fallback to file reads } @@ -280,7 +278,7 @@ func (idx *Index) mmapFile() { // Also invalidates page pool (data slices pointed into old mmap). func (idx *Index) remapFile() { if idx.mmapData != nil { - syscall.Munmap(idx.mmapData) + munmapFile(idx.mmapData) idx.mmapData = nil } // Invalidate page pool — data slices pointed into old mmap @@ -295,7 +293,7 @@ func (idx *Index) TestGetMmap() []byte { return idx.mmapData } func (idx *Index) Close() error { if idx.mmapData != nil { - syscall.Munmap(idx.mmapData) + munmapFile(idx.mmapData) idx.mmapData = nil } return idx.file.Close() diff --git a/hbrt/debugcli.go b/hbrt/debugcli.go index a02eed5..eb6e925 100644 --- a/hbrt/debugcli.go +++ b/hbrt/debugcli.go @@ -1,3 +1,5 @@ +//go:build !windows + // Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com) // All rights reserved. diff --git a/hbrt/debugcli_windows.go b/hbrt/debugcli_windows.go new file mode 100644 index 0000000..12481f5 --- /dev/null +++ b/hbrt/debugcli_windows.go @@ -0,0 +1,13 @@ +//go:build windows + +package hbrt + +import "fmt" + +// CLIDebugger returns a no-op debug callback on Windows. +func CLIDebugger() DebugCallback { + return func(event *DebugEvent) int { + fmt.Println("[debugger not available on Windows]") + return 0 // continue + } +} diff --git a/hbrt/debugtui.go b/hbrt/debugtui.go index 0b169e6..efd384d 100644 --- a/hbrt/debugtui.go +++ b/hbrt/debugtui.go @@ -1,3 +1,5 @@ +//go:build !windows + // Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com) // All rights reserved. diff --git a/hbrt/debugtui_windows.go b/hbrt/debugtui_windows.go new file mode 100644 index 0000000..07cadbf --- /dev/null +++ b/hbrt/debugtui_windows.go @@ -0,0 +1,13 @@ +//go:build windows + +package hbrt + +import "fmt" + +// TUIDebugger returns a no-op debug callback on Windows. +func TUIDebugger() DebugCallback { + return func(event *DebugEvent) int { + fmt.Println("[TUI debugger not available on Windows]") + return 0 // continue + } +}