Skip to content

Build with SwiftPM on Windows - #36

Open
mortenbekditlevsen wants to merge 1 commit into
firebase:mainfrom
mortenbekditlevsen:windows-swiftpm
Open

mortenbekditlevsen wants to merge 1 commit into
firebase:mainfrom
mortenbekditlevsen:windows-swiftpm

Conversation

@mortenbekditlevsen

Copy link
Copy Markdown

This builds gRPC's BoringSSL with SwiftPM on Windows. Only Package.swift changes, so the changes survive scripts/sync-upstream.sh.

  • _WINSOCKAPI_, NOMINMAX and NOCRYPT on Windows, as swift-nio-ssl's copy of BoringSSL defines them. Otherwise windows.h's winsock.h clashes with winsock2.h.
  • The thread-exit callback is renamed on Windows with a define: p_thread_callback_boringssl becomes p_thread_callback_boringssl_grpc. It isn't prefixed like the other symbols, so it clashes with the one in swift-crypto's or swift-nio-ssl's BoringSSL when both end up in one binary. crypto/thread_win.cc already allows the name to be a macro (it stringifies it through EXPAND_AND_STRINGIFY).
  • The error tables come from gen/crypto/err_data.cc instead of the generated err_data.c. crypto/err/err.cc is C++ and declares the tables without extern "C". Elsewhere a global variable's C++ name is the same as its C name, but on Windows it isn't, so the C definitions didn't link. gen/crypto/err_data.cc is BoringSSL's own C++ version of the same tables, and it comes with each sync. If you agree, scripts/generate-err-data.sh may no longer be needed. I've left it in.

We build gRPC this way for Windows in firebase-swift, a Swift port of the Firebase SDK that also runs on Linux, Android and Windows. Its Windows CI builds Firestore and runs its integration tests with these changes, on top of 0.41.0. I also built this branch on macOS.

🤖 Generated with Claude Code

- Defines _WINSOCKAPI_, NOMINMAX and NOCRYPT on Windows, as swift-nio-ssl's
  copy of BoringSSL does (2.37.3): otherwise windows.h's winsock.h clashes
  with winsock2.h.
- Renames the thread-exit callback on Windows with a define (thread_win.cc
  allows it to be a macro). Unprefixed, it clashes with the one in
  swift-crypto's BoringSSL when both are linked into one binary.
- Compiles the error tables from gen/crypto/err_data.cc instead of
  err_data.c. crypto/err/err.cc (C++) declares them without extern "C";
  elsewhere a global variable's C++ name is its C name, but on Windows it
  isn't, so the C definitions didn't link.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates Package.swift to resolve Windows-specific compilation and linking issues. Specifically, it replaces err_data.c with gen/crypto/err_data.cc to avoid C++ name mangling issues on Windows, and adds several Windows-specific preprocessor definitions (_WINSOCKAPI_, NOMINMAX, NOCRYPT, and a custom p_thread_callback_boringssl macro) to prevent header clashes and symbol collisions. There are no review comments, so I have no feedback to provide.

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