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) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 12:23:10 +09:00
parent 3ed246c47e
commit ad544a5528
11 changed files with 102 additions and 12 deletions

View File

@@ -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()

16
hbrdd/cdx/mmap_posix.go Normal file
View File

@@ -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)
}

17
hbrdd/cdx/mmap_windows.go Normal file
View File

@@ -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
}

View File

@@ -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

16
hbrdd/ntx/mmap_posix.go Normal file
View File

@@ -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)
}

16
hbrdd/ntx/mmap_windows.go Normal file
View File

@@ -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
}

View File

@@ -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()

View File

@@ -1,3 +1,5 @@
//go:build !windows
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.

13
hbrt/debugcli_windows.go Normal file
View File

@@ -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
}
}

View File

@@ -1,3 +1,5 @@
//go:build !windows
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
// All rights reserved.

13
hbrt/debugtui_windows.go Normal file
View File

@@ -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
}
}