Skip to content

Commit

Permalink
Merge branch 'jh/simple-ipc-sans-pthread'
Browse files Browse the repository at this point in the history
The "simple-ipc" did not compile without pthreads support, but the
build procedure was not properly account for it.

* jh/simple-ipc-sans-pthread:
  simple-ipc: correct ifdefs when NO_PTHREADS is defined
  • Loading branch information
gitster committed May 22, 2021
2 parents 99fe1c6 + 6aac70a commit 6aae0e2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1687,13 +1687,31 @@ ifdef NO_UNIX_SOCKETS
else
LIB_OBJS += unix-socket.o
LIB_OBJS += unix-stream-server.o
LIB_OBJS += compat/simple-ipc/ipc-shared.o
LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
endif

# Simple IPC requires threads and platform-specific IPC support.
# Only platforms that have both should include these source files
# in the build.
#
# On Windows-based systems, Simple IPC requires threads and Windows
# Named Pipes. These are always available, so Simple IPC support
# is optional.
#
# On Unix-based systems, Simple IPC requires pthreads and Unix
# domain sockets. So support is only enabled when both are present.
#
ifdef USE_WIN32_IPC
BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
LIB_OBJS += compat/simple-ipc/ipc-shared.o
LIB_OBJS += compat/simple-ipc/ipc-win32.o
else
ifndef NO_PTHREADS
ifndef NO_UNIX_SOCKETS
BASIC_CFLAGS += -DSUPPORTS_SIMPLE_IPC
LIB_OBJS += compat/simple-ipc/ipc-shared.o
LIB_OBJS += compat/simple-ipc/ipc-unix-socket.o
endif
endif
endif

ifdef NO_ICONV
Expand Down
10 changes: 7 additions & 3 deletions compat/simple-ipc/ipc-shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
#include "pkt-line.h"
#include "thread-utils.h"

#ifdef SUPPORTS_SIMPLE_IPC
#ifndef SUPPORTS_SIMPLE_IPC
/*
* This source file should only be compiled when Simple IPC is supported.
* See the top-level Makefile.
*/
#error SUPPORTS_SIMPLE_IPC not defined
#endif

int ipc_server_run(const char *path, const struct ipc_server_opts *opts,
ipc_server_application_cb *application_cb,
Expand All @@ -24,5 +30,3 @@ int ipc_server_run(const char *path, const struct ipc_server_opts *opts,

return ret;
}

#endif /* SUPPORTS_SIMPLE_IPC */
8 changes: 6 additions & 2 deletions compat/simple-ipc/ipc-unix-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
#include "unix-socket.h"
#include "unix-stream-server.h"

#ifdef NO_UNIX_SOCKETS
#error compat/simple-ipc/ipc-unix-socket.c requires Unix sockets
#ifndef SUPPORTS_SIMPLE_IPC
/*
* This source file should only be compiled when Simple IPC is supported.
* See the top-level Makefile.
*/
#error SUPPORTS_SIMPLE_IPC not defined
#endif

enum ipc_active_state ipc_get_active_state(const char *path)
Expand Down
8 changes: 6 additions & 2 deletions compat/simple-ipc/ipc-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#include "pkt-line.h"
#include "thread-utils.h"

#ifndef GIT_WINDOWS_NATIVE
#error This file can only be compiled on Windows
#ifndef SUPPORTS_SIMPLE_IPC
/*
* This source file should only be compiled when Simple IPC is supported.
* See the top-level Makefile.
*/
#error SUPPORTS_SIMPLE_IPC not defined
#endif

static int initialize_pipe_name(const char *path, wchar_t *wpath, size_t alloc)
Expand Down
10 changes: 9 additions & 1 deletion contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,15 @@ endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-win32.c)
add_compile_definitions(SUPPORTS_SIMPLE_IPC)
set(SUPPORTS_SIMPLE_IPC 1)
else()
list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
# Simple IPC requires both Unix sockets and pthreads on Unix-based systems.
if(NOT NO_UNIX_SOCKETS AND NOT NO_PTHREADS)
list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
add_compile_definitions(SUPPORTS_SIMPLE_IPC)
set(SUPPORTS_SIMPLE_IPC 1)
endif()
endif()

set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
Expand Down Expand Up @@ -974,6 +981,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
if(WIN32)
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
endif()
Expand Down
4 changes: 0 additions & 4 deletions simple-ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* See Documentation/technical/api-simple-ipc.txt
*/

#if defined(GIT_WINDOWS_NATIVE) || !defined(NO_UNIX_SOCKETS)
#define SUPPORTS_SIMPLE_IPC
#endif

#ifdef SUPPORTS_SIMPLE_IPC
#include "pkt-line.h"

Expand Down

0 comments on commit 6aae0e2

Please sign in to comment.