Skip to content

Commit 21d09c4

Browse files
committed
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.
1 parent dc3bbd2 commit 21d09c4

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

Sources/_SubprocessCShims/include/process_shims.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@
3535
#include <sys/wait.h>
3636
#endif // TARGET_OS_LINUX || TARGET_OS_FREEBSD
3737

38+
#ifdef __cplusplus
39+
#define SWIFTSUBPROCESS_EXPORT extern "C"
40+
#else
41+
#define SWIFTSUBPROCESS_EXPORT extern
42+
#endif
43+
3844
#if __has_include(<mach/vm_page_size.h>)
39-
vm_size_t _subprocess_vm_size(void);
45+
SWIFTSUBPROCESS_EXPORT vm_size_t _subprocess_vm_size(void);
4046
#endif
4147

4248
#if TARGET_OS_MAC
49+
SWIFTSUBPROCESS_EXPORT
4350
int _subprocess_spawn(
4451
pid_t * _Nonnull pid,
4552
const char * _Nonnull exec_path,
@@ -54,6 +61,7 @@ int _subprocess_spawn(
5461
);
5562
#endif // TARGET_OS_MAC
5663

64+
SWIFTSUBPROCESS_EXPORT
5765
int _subprocess_fork_exec(
5866
pid_t * _Nonnull pid,
5967
int * _Nonnull pidfd,
@@ -69,19 +77,20 @@ int _subprocess_fork_exec(
6977
int create_session
7078
);
7179

72-
int _was_process_exited(int status);
73-
int _get_exit_code(int status);
74-
int _was_process_signaled(int status);
75-
int _get_signal_code(int status);
76-
int _was_process_suspended(int status);
80+
SWIFTSUBPROCESS_EXPORT int _was_process_exited(int status);
81+
SWIFTSUBPROCESS_EXPORT int _get_exit_code(int status);
82+
SWIFTSUBPROCESS_EXPORT int _was_process_signaled(int status);
83+
SWIFTSUBPROCESS_EXPORT int _get_signal_code(int status);
84+
SWIFTSUBPROCESS_EXPORT int _was_process_suspended(int status);
7785

78-
void _subprocess_lock_environ(void);
79-
void _subprocess_unlock_environ(void);
80-
char * _Nullable * _Nullable _subprocess_get_environ(void);
86+
SWIFTSUBPROCESS_EXPORT void _subprocess_lock_environ(void);
87+
SWIFTSUBPROCESS_EXPORT void _subprocess_unlock_environ(void);
88+
SWIFTSUBPROCESS_EXPORT char * _Nullable * _Nullable _subprocess_get_environ(void);
8189

82-
int _subprocess_pdkill(int pidfd, int signal);
90+
SWIFTSUBPROCESS_EXPORT int _subprocess_pdkill(int pidfd, int signal);
8391

8492
#if TARGET_OS_UNIX && !TARGET_OS_FREEBSD
93+
SWIFTSUBPROCESS_EXPORT
8594
int _shims_snprintf(
8695
char * _Nonnull str,
8796
int len,
@@ -92,7 +101,7 @@ int _shims_snprintf(
92101
#endif
93102

94103
#if TARGET_OS_LINUX
95-
int _pidfd_open(pid_t pid);
104+
SWIFTSUBPROCESS_EXPORT int _pidfd_open(pid_t pid);
96105

97106
// P_PIDFD is only defined on Linux Kernel 5.4 and above
98107
// Define our value if it's not available
@@ -113,14 +122,14 @@ typedef unsigned long DWORD;
113122
typedef int BOOL;
114123
#endif
115124

116-
BOOL _subprocess_windows_send_vm_close(DWORD pid);
117-
unsigned int _subprocess_windows_get_errno(void);
125+
SWIFTSUBPROCESS_EXPORT BOOL _subprocess_windows_send_vm_close(DWORD pid);
126+
SWIFTSUBPROCESS_EXPORT unsigned int _subprocess_windows_get_errno(void);
118127

119128
/// Get the value of `PROC_THREAD_ATTRIBUTE_HANDLE_LIST`.
120129
///
121130
/// This function is provided because `PROC_THREAD_ATTRIBUTE_HANDLE_LIST` is a
122131
/// complex macro and cannot be imported directly into Swift.
123-
DWORD_PTR _subprocess_PROC_THREAD_ATTRIBUTE_HANDLE_LIST(void);
132+
SWIFTSUBPROCESS_EXPORT DWORD_PTR _subprocess_PROC_THREAD_ATTRIBUTE_HANDLE_LIST(void);
124133

125134
#endif
126135

0 commit comments

Comments
 (0)