diff --git a/.bazelrc b/.bazelrc index f8c0c4240..a344955a0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -38,4 +38,5 @@ build:macos --cxxopt=-std=c++17 build:windows --enable_runfiles build:windows --cxxopt="/std:c++17" # See https://bytecodealliance.github.io/wasmtime/c-api/ -# build:windows --linkopt="ws2_32.lib advapi32.lib userenv.lib ntdll.lib shell32.lib ole32.lib" +build:windows --copt="/DWASM_API_EXTERN=" +build:windows --linkopt="ws2_32.lib advapi32.lib userenv.lib ntdll.lib shell32.lib ole32.lib bcrypt.lib" diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 449bde919..c0f8e59c8 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -195,6 +195,12 @@ jobs: os: macos-11 arch: x86_64 action: test + - name: 'Wasmtime on Windows/x86_64' + engine: 'wasmtime' + repo: 'com_github_bytecodealliance_wasmtime' + os: windows-2019 + arch: x86_64 + action: test - name: 'WAVM on Linux/x86_64' engine: 'wavm' repo: 'com_github_wavm_wavm' @@ -257,7 +263,7 @@ jobs: //test/... - name: Bazel build/test (signed Wasm module) - if: ${{ matrix.engine != 'null' }} + if: ${{ matrix.engine != 'null' && !startsWith(matrix.os, 'windows') }} run: > ${{ matrix.run_under }} bazel ${{ matrix.action }} diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index 578efd6e5..1d2c97e1c 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -239,30 +239,10 @@ class ContextBase : public RootInterface, } uint32_t getLogLevel() override { return static_cast(LogLevel::info); } uint64_t getCurrentTimeNanoseconds() override { -#if !defined(_MSC_VER) - struct timespec tpe; - clock_gettime(CLOCK_REALTIME, &tpe); - uint64_t t = tpe.tv_sec; - t *= 1000000000; - t += tpe.tv_nsec; - return t; -#else - unimplemented(); - return 0; -#endif + return std::chrono::system_clock::now().time_since_epoch().count(); } uint64_t getMonotonicTimeNanoseconds() override { -#if !defined(_MSC_VER) - struct timespec tpe; - clock_gettime(CLOCK_MONOTONIC, &tpe); - uint64_t t = tpe.tv_sec; - t *= 1000000000; - t += tpe.tv_nsec; - return t; -#else - unimplemented(); - return 0; -#endif + return std::chrono::steady_clock::now().time_since_epoch().count(); } std::string_view getConfiguration() override { unimplemented(); diff --git a/src/wasmtime/wasmtime.cc b/src/wasmtime/wasmtime.cc index b3f5dc25c..5825b2157 100644 --- a/src/wasmtime/wasmtime.cc +++ b/src/wasmtime/wasmtime.cc @@ -585,8 +585,13 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, } *function = [func, function_name, this](ContextBase *context, Args... args) -> void { - wasm_val_t params_arr[] = {makeVal(args)...}; - const wasm_val_vec_t params = WASM_ARRAY_VEC(params_arr); + wasm_val_vec_t params; + if constexpr (sizeof...(args) > 0) { + wasm_val_t params_arr[] = {makeVal(args)...}; + params = WASM_ARRAY_VEC(params_arr); + } else { + params = WASM_EMPTY_VEC; + } wasm_val_vec_t results = WASM_EMPTY_VEC; const bool log = cmpLogLevel(LogLevel::trace); if (log) { @@ -633,8 +638,13 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name, } *function = [func, function_name, this](ContextBase *context, Args... args) -> R { - wasm_val_t params_arr[] = {makeVal(args)...}; - const wasm_val_vec_t params = WASM_ARRAY_VEC(params_arr); + wasm_val_vec_t params; + if constexpr (sizeof...(args) > 0) { + wasm_val_t params_arr[] = {makeVal(args)...}; + params = WASM_ARRAY_VEC(params_arr); + } else { + params = WASM_EMPTY_VEC; + } wasm_val_t results_arr[1]; wasm_val_vec_t results = WASM_ARRAY_VEC(results_arr); const bool log = cmpLogLevel(LogLevel::trace);