Zig CC cross-compilation support for Windows on Linux host. (#128)

Zig CC cross-compilation support for Windows on Linux host
This commit is contained in:
Sergi Vladykin 2023-12-20 23:50:39 -08:00 committed by GitHub
parent c729344792
commit 2fa40dd436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 67 additions and 18 deletions

View File

@ -129,4 +129,25 @@ jobs:
mkdir build-debug && cd build-debug
cmake .. -DCMAKE_C_FLAGS=-m32 -DSANITIZER=undefined
make -j
make check
make check
ubuntu-zig-windows:
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request') ||
(github.event_name == 'push') ||
(github.event_name == 'workflow_dispatch' ||
(github.event_name == 'schedule' && github.repository == 'tezc/sc')) && !contains(github.event.inputs.skip, 'zig-windows')
name: Zig Windows
steps:
- uses: actions/checkout@v2.1.0
- name: build
run: |
sudo apt update
sudo apt-get install cmake curl tar
mkdir build-debug && cd build-debug
export ZIG=zig-linux-x86_64-0.12.0-dev.1834+f36ac227b
curl -o zig.tar.xz "https://ziglang.org/builds/$ZIG.tar.xz"
tar -xf zig.tar.xz
export CC="$(pwd)/$ZIG/zig cc -target x86_64-windows"
cmake .. -DCMAKE_SYSTEM_NAME=Windows
make -j

View File

@ -617,7 +617,7 @@ void fail_test(void)
sc_buf_term(&buf);
}
#else
void fail_test()
void fail_test(void)
{
}
#endif

View File

@ -280,7 +280,7 @@ void fail_test(void)
}
#else
void fail_test()
void fail_test(void)
{
}
#endif

View File

@ -40,7 +40,10 @@
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
int sc_cond_init(struct sc_cond *c)
{

View File

@ -239,7 +239,7 @@ void fail_test(void)
sc_heap_term(&heap);
}
#else
void fail_test()
void fail_test(void)
{
}
#endif

View File

@ -6,7 +6,7 @@
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif

View File

@ -37,7 +37,7 @@
#include <ctype.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif

View File

@ -5,7 +5,7 @@
#include <stdarg.h>
#include <time.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif

View File

@ -73,7 +73,10 @@ thread_local char sc_name[32] = "Thread";
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
#define strcasecmp _stricmp
#define localtime_r(a, b) (localtime_s(b, a) == 0 ? b : NULL)
#include <windows.h>

View File

@ -297,7 +297,7 @@ void fail_test(void)
fail_posix_fallocate = UINT32_MAX;
}
#else
void fail_test()
void fail_test(void)
{
}
#endif

View File

@ -43,7 +43,9 @@
#include <io.h>
#include <stdint.h>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
static void sc_mmap_errstr(struct sc_mmap *m)
{

View File

@ -12,6 +12,10 @@ add_library(
target_include_directories(sc_signal PUBLIC ${CMAKE_CURRENT_LIST_DIR})
if (CMAKE_SYSTEM_NAME MATCHES Windows)
target_link_libraries(sc_signal -lws2_32)
endif()
if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -Werror")
endif ()
@ -41,6 +45,10 @@ if (SC_BUILD_TEST)
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_SIZE_MAX=1400000ul)
if (CMAKE_SYSTEM_NAME MATCHES Windows)
target_link_libraries(${PROJECT_NAME}_test -lws2_32)
endif()
check_c_source_compiles("
#include <execinfo.h>
#include <unistd.h>

View File

@ -52,7 +52,7 @@
#endif
#if defined(_WIN32)
#include <WinSock2.h>
#include <winsock2.h>
volatile SOCKET sc_signal_shutdown_fd;
#else
volatile sig_atomic_t sc_signal_shutdown_fd;
@ -202,13 +202,15 @@ int sc_signal_snprintf(char *buf, size_t sz, const char *fmt, ...)
#define WIN32_LEAN_AND_MEAN
#include <Ws2tcpip.h>
#include <ws2tcpip.h>
#include <io.h>
#include <signal.h>
#include <windows.h>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#pragma comment(lib, "Ws2_32.lib")
#endif
BOOL WINAPI sc_console_handler(DWORD type)
{
@ -297,9 +299,10 @@ void sc_signal_std_on_fatal(int sig)
void sc_signal_std_on_shutdown(int type)
{
(void)type;
sc_console_handler(CTRL_C_EVENT);
}
int sc_signal_init()
int sc_signal_init(void)
{
BOOL b;
sc_signal_log_fd = -1;

View File

@ -47,7 +47,7 @@
* e.g., CTRL+C to shutdown, twice CTRL+C means 'I don't want to wait anything'.
*/
#if defined(_WIN32)
#include <WinSock2.h>
#include <winsock2.h>
extern volatile SOCKET sc_signal_shutdown_fd;
#else
extern volatile sig_atomic_t sc_signal_shutdown_fd;

View File

@ -12,6 +12,10 @@ add_library(
target_include_directories(sc_socket PUBLIC ${CMAKE_CURRENT_LIST_DIR})
if (CMAKE_SYSTEM_NAME MATCHES Windows)
target_link_libraries(sc_socket -lws2_32)
endif()
if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -pthread -Werror")
endif ()
@ -41,6 +45,10 @@ if (SC_BUILD_TEST)
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_SIZE_MAX=300 -Dsc_fcntl=test_fcntl)
if (CMAKE_SYSTEM_NAME MATCHES Windows)
target_link_libraries(${PROJECT_NAME}_test -lws2_32)
endif()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND SC_USE_WRAP)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")

View File

@ -6,6 +6,7 @@
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#if defined(_WIN32) || defined(_WIN64)
#include <synchapi.h>
@ -25,7 +26,6 @@ struct sc_thread {
#else
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdarg.h>

View File

@ -5,7 +5,7 @@
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif

View File

@ -39,7 +39,10 @@ void sc_thread_init(struct sc_thread *t)
}
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
#include <process.h>
@ -85,7 +88,6 @@ int sc_thread_start(struct sc_thread *t, void *(*fn)(void *), void *arg)
int sc_thread_join(struct sc_thread *t, void **ret)
{
int rc = 0;
void *val = NULL;
DWORD rv;
BOOL brc;
@ -105,7 +107,6 @@ int sc_thread_join(struct sc_thread *t, void **ret)
rc = -1;
}
val = t->ret;
t->id = 0;
out:

View File

@ -35,7 +35,7 @@
#include <stdio.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif

View File

@ -355,7 +355,7 @@ void fail_test(void)
fail_second_call = 0;
}
#else
void fail_test()
void fail_test(void)
{
}
#endif