From 7e3fc1db038c1707e00fc130dc1e4a0bfd2e7ff0 Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 1 Jan 2021 21:22:17 -0500 Subject: [PATCH] Fix Actions CI for MSVC Fixes #616 --- CMakeLists.txt | 4 +++- include/asm/symbol.h | 3 ++- include/platform.h | 7 +++++++ src/CMakeLists.txt | 2 +- src/asm/lexer.c | 9 ++++++--- src/asm/symbol.c | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2089c590..4842361a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,9 @@ option(TRACE_PARSER "Trace parser execution" OFF) option(TRACE_LEXER "Trace lexer execution" OFF) if(MSVC) - add_compile_options(/W1 /MP) + # MSVC's standard library triggers warning C5105, + # "macro expansion producing 'defined' has undefined behavior" + add_compile_options(/std:c11 /W1 /MP /wd5105) add_definitions(/D_CRT_SECURE_NO_WARNINGS) else() add_compile_options(-Wall -pedantic) diff --git a/include/asm/symbol.h b/include/asm/symbol.h index 60248284..edef3238 100644 --- a/include/asm/symbol.h +++ b/include/asm/symbol.h @@ -16,6 +16,7 @@ #include "asm/section.h" +#include "platform.h" // MIN_NB_ELMS #include "types.h" #define HASHSIZE (1 << 16) @@ -117,7 +118,7 @@ void sym_SetExportAll(bool set); struct Symbol *sym_AddLocalLabel(char const *symName); struct Symbol *sym_AddLabel(char const *symName); struct Symbol *sym_AddAnonLabel(void); -void sym_WriteAnonLabelName(char name[static MAXSYMLEN + 1], uint32_t ofs, bool neg); +void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg); void sym_Export(char const *symName); struct Symbol *sym_AddEqu(char const *symName, int32_t value); struct Symbol *sym_AddSet(char const *symName, int32_t value); diff --git a/include/platform.h b/include/platform.h index 4c060e96..9fbd95cc 100644 --- a/include/platform.h +++ b/include/platform.h @@ -39,4 +39,11 @@ # define SSIZE_MAX INT_MAX #endif +/* MSVC doesn't support `[static N]` for array arguments from C99 */ +#ifdef _MSC_VER +# define MIN_NB_ELMS(N) +#else +# define MIN_NB_ELMS(N) static (N) +#endif + #endif /* RGBDS_PLATFORM_H */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95566bf4..b4a924a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set(common_src ) find_package(PkgConfig) -if(NOT PKG_CONFIG_FOUND) +if(MSVC OR NOT PKG_CONFIG_FOUND) # fallback to find_package find_package(PNG REQUIRED) else() diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 7743f90d..54a0d562 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -47,9 +47,12 @@ /* Neither MSVC nor MinGW provide `mmap` */ #if defined(_MSC_VER) || defined(__MINGW32__) -# include -# include -# include +# define WIN32_LEAN_AND_MEAN // include less from windows.h +# include // target architecture +# include // CreateFileA +# include // CreateFileMappingA +# include // MapViewOfFile +# include // CloseHandle # define MAP_FAILED NULL # define mapFile(ptr, fd, path, size) do { \ (ptr) = MAP_FAILED; \ diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 2cc33ce9..9d64435b 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -567,7 +567,7 @@ struct Symbol *sym_AddAnonLabel(void) /* * Write an anonymous label's name to a buffer */ -void sym_WriteAnonLabelName(char buf[static MAXSYMLEN + 1], uint32_t ofs, bool neg) +void sym_WriteAnonLabelName(char buf[MIN_NB_ELMS(MAXSYMLEN + 1)], uint32_t ofs, bool neg) { uint32_t id = 0;