Skip to content

c: support Windows MSVC interop - #26

Draft
cpunion wants to merge 26 commits into
goplus:mainfrom
cpunion:codex/windows-msvc-c-interop-20260822
Draft

c: support Windows MSVC interop#26
cpunion wants to merge 26 commits into
goplus:mainfrom
cpunion:codex/windows-msvc-c-interop-20260822

Conversation

@cpunion

@cpunion cpunion commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Add the Windows/MSVC host bindings needed by LLGo while preserving the existing POSIX C ABI on non-Windows hosts.

  • add UCRT/MSVC implementations for standard streams, file/environment access, clocks, random, and setjmp
  • add Win32 thread, FLS, synchronization, semaphore, and Winsock bindings
  • select the Windows C++ runtime and cover the relevant LLVM 19 layouts
  • reuse LLGo's native Windows synchronization backend instead of carrying a second lock implementation

The pthread_once boundary remains a direct C mapping:

int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));

Accordingly, Once.Do accepts a C-ABI OnceFunc func() on every host. Capturing Go closures use the separate Once.DoFunc adapter: Go retains the closure object, while the native layer sees only a fixed callback and an opaque context pointer. The C layer never depends on LLGo's {function, environment} closure representation. The adapter covers concurrent callers and nested calls without changing the raw pthread API.

Validation

  • go test ./... on macOS ARM64
  • committed llgo test -v ./c/pthread/sync coverage for:
    • a raw non-capturing once callback
    • a capturing closure
    • concurrent callers with distinct closure contexts
    • nested DoFunc calls
  • the LLGo tests pass through actual execution on macOS ARM64 and Windows 11 ARM64
  • CI builds released LLGo v1.0.0 with LLVM 19 and runs the same tests on Linux and macOS
  • Windows-target compile checks pass for the changed pthread/synchronization packages

The latest merged LLGo Windows foundation (R5) builds on Windows but cannot yet run llgo test: compiling the standard-library internal/fuzz package fails LLVM IR verification. Windows CI therefore waits for the remaining llgo test support to merge; the same tests already pass locally with the staged R8 integration.

The corresponding LLGo integration remains staged in xgo-dev/llgo#2425. This work is part of the Windows support proposal.

@cpunion

cpunion commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Validation update:

  • Added LLGo-native unit tests for the raw Once.Do callback, a captured DoFunc closure, concurrent callers with distinct contexts, and nested DoFunc calls.
  • llgo test -v ./c/pthread/sync passes locally on macOS ARM64 and Windows 11 ARM64.
  • The new Linux LLGo CI job passed all four tests using released LLGo v1.0.0 and LLVM 19: https://github.com/goplus/lib/actions/runs/33037946987/job/98404795022
  • The ordinary Go build job remains green.

@cpunion

cpunion commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

LLGo execution coverage is now automated on both host platforms:

Both jobs build LLGo v1.0.0 with LLVM 19 and run all four c/pthread/sync tests.

Windows 11 ARM64 has also passed the same tests locally with the staged R8 integration. I additionally built and tested the latest merged LLGo Windows commit (71754b459, R5): LLGo itself builds, but llgo test still fails while compiling standard-library internal/fuzz due invalid LLVM IR. Windows CI should therefore be added after the remaining R6 testing support is merged, rather than pinning this upstream PR to an unmerged fork commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant