From d52502794ef9ea66825a25f8c998714d041df6f7 Mon Sep 17 00:00:00 2001 From: John Hui Date: Fri, 3 Oct 2025 17:18:54 -0700 Subject: [PATCH] Add extern "C" to header process_shims.h Previous, we would encounter missing symbol errors like: "_subprocess_vm_size()", referenced from: closure #1 () -> Swift.Int in variable initialization expression of Subprocess.(_pageSize in _EDE99368FF43462E0C75AF3C9D4D8F2D) : Swift.Int in AsyncBufferSequence.swift.o NOTE: found '__subprocess_vm_size' in process_shims.c.o, declaration possibly missing 'extern "C"' We can reproduce this by running: xcrun swift build -Xswiftc -cxx-interoperability-mode=default --build-tests Adding `extern "C"` fixes these issues. rdar://161624906 --- .../_SubprocessCShims/include/process_shims.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sources/_SubprocessCShims/include/process_shims.h b/Sources/_SubprocessCShims/include/process_shims.h index 584d5418..cd4b3423 100644 --- a/Sources/_SubprocessCShims/include/process_shims.h +++ b/Sources/_SubprocessCShims/include/process_shims.h @@ -35,6 +35,10 @@ #include #endif // TARGET_OS_LINUX || TARGET_OS_FREEBSD +#ifdef __cplusplus +extern "C" { +#endif + #if __has_include() vm_size_t _subprocess_vm_size(void); #endif @@ -102,12 +106,20 @@ int _pidfd_open(pid_t pid); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif // !TARGET_OS_WINDOWS #if TARGET_OS_WINDOWS #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef _WINDEF_ typedef unsigned long DWORD; typedef int BOOL; @@ -122,6 +134,10 @@ unsigned int _subprocess_windows_get_errno(void); /// complex macro and cannot be imported directly into Swift. DWORD_PTR _subprocess_PROC_THREAD_ATTRIBUTE_HANDLE_LIST(void); +#ifdef __cplusplus +} // extern "C" +#endif + #endif #endif /* process_shims_h */