diff --git a/CMakeLists.txt b/CMakeLists.txt index fb3ea7b28..e2f7a23e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,10 @@ endif() cable_configure_compiler() cable_add_compile_options( + IF_SUPPORTED -Wcast-qual -Wcast-align -Wmissing-declarations - IF_SUPPORTED -Wextra-semi -Wold-style-cast -Wfinal-dtor-non-final-class diff --git a/circle.yml b/circle.yml index affd23dc8..32a070768 100644 --- a/circle.yml +++ b/circle.yml @@ -1,4 +1,6 @@ version: 2.1 +orbs: + win: circleci/windows@5.0 parameters: benchmark: @@ -400,6 +402,34 @@ jobs: cmake_options: -DNATIVE=ON - test + release-windows: + executor: win/server-2022 + environment: + CMAKE_BUILD_TYPE: Release + steps: + - checkout + - run: + name: "Setup environment (bash)" + shell: bash + command: | + echo 'export PATH=$PATH:"/c/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin"' >> $BASH_ENV + - run: + name: 'Configure' + shell: powershell + command: | + $ErrorActionPreference = "Stop" + & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 + which cmake + cmake -S . -B ~/build -G Ninja -DCMAKE_INSTALL_PREFIX=C:\install -DCMAKE_CXX_STANDARD=20 -DFIZZY_TESTING=ON + - run: + name: 'Build' + shell: powershell + command: | + $ErrorActionPreference = "Stop" + & 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 + cmake --build ~/build + - test + coverage-clang: executor: linux-clang-latest steps: @@ -789,6 +819,7 @@ workflows: - release-native-linux - release-macos - release-native-macos + - release-windows - coverage-gcc: requires: - fetch-spectests diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 8ced70a0a..ad93b11df 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -1,14 +1,14 @@ # Hunter local configuration. -hunter_config( - GTest - VERSION 1.11.0 - URL https://github.com/google/googletest/archive/release-1.11.0.tar.gz - SHA1 7b100bb68db8df1060e178c495f3cbe941c9b058 - CMAKE_ARGS - HUNTER_INSTALL_LICENSE_FILES=LICENSE - gtest_force_shared_crt=TRUE -) +#hunter_config( +# GTest +# VERSION 1.11.0 +# URL https://github.com/google/googletest/archive/release-1.11.0.tar.gz +# SHA1 7b100bb68db8df1060e178c495f3cbe941c9b058 +# CMAKE_ARGS +# HUNTER_INSTALL_LICENSE_FILES=LICENSE +# gtest_force_shared_crt=TRUE +#) hunter_config( benchmark diff --git a/cmake/Hunter/init.cmake b/cmake/Hunter/init.cmake index 4ccf3bedf..6412569a7 100644 --- a/cmake/Hunter/init.cmake +++ b/cmake/Hunter/init.cmake @@ -25,7 +25,7 @@ if(NOT CMAKE_CONFIGURATION_TYPES) endif() HunterGate( - URL https://github.com/cpp-pm/hunter/archive/v0.23.294.tar.gz - SHA1 0dd1ee8723d54a15822519c17a877c1f281fce39 + URL https://github.com/cpp-pm/hunter/archive/v0.24.13.tar.gz + SHA1 2bc7384b2bf27db5b3847739a6a5361fa04075e7 LOCAL ) diff --git a/cmake/ProjectUVWASI.cmake b/cmake/ProjectUVWASI.cmake index 74c29cbe9..4347d9ab8 100644 --- a/cmake/ProjectUVWASI.cmake +++ b/cmake/ProjectUVWASI.cmake @@ -12,6 +12,14 @@ set(include_dir ${source_dir}/include) set(uvwasi_library ${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}uvwasi_a${CMAKE_STATIC_LIBRARY_SUFFIX}) set(uv_library ${binary_dir}/_deps/libuv-build/${CMAKE_STATIC_LIBRARY_PREFIX}uv_a${CMAKE_STATIC_LIBRARY_SUFFIX}) +# This is hack. Should fix proper uvwasi.cmake integration. +if(WIN32) + list(APPEND uv_library iphlpapi) + list(APPEND uv_library userenv) + list(APPEND uv_library psapi) + list(APPEND uv_library ws2_32) +endif() + if(UNIX AND NOT APPLE) set(system_libs "pthread;dl;rt") endif() diff --git a/lib/fizzy/bytes.hpp b/lib/fizzy/bytes.hpp index 07dd80695..f602185d3 100644 --- a/lib/fizzy/bytes.hpp +++ b/lib/fizzy/bytes.hpp @@ -7,9 +7,142 @@ #include #include +#include + namespace fizzy { + +template > +class basic_string_view +{ + // static_assert(!is_array_v); + // static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>); + // static_assert(is_same_v<_CharT, typename _Traits::char_type>); + +public: + // Types. + using traits_type = Traits; + using value_type = CharT; + using const_pointer = const value_type*; + using const_reference = const value_type&; + using const_iterator = const value_type*; + using size_type = size_t; + static constexpr size_type npos = size_type(-1); + + // Construction. + constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} + // constexpr basic_string_view(const basic_string_view& other) noexcept = + // default; + constexpr basic_string_view(const_pointer str) : data_(str), len_(internal_strlen(str)) {} + constexpr basic_string_view(const_pointer str, size_type len) : data_(str), len_(len) {} + // basic_string_view(const std::string& str) + // : data_(str.data()), len_(str.size()) {} + constexpr basic_string_view(std::basic_string /*str*/) : data_(nullptr), len_(0) {} + + // basic_string_view& operator=(const basic_string_view&) noexcept = default; + + // constexpr basic_string_view() noexcept : data_(nullptr), len_(0) {} + // constexpr basic_string_view(const_pointer str, size_type len) + // : data_(str), len_(len) {} + // constexpr basic_string_view(const_pointer str) + // : data_(str), len_(internal_strlen(str)) {} + // basic_string_view(const std::string& str) + // : data_(str.data()), len_(str.size()) {} + // template + // constexpr basic_string_view(It first, End last) {} + // template< class R > + // explicit constexpr basic_string_view( R&& r ) {} + + // Iterator support. + constexpr const_iterator begin() const noexcept { return data_; } + constexpr const_iterator end() const noexcept { return data_ + len_; } + + // Element access. + constexpr const_pointer data() const noexcept { return data_; } + + // Capacity. + constexpr size_type size() const noexcept { return len_; } + + constexpr const_reference operator[](size_type pos) const { return data_[pos]; } + + // Modifiers. + void remove_prefix(size_type n) + { + data_ = data_ + n; + len_ -= n; + } + + // Operations. + + // Returns a view of the substring [pos, pos + rcount), where rcount is the + // smaller of count and size() - pos. + constexpr basic_string_view substr(size_type pos = 0, size_type count = npos) const + { + if (pos > len_) + { + throw std::out_of_range("Out of range"); + } + + const size_type rcount = std::min(count, len_ - pos); + if (rcount > 0) + { + return basic_string_view(data_ + pos, rcount); + } + return basic_string_view(); + } + + // Compares two character sequences. + constexpr int compare(basic_string_view s) const noexcept + { + const size_t rlen = std::min(len_, s.len_); + const int comparison = traits_type::compare(data_, s.data_, rlen); + if (comparison != 0) + return comparison; + if (len_ == s.len_) + return 0; + return len_ < s.len_ ? -1 : 1; + } + // Compare substring(pos1, count1) with s. + constexpr int compare(size_type pos1, size_type count1, basic_string_view s) const + { + return substr(pos1, count1).compare(s); + } + // Compare substring(pos1, count1) with s.substring(pos2, count2). + constexpr int compare(size_type pos1, size_type count1, basic_string_view s, size_type pos2, + size_type count2) const + { + return substr(pos1, count1).compare(s.substr(pos2, count2)); + } + constexpr int compare(const_pointer s) const { return compare(basic_string_view(s)); } + constexpr int compare(size_type pos1, size_type count1, const_pointer s) const + { + return substr(pos1, count1).compare(basic_string_view(s)); + } + constexpr int compare(size_type pos1, size_type count1, const_pointer s, size_type count2) const + { + return substr(pos1, count1).compare(basic_string_view(s, count2)); + } + + // operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, + + // constexpr bool operator!=(basic_string_view x, const std::basic_string y) + // const { + // return true; + // } + +private: + constexpr static size_type internal_strlen(const_pointer str) + { + return str ? traits_type::length(str) : 0; + } + + const_pointer data_; + size_type len_; +}; + +using bytes_view = basic_string_view; + using bytes = std::basic_string; -using bytes_view = std::basic_string_view; +// using bytes_view = std::basic_string_view; } // namespace fizzy diff --git a/lib/fizzy/capi.cpp b/lib/fizzy/capi.cpp index e06e6f3a9..d831b6640 100644 --- a/lib/fizzy/capi.cpp +++ b/lib/fizzy/capi.cpp @@ -8,7 +8,9 @@ #include "instantiate.hpp" #include "parser.hpp" #include +#include #include +#include #include namespace diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index 10a21a261..b099b5156 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -31,7 +31,7 @@ template inline T read(const uint8_t*& input) noexcept { T ret; - __builtin_memcpy(&ret, input, sizeof(ret)); + memcpy(&ret, input, sizeof(ret)); input += sizeof(ret); return ret; } @@ -39,14 +39,14 @@ inline T read(const uint8_t*& input) noexcept template inline void store(bytes& input, size_t offset, T value) noexcept { - __builtin_memcpy(input.data() + offset, &value, sizeof(value)); + memcpy(input.data() + offset, &value, sizeof(value)); } template inline T load(bytes_view input, size_t offset) noexcept { T ret; - __builtin_memcpy(&ret, input.data() + offset, sizeof(ret)); + memcpy(&ret, input.data() + offset, sizeof(ret)); return ret; } @@ -459,7 +459,11 @@ T fnearest(T value) noexcept } template -__attribute__((no_sanitize("float-divide-by-zero"))) inline constexpr T fdiv(T a, T b) noexcept +#ifndef _MSC_VER +__attribute__((no_sanitize("float-divide-by-zero"))) +#endif +inline constexpr T +fdiv(T a, T b) noexcept { static_assert(std::is_floating_point_v); static_assert(std::numeric_limits::is_iec559); @@ -494,9 +498,11 @@ inline T fmax(T a, T b) noexcept return a < b ? b : a; } - -__attribute__((no_sanitize("float-cast-overflow"))) inline constexpr float demote( - double value) noexcept +#ifndef _MSC_VER +__attribute__((no_sanitize("float-cast-overflow"))) +#endif +inline constexpr float +demote(double value) noexcept { // The float-cast-overflow UBSan check disabled for this conversion. In older clang versions // (up to 8.0) it reports a failure when non-infinity f64 value is converted to f32 infinity. diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index 20413d0dd..75ad76b55 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -9,6 +9,7 @@ #include "types.hpp" #include "utf8.hpp" #include +#include #include namespace fizzy @@ -455,8 +456,8 @@ inline parser_result parse(const uint8_t* pos, const uint8_t* end) std::unique_ptr parse(bytes_view input) { - if (input.substr(0, wasm_prefix.size()) != wasm_prefix) - throw parser_error{"invalid wasm module prefix"}; + // if (input.substr(0, wasm_prefix.size()) != wasm_prefix) + // throw parser_error{"invalid wasm module prefix"}; input.remove_prefix(wasm_prefix.size()); diff --git a/lib/fizzy/parser.hpp b/lib/fizzy/parser.hpp index b2db86fde..2026d507c 100644 --- a/lib/fizzy/parser.hpp +++ b/lib/fizzy/parser.hpp @@ -7,6 +7,7 @@ #include "exceptions.hpp" #include "leb128.hpp" #include "module.hpp" +#include #include namespace fizzy @@ -40,7 +41,7 @@ inline parser_result parse_value(const uint8_t* pos, const uint8_t* end) throw parser_error{"unexpected EOF"}; T value; - __builtin_memcpy(&value, pos, size); + memcpy(&value, pos, size); return {value, pos + size}; } diff --git a/lib/fizzy/parser_expr.cpp b/lib/fizzy/parser_expr.cpp index f75f2b4e9..7764a315e 100644 --- a/lib/fizzy/parser_expr.cpp +++ b/lib/fizzy/parser_expr.cpp @@ -8,6 +8,7 @@ #include "parser.hpp" #include "stack.hpp" #include +#include namespace fizzy { @@ -16,7 +17,7 @@ namespace template inline void store(uint8_t* dst, T value) noexcept { - __builtin_memcpy(dst, &value, sizeof(value)); + memcpy(dst, &value, sizeof(value)); } template diff --git a/test/utils/wabt_engine.cpp b/test/utils/wabt_engine.cpp index 3c1fc93a3..4f37c38cd 100644 --- a/test/utils/wabt_engine.cpp +++ b/test/utils/wabt_engine.cpp @@ -16,7 +16,7 @@ namespace fizzy::test class WabtEngine final : public WasmEngine { // mutable because getting RefPtr from Ref requires non-const Store - mutable wabt::interp::Store m_store{([]() constexpr noexcept { + mutable wabt::interp::Store m_store{([]() noexcept { wabt::Features features; features.disable_multi_value(); features.disable_sat_float_to_int(); diff --git a/test/utils/wasm_engine.hpp b/test/utils/wasm_engine.hpp index aaacd96f3..3bb0e98d6 100644 --- a/test/utils/wasm_engine.hpp +++ b/test/utils/wasm_engine.hpp @@ -7,6 +7,7 @@ #include "bytes.hpp" #include #include +#include #include #include #include