From 0b5745e4eb5bbd0580f5f56b719053da952885fa Mon Sep 17 00:00:00 2001 From: Wunk Date: Tue, 15 Nov 2022 01:45:59 -0800 Subject: [PATCH] oaknut: Add Windows on Arm support (#1) * Add instruction-cache invalidation for Windows chromium uses this function as well for their `CpuFeatures::FlushICache` implementation and similarly utilizes `sys_icache_invalidate` on OSX. * Fix MSVC compiler warning flags Avoids build errors on MSVC. Just copied the warning flags used on dynarmic. * Implement `OAKNUT_USE_BUNDLED_CATCH` For building on Windows. This was previously unimplemented as `DYNARMIC_USE_BUNDLED_CATCH`. --- .github/workflows/build-and-test.yml | 2 +- CMakeLists.txt | 33 ++++++++++++++++++++++++++-- include/oaknut/code_block.hpp | 3 +++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 59a5b6e..149efba 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -29,7 +29,7 @@ jobs: -B ${{github.workspace}}/build -H. -GNinja - -DDYNARMIC_USE_BUNDLED_CATCH=ON + -DOAKNUT_USE_BUNDLED_CATCH=ON - name: Build working-directory: ${{github.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 42d4170..2deb7f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,8 @@ target_compile_features(oaknut INTERFACE cxx_std_20) # Tests if (MASTER_PROJECT) - if (DYNARMIC_USE_BUNDLED_CATCH) + option(OAKNUT_USE_BUNDLED_CATCH "Use the embedded Catch2 submodule" OFF) + if (OAKNUT_USE_BUNDLED_CATCH) add_subdirectory(externals/catch) else() find_package(Catch2 3 REQUIRED) @@ -54,5 +55,33 @@ if (MASTER_PROJECT) ) target_include_directories(oaknut-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests) target_link_libraries(oaknut-tests PRIVATE Catch2::Catch2WithMain merry::oaknut) - target_compile_options(oaknut-tests PRIVATE -Wall -Wextra -Wcast-qual -pedantic -pedantic-errors -Wfatal-errors -Wno-missing-braces) + if (MSVC) + target_compile_options(oaknut-tests PRIVATE + /experimental:external + /external:W0 + /external:anglebrackets + /W4 + /w44263 # Non-virtual member function hides base class virtual function + /w44265 # Class has virtual functions, but destructor is not virtual + /w44456 # Declaration of 'var' hides previous local declaration + /w44457 # Declaration of 'var' hides function parameter + /w44458 # Declaration of 'var' hides class member + /w44459 # Declaration of 'var' hides global definition + /w44946 # Reinterpret-cast between related types + /wd4592 # Symbol will be dynamically initialized (implementation limitation) + /permissive- # Stricter C++ standards conformance + /MP + /Zi + /Zo + /EHsc + /Zc:externConstexpr # Allows external linkage for variables declared "extern constexpr", as the standard permits. + /Zc:inline # Omits inline functions from object-file output. + /Zc:throwingNew # Assumes new (without std::nothrow) never returns null. + /volatile:iso # Use strict standard-abiding volatile semantics + /bigobj # Increase number of sections in .obj files + /DNOMINMAX + ) + else() + target_compile_options(oaknut-tests PRIVATE -Wall -Wextra -Wcast-qual -pedantic -pedantic-errors -Wfatal-errors -Wno-missing-braces) + endif() endif() diff --git a/include/oaknut/code_block.hpp b/include/oaknut/code_block.hpp index 6b7deac..e700d6c 100644 --- a/include/oaknut/code_block.hpp +++ b/include/oaknut/code_block.hpp @@ -9,6 +9,7 @@ #include #if defined(_WIN32) +# define NOMINMAX # include #elif defined(__APPLE__) # include @@ -78,6 +79,8 @@ public: { #if defined(__APPLE__) sys_icache_invalidate(mem, size); +#elif defined(_WIN32) + FlushInstructionCache(GetCurrentProcess(), mem, size); #else static std::size_t icache_line_size = 0x10000, dcache_line_size = 0x10000;