ref: 7e3fc1db038c1707e00fc130dc1e4a0bfd2e7ff0
parent: 77279984a53054436450ea251343515bfdbf25b1
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Jan 1 16:22:17 EST 2021
Fix Actions CI for MSVC Fixes #616
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,7 +31,9 @@
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)
--- 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 @@
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);
--- 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 */
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,7 +13,7 @@
)
find_package(PkgConfig)
-if(NOT PKG_CONFIG_FOUND)
+if(MSVC OR NOT PKG_CONFIG_FOUND)
# fallback to find_package
find_package(PNG REQUIRED)
else()
--- 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 <windows.h>
-# include <fileapi.h>
-# include <winbase.h>
+# define WIN32_LEAN_AND_MEAN // include less from windows.h
+# include <windows.h> // target architecture
+# include <fileapi.h> // CreateFileA
+# include <winbase.h> // CreateFileMappingA
+# include <memoryapi.h> // MapViewOfFile
+# include <handleapi.h> // CloseHandle
# define MAP_FAILED NULL
# define mapFile(ptr, fd, path, size) do { \
(ptr) = MAP_FAILED; \
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -567,7 +567,7 @@
/*
* 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;