some fixes (#1308)

* Only append compiler flags in cmake

* add `RelWithDebInfo-clang` windows build

* bump serializer initial buffer size to 32mb

* extra flags for msvc

* proper anaphoric goal macros

* specify windows sdk version?

* fix "Object files are not named properly" fake error

* Update goal-lib.gc
This commit is contained in:
ManDude 2022-04-15 23:32:37 +01:00 committed by GitHub
parent cc01f2810f
commit 65de778b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 24 deletions

View File

@ -21,21 +21,25 @@ endif()
if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
message(STATUS "Clang on MSVC detected! Adding compile flags")
set(CMAKE_CXX_FLAGS
"-Xclang -fcxx-exceptions \
"${CMAKE_CXX_FLAGS} \
-Xclang -fcxx-exceptions \
-Xclang -fexceptions \
-Xclang -std=c++17 \
-Xclang -D_CRT_SECURE_NO_WARNINGS \
-mavx \
-Wno-c++11-narrowing -Wno-c++98-compat -W3")
# additional c++ flags for release mode for our projects
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384")
# additional c++ and linker flags for release mode for our projects
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
endif()
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384")
elseif(UNIX)
message(STATUS "GCC detected! Adding compile flags")
set(CMAKE_CXX_FLAGS
@ -69,10 +73,18 @@ elseif(MSVC)
# set(CMAKE_CXX_FLAGS_DEBUG "/ZI")
endif()
# c++ flags for all build types
set(CMAKE_CXX_FLAGS "/EHsc /utf-8 /arch:AVX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /arch:AVX")
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384")
# additional c++ and linker flags for specific build types
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
endif()
endif()
if(WIN32)
@ -80,6 +92,9 @@ if(WIN32)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 7.1.7600.0.30514) # win7.1, supports xp
message("Windows SDK version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()
if(ASAN_BUILD)

View File

@ -54,6 +54,25 @@
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
{
"name": "RelWithDebInfo-clang",
"displayName": "Windows RelWithDebInfo (clang-cl)",
"description": "Target Windows with the Visual Studio development environment.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/Release",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"INSTALL_GTEST": "True",
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
{
"name": "Release-clang-static",
"displayName": "Windows Release - Static (clang-cl)",

View File

@ -3,6 +3,7 @@
#include <cstring>
#include <string>
#include <vector>
#include "common/common_types.h"
#include "common/util/Assert.h"
/*!
@ -35,7 +36,7 @@ class Serializer {
* later be accessed with get_save_result.
*/
Serializer() : m_writing(true) {
const size_t initial_size = 32;
constexpr size_t initial_size = 32 * 1024 * 1024;
m_data = (u8*)malloc(initial_size);
m_size = initial_size;
}

View File

@ -393,11 +393,14 @@ std::string ObjectFileDB::generate_obj_listing(const std::unordered_set<std::str
result += "[\"" + pad_string(name + "\", ", 50) + "\"" +
pad_string(x.name_in_dgo + "\", ", 50) + std::to_string(x.obj_version) + ", " +
dgos + ", \"\"],\n";
unique_count++;
if (all_unique_names.find(name) != all_unique_names.end() &&
merged_objs.find(name) == merged_objs.end()) {
lg::error("Object file {} appears multiple times with the same name.", name);
}
if (merged_objs.find(name) == merged_objs.end() ||
all_unique_names.find(name) == all_unique_names.end()) {
unique_count++;
}
all_unique_names.insert(name);
}
}

View File

@ -314,9 +314,9 @@
(let* ((level-info (lookup-level-info name))
(level-name (remap-level-name level-info))
)
(swhen (level-get obj level-name)
(level-status-set! bc want-status)
(return bc)
(awhen (level-get obj level-name)
(level-status-set! it want-status)
(return it)
)
(let ((a0-7 (level-get-most-disposable obj)))
(set! s5-1 (if a0-7 (level-status-set! a0-7 'inactive)

View File

@ -553,8 +553,8 @@
"Get the status of a file in this art control. #f = file not found"
(dotimes (i 2)
(swhen (file-status (-> obj buffer i) name part)
(return bc)
(awhen (file-status (-> obj buffer i) name part)
(return it)
)
)
#f

View File

@ -544,13 +544,13 @@
)
(case (-> src type)
((entity-actor entity-ambient)
(swhen (res-lump-struct-exact (the entity src) 'effect-name symbol)
(set! name (string->sound-name (symbol->string bc)))
(awhen (res-lump-struct-exact (the entity src) 'effect-name symbol)
(set! name (string->sound-name (symbol->string it)))
(set! sound-times (res-lump-data (the entity src) 'cycle-speed (pointer float)))
(set! spec *ambient-spec*)
(let ((tag (new 'static 'res-tag)))
(swhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag))
(set! params bc)
(awhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag))
(set! params it)
(set! param-count (the int (-> tag elt-count)))
)
)

View File

@ -438,16 +438,23 @@
)
)
(defmacro swhen (condition &rest body)
"Same as when, but saves the branch condition onto a variable named bc"
(defmacro aif (condition true false)
"Anaphoric if, similar to Common Lisp"
`(let ((bc ,condition))
(if bc
(begin ,@body)
`(let ((it ,condition))
(if it
,true
,false
)
)
)
(defmacro awhen (condition &rest body)
"Anaphoric when"
`(aif ,condition (begin ,@body) #f)
)
(defmacro return (val)
`(return-from #f ,val)
)
@ -460,7 +467,8 @@
(defmacro case (switch &key (comp =) &rest cases)
"A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially.
else can be used like the 'default' case, but it must be the last one."
else can be used like the 'default' case, but it must be the last one.
comp is the function to use when evaluating the clauses. It can be any valid head of a form (operator or call)."
(with-gensyms (sw)
;; save the switch to a variable (only evaluated once)