Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #843

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: 2.1
orbs:
win: circleci/[email protected]

parameters:
benchmark:
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++20 is forced here.

- 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:
Expand Down Expand Up @@ -789,6 +819,7 @@ workflows:
- release-native-linux
- release-macos
- release-native-macos
- release-windows
- coverage-gcc:
requires:
- fetch-spectests
Expand Down
18 changes: 9 additions & 9 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -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(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newer Hunter contains this.

# 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
Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update to 0.23.371 at least in order to support MSVC 2022.

SHA1 2bc7384b2bf27db5b3847739a6a5361fa04075e7
LOCAL
)
8 changes: 8 additions & 0 deletions cmake/ProjectUVWASI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theses are imported in https://github.com/nodejs/uvwasi/blob/master/cmake/FindLibUV.cmake, but we do a botched job at cmake-integrating uvwasi.

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()
Expand Down
135 changes: 134 additions & 1 deletion lib/fizzy/bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,142 @@
#include <cstdint>
#include <string>

#include <stdexcept>

namespace fizzy
{

template <class CharT, class Traits = std::char_traits<CharT>>
class basic_string_view
{
// static_assert(!is_array_v<CharT>);
// 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<CharT> /*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<class It, class End>
// 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<CharT> x, const std::basic_string<CharT> 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<uint8_t>;

using bytes = std::basic_string<uint8_t>;
using bytes_view = std::basic_string_view<uint8_t>;
// using bytes_view = std::basic_string_view<uint8_t>;

} // namespace fizzy
2 changes: 2 additions & 0 deletions lib/fizzy/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "instantiate.hpp"
#include "parser.hpp"
#include <fizzy/fizzy.h>
#include <algorithm>
#include <cstring>
#include <iterator>
#include <memory>

namespace
Expand Down
20 changes: 13 additions & 7 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ template <typename T>
inline T read(const uint8_t*& input) noexcept
{
T ret;
__builtin_memcpy(&ret, input, sizeof(ret));
memcpy(&ret, input, sizeof(ret));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fixed.

input += sizeof(ret);
return ret;
}

template <typename T>
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 <typename T>
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;
}

Expand Down Expand Up @@ -459,7 +459,11 @@ T fnearest(T value) noexcept
}

template <typename T>
__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<T>);
static_assert(std::numeric_limits<T>::is_iec559);
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions lib/fizzy/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "types.hpp"
#include "utf8.hpp"
#include <cassert>
#include <iterator>
#include <unordered_set>

namespace fizzy
Expand Down Expand Up @@ -455,8 +456,8 @@ inline parser_result<Data> parse(const uint8_t* pos, const uint8_t* end)

std::unique_ptr<const Module> 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());

Expand Down
3 changes: 2 additions & 1 deletion lib/fizzy/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "exceptions.hpp"
#include "leb128.hpp"
#include "module.hpp"
#include <cstring>
#include <memory>

namespace fizzy
Expand Down Expand Up @@ -40,7 +41,7 @@ inline parser_result<T> 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};
}

Expand Down
3 changes: 2 additions & 1 deletion lib/fizzy/parser_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "parser.hpp"
#include "stack.hpp"
#include <cassert>
#include <cstring>

namespace fizzy
{
Expand All @@ -16,7 +17,7 @@ namespace
template <typename T>
inline void store(uint8_t* dst, T value) noexcept
{
__builtin_memcpy(dst, &value, sizeof(value));
memcpy(dst, &value, sizeof(value));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CWE 805 advisory: suspicious sizeof in strncpy, strncat or memcpy


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

}

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion test/utils/wabt_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member Author

@axic axic Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found by MSVC:

[48/103] Building CXX object test\utils\CMakeFiles\test-utils.dir\wabt_engine.cpp.obj
FAILED: test/utils/CMakeFiles/test-utils.dir/wabt_engine.cpp.obj 
C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\cl.exe  /nologo /TP  -IC:\Users\circleci.PACKER-633B1A5A\project -IC:\Users\circleci.PACKER-633B1A5A\project\lib\fizzy -IC:\Users\circleci.PACKER-633B1A5A\project\include -external:IC:\Users\circleci.PACKER-633B1A5A\build\_deps\src\wabt -external:IC:\Users\circleci.PACKER-633B1A5A\build\_deps\src\wabt-build -external:IC:\Users\circleci.PACKER-633B1A5A\build\_deps\src\wasm3 -external:IC:\Users\circleci.PACKER-633B1A5A\.hunter\_Base\2bc7384\4753fe5\c0cf92b\Install\include -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG -MD /W4 /WX /wd4068 -std:c++20 /showIncludes /Fotest\utils\CMakeFiles\test-utils.dir\wabt_engine.cpp.obj /Fdtest\utils\CMakeFiles\test-utils.dir\test-utils.pdb /FS -c C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(19): error C3615: constexpr function 'fizzy::test::WabtEngine::<lambda_1>::operator ()' cannot result in a constant expression
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(21): note: failure was caused by call of undefined function or one not declared 'constexpr'
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(21): note: see usage of 'wabt::Features::disable_multi_value'
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(22): note: failure was caused by call of undefined function or one not declared 'constexpr'
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(22): note: see usage of 'wabt::Features::disable_sat_float_to_int'
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(23): note: failure was caused by call of undefined function or one not declared 'constexpr'
C:\Users\circleci.PACKER-633B1A5A\project\test\utils\wabt_engine.cpp(23): note: see usage of 'wabt::Features::disable_sign_extension'
[49/103] Building CXX object test\utils\CMakeFiles\test-utils.dir\asserts.cpp.obj
``

features.disable_sat_float_to_int();
Expand Down
1 change: 1 addition & 0 deletions test/utils/wasm_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "bytes.hpp"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <memory>
#include <optional>
#include <stdexcept>
Expand Down