Merge pull request #50 from NeroBurner/actions-mingw-w64
Add github action to compile with mingw-w64 on windows
This commit is contained in:
commit
a9adaf09fd
|
@ -1,15 +1,30 @@
|
|||
name: CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
job:
|
||||
name: ${{ matrix.os }}-cmake-build
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
include:
|
||||
- os: windows-latest
|
||||
CC: gcc
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install alsa pulse and jack
|
||||
run: sudo apt-get -y install libasound2-dev libpulse-dev libjack-dev
|
||||
- name: run-cmake
|
||||
uses: lukka/run-cmake@v0.10
|
||||
- uses: actions/checkout@v2
|
||||
- name: install alsa pulse and jack
|
||||
run: sudo apt-get -y install libasound2-dev libpulse-dev libjack-dev
|
||||
if: "contains( matrix.os, 'ubuntu')"
|
||||
- name: run-cmake
|
||||
uses: lukka/run-cmake@v0.10
|
||||
if: "!contains( matrix.os, 'windows')"
|
||||
- name: Run CMake+MinGW-w64
|
||||
uses: lukka/run-cmake@v0.10
|
||||
if: "contains( matrix.os, 'windows')"
|
||||
with:
|
||||
buildDirectory: '${{ runner.workspace }}/b/mingw-w64'
|
||||
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
|
||||
cmakeAppendedArgs: '-G "Ninja" -DWITH_ALSA=No -DWITH_PULSEAUDIO=No -DWITH_JACK=No'
|
||||
|
|
|
@ -71,6 +71,11 @@ foreach(exe vban_receptor vban_emitter vban_sendtext)
|
|||
target_link_libraries( ${exe} PRIVATE ${JACK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# Windows has no sys/socket.h, need to use Winsock2.h and link to lib
|
||||
target_link_libraries( ${exe} PRIVATE ws2_32)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${exe} DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
endforeach()
|
||||
|
||||
|
|
|
@ -8,7 +8,14 @@
|
|||
#include <unistd.h>
|
||||
#include "common/logger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#define FIFO_FILENAME "/tmp/vban_0"
|
||||
#else
|
||||
// name of named pipe is \\.\pipe\vban_0
|
||||
#include <windef.h> // for DWORD and others
|
||||
#include <winbase.h>
|
||||
#define FIFO_FILENAME "\\\\.\\pipe\\vban_0"
|
||||
#endif
|
||||
|
||||
struct pipe_backend_t
|
||||
{
|
||||
|
@ -60,6 +67,7 @@ int pipe_open(audio_backend_handle_t handle, char const* output_name, enum audio
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
ret = mkfifo(FIFO_FILENAME, 0666);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -69,6 +77,27 @@ int pipe_open(audio_backend_handle_t handle, char const* output_name, enum audio
|
|||
pipe_backend->fd = 0;
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
// Windows has no mkfifo function. Use named pipes instead
|
||||
HANDLE named_pipe = CreateNamedPipeA(
|
||||
/* lpName */ FIFO_FILENAME,
|
||||
/* dwOpenMode */ PIPE_ACCESS_DUPLEX,
|
||||
/* dwPipeMode */ PIPE_TYPE_MESSAGE, // or maybe PIPE_TYPE_BYTE, let's see
|
||||
/* nMaxInstances */ 1,
|
||||
/* nOutBufferSize */ 0,
|
||||
/* nInBufferSize */ 0,
|
||||
/* nDefaultTimeOut */ 0,
|
||||
/* lpSecurityAttributes */ 0);
|
||||
if (named_pipe == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
logger_log(LOG_FATAL, "%s: ???", __func__);
|
||||
//todo:strerror
|
||||
perror("mknod");
|
||||
pipe_backend->fd = 0;
|
||||
ret = GetLastError();
|
||||
return ret;
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
pipe_backend->fd = open((output_name[0] == 0) ? FIFO_FILENAME : output_name, (direction == AUDIO_OUT) ? O_WRONLY : O_RDONLY);
|
||||
if (pipe_backend->fd == -1)
|
||||
|
|
|
@ -21,17 +21,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/poll.h>
|
||||
#else // _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include "common/logger.h"
|
||||
|
||||
struct socket_t
|
||||
{
|
||||
struct socket_config_t config;
|
||||
#ifndef _WIN32
|
||||
int fd;
|
||||
#else // _WIN32
|
||||
SOCKET fd;
|
||||
#endif
|
||||
};
|
||||
|
||||
static int socket_open(socket_handle_t handle);
|
||||
|
@ -54,6 +62,16 @@ int socket_init(socket_handle_t* handle, struct socket_config_t const* config)
|
|||
logger_log(LOG_FATAL, "%s: could not allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
WSADATA wsadata;
|
||||
ret = WSAStartup(MAKEWORD(2,2), &wsadata);
|
||||
if (ret != 0)
|
||||
{
|
||||
logger_log(LOG_FATAL, "%s: WSAStartup failed: %d", __func__, ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
(*handle)->fd = INVALID_SOCKET;
|
||||
#endif
|
||||
|
||||
(*handle)->config = *config;
|
||||
|
||||
|
@ -82,6 +100,9 @@ int socket_release(socket_handle_t* handle)
|
|||
free(*handle);
|
||||
*handle = 0;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -94,7 +115,21 @@ int socket_is_broadcast_address(char const* ip)
|
|||
int socket_open(socket_handle_t handle)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifndef _WIN32
|
||||
int optflag = 0;
|
||||
#else // _WIN32
|
||||
// optflag is used as optval for setsockopt(), windows expects it to be a char
|
||||
// posix expects a void *
|
||||
// from https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
|
||||
// int setsockopt(
|
||||
// SOCKET s,
|
||||
// int level,
|
||||
// int optname,
|
||||
// const char *optval,
|
||||
// int optlen
|
||||
// );
|
||||
char optflag = 0;
|
||||
#endif
|
||||
struct sockaddr_in si_me;
|
||||
|
||||
if (handle == 0)
|
||||
|
@ -105,7 +140,11 @@ int socket_open(socket_handle_t handle)
|
|||
|
||||
logger_log(LOG_INFO, "%s: opening socket with port %d", __func__, handle->config.port);
|
||||
|
||||
#ifndef _WIN32
|
||||
if (handle->fd != 0)
|
||||
#else // _WIN32
|
||||
if (handle->fd != INVALID_SOCKET)
|
||||
#endif
|
||||
{
|
||||
ret = socket_close(handle);
|
||||
if (ret != 0)
|
||||
|
@ -116,6 +155,7 @@ int socket_open(socket_handle_t handle)
|
|||
}
|
||||
|
||||
handle->fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
#ifndef _WIN32
|
||||
if (handle->fd < 0)
|
||||
{
|
||||
logger_log(LOG_ERROR, "%s: unable to create socket", __func__);
|
||||
|
@ -123,6 +163,15 @@ int socket_open(socket_handle_t handle)
|
|||
handle->fd = 0;
|
||||
return ret;
|
||||
}
|
||||
#else // _WIN32
|
||||
if (handle->fd == INVALID_SOCKET)
|
||||
{
|
||||
logger_log(LOG_ERROR, "%s: unable to create socket", __func__);
|
||||
ret = -1;
|
||||
handle->fd = INVALID_SOCKET;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (handle->config.direction == SOCKET_IN)
|
||||
{
|
||||
|
@ -132,11 +181,19 @@ int socket_open(socket_handle_t handle)
|
|||
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
ret = bind(handle->fd, (struct sockaddr const*)&si_me, sizeof(si_me));
|
||||
|
||||
#ifndef _WIN32
|
||||
if (ret < 0)
|
||||
#else // _WIN32
|
||||
if (ret == SOCKET_ERROR)
|
||||
#endif
|
||||
{
|
||||
logger_log(LOG_ERROR, "%s: unable to bind socket", __func__);
|
||||
socket_close(handle);
|
||||
#ifndef _WIN32
|
||||
return errno;
|
||||
#else // _WIN32
|
||||
return WSAGetLastError();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -172,11 +229,19 @@ int socket_close(socket_handle_t handle)
|
|||
|
||||
logger_log(LOG_INFO, "%s: closing socket with port %d", __func__, handle->config.port);
|
||||
|
||||
#ifndef _WIN32
|
||||
if (handle->fd != 0)
|
||||
#else // _WIN32
|
||||
if (handle->fd == INVALID_SOCKET)
|
||||
#endif
|
||||
{
|
||||
ret = close(handle->fd);
|
||||
handle->fd = 0;
|
||||
#ifndef _WIN32
|
||||
if (ret != 0)
|
||||
#else // _WIN32
|
||||
if (ret == SOCKET_ERROR)
|
||||
#endif
|
||||
{
|
||||
logger_log(LOG_ERROR, "%s: unable to close socket", __func__);
|
||||
return ret;
|
||||
|
@ -190,7 +255,11 @@ int socket_read(socket_handle_t handle, char* buffer, size_t size)
|
|||
{
|
||||
int ret = 0;
|
||||
struct sockaddr_in si_other;
|
||||
#ifndef _WIN32
|
||||
socklen_t slen = sizeof(si_other);
|
||||
#else // _WIN32
|
||||
int slen = sizeof(si_other);
|
||||
#endif
|
||||
|
||||
logger_log(LOG_DEBUG, "%s invoked", __func__);
|
||||
|
||||
|
@ -202,7 +271,11 @@ int socket_read(socket_handle_t handle, char* buffer, size_t size)
|
|||
|
||||
logger_log(LOG_DEBUG, "%s ip %s", __func__, handle->config.ip_address);
|
||||
|
||||
#ifndef _WIN32
|
||||
if (handle->fd == 0)
|
||||
#else // _WIN32
|
||||
if (handle->fd == INVALID_SOCKET)
|
||||
#endif
|
||||
{
|
||||
logger_log(LOG_ERROR, "%s: socket is not open", __func__);
|
||||
return -ENODEV;
|
||||
|
@ -232,7 +305,11 @@ int socket_write(socket_handle_t handle, char const* buffer, size_t size)
|
|||
{
|
||||
int ret = 0;
|
||||
struct sockaddr_in si_other;
|
||||
#ifndef _WIN32
|
||||
socklen_t slen = sizeof(si_other);
|
||||
#else // _WIN32
|
||||
int slen = sizeof(si_other);
|
||||
#endif
|
||||
|
||||
logger_log(LOG_DEBUG, "%s invoked", __func__);
|
||||
|
||||
|
|
Loading…
Reference in New Issue