Skip to content

Conversation

@vkensou
Copy link
Contributor

@vkensou vkensou commented Aug 30, 2025

No description provided.

@GordonSmith GordonSmith requested a review from Copilot August 30, 2025 19:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses compilation issues with MSVC C++20 by adding header guards, function inlining, and resolving compiler-specific problems with array sizing and template processing.

  • Added header guards and inline specifiers to prevent multiple definition errors
  • Fixed zero-sized array compilation error by ensuring minimum array size of 1
  • Replaced problematic std::ceil/std::log2 usage with constexpr-compatible alternatives

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
include/wamr.hpp Added header guards and inline specifiers to all functions
include/cmcpp/traits.hpp Added constexpr helper functions and fixed template recursion for variant processing
include/cmcpp/lower.hpp Changed uint parameter type to uint32_t for consistency
include/cmcpp/lift.hpp Changed uint parameter type to uint32_t for consistency
include/cmcpp/context.hpp Fixed func_t template syntax from comma-separated to function signature format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

void trap(const char *msg)
inline void trap(const char *msg)
{
throw new std::runtime_error(msg);
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Throwing a pointer to an exception object instead of the exception object itself. This should be throw std::runtime_error(msg); without the new keyword.

Suggested change
throw new std::runtime_error(msg);
throw std::runtime_error(msg);

Copilot uses AI. Check for mistakes.

constexpr size_t output_size = std::is_same<result_t, void>::value ? 0 : 1;
wasm_val_t outputs[output_size];
wasm_val_t outputs[output_size == 0 ? 1 : output_size];
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The ternary operator used to avoid zero-sized arrays is unclear. Consider using a named constant or adding a comment explaining why this workaround is necessary for MSVC C++20 compatibility.

Suggested change
wasm_val_t outputs[output_size == 0 ? 1 : output_size];
// MSVC does not allow zero-sized arrays, so we use 1 when output_size is zero.
constexpr size_t OUTPUT_ARRAY_SIZE = (output_size == 0 ? 1 : output_size);
wasm_val_t outputs[OUTPUT_ARRAY_SIZE];

Copilot uses AI. Check for mistakes.
Comment on lines +713 to +715
process_types<StartIndex + 1, Rest...>(flat);
}
}
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

The recursive call to process_types is inside the for loop, which will cause multiple recursive calls for each element in ValTrait<First>::flat_types. The recursion should happen after processing all elements of the current type.

Suggested change
process_types<StartIndex + 1, Rest...>(flat);
}
}
}
}
process_types<StartIndex + 1, Rest...>(flat);

Copilot uses AI. Check for mistakes.
@GordonSmith
Copy link
Owner

Thanks for the submission!

The windows CI build failure looks unrelated to this PR and I would like to see that working before I merge (even if I just see it passing on my machine), I will try and look in the next could of days...

@GordonSmith
Copy link
Owner

Can you check the failing windows build (I fixed the vcpkg configuration failing)?

@vkensou
Copy link
Contributor Author

vkensou commented Sep 2, 2025

Can you check the failing windows build (I fixed the vcpkg configuration failing)?

I have some error:

error: building wasi-sdk:x64-windows failed with: BUILD_FAILED
See https://learn.microsoft.com/vcpkg/troubleshoot/build-failures?WT.mc_id=vcpkg_inproduct_cli for more information.
Elapsed time to handle wasi-sdk:x64-windows: 5 min
Please ensure you're using the latest port files with `git pull` and `vcpkg update`.
Then check for known issues at:
  https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+wasi-sdk
You can submit a new issue at:
  https://github.com/microsoft/vcpkg/issues/new?title=[wasi-sdk]+Build+error+on+x64-windows&body=Copy%20issue%20body%20from%20F%3A%2Fcode2%2Fdodo%2Fcomponent-model-cpp%2Fbuild%2Fvcpkg_installed%2Fvcpkg%2Fissue_body.md

-- Running vcpkg install - failed
CMake Error at vcpkg/scripts/buildsystems/vcpkg.cmake:941 (message):
  vcpkg install failed.  See logs for more information:
  F:\code2\dodo\component-model-cpp\build\vcpkg-manifest-install.log
Call Stack (most recent call first):
  D:/Program Files/CMake/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:146 (include)
  CMakeLists.txt:3 (project)

@vkensou
Copy link
Contributor Author

vkensou commented Sep 2, 2025

vcpkg configure is so slow

@GordonSmith
Copy link
Owner

It is slow, but it does do a good job of caching the builds.

Can you share the content of F:\code2\dodo\component-model-cpp\build\vcpkg-manifest-install.log?

@vkensou
Copy link
Contributor Author

vkensou commented Sep 2, 2025

log is here

A suitable version of cmake was not found (required v3.30.1).
Downloading https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-windows-i386.zip -> cmake-3.30.1-windows-i386.zip
Successfully downloaded cmake-3.30.1-windows-i386.zip
Extracting cmake...
A suitable version of 7zip was not found (required v24.9.0).
Downloading https://github.com/ip7z/7zip/releases/download/24.09/7z2409.exe -> 7z2409.7z.exe
Successfully downloaded 7z2409.7z.exe
Extracting 7zip...
A suitable version of 7zr was not found (required v24.9.0).
Downloading https://github.com/ip7z/7zip/releases/download/24.09/7zr.exe -> 44d8504a-7zr.exe
Successfully downloaded 44d8504a-7zr.exe
Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)...
Detecting compiler hash for triplet x64-windows...
A suitable version of powershell-core was not found (required v7.2.24).
Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.2.24/PowerShell-7.2.24-win-x64.zip -> PowerShell-7.2.24-win-x64.zip
Successfully downloaded PowerShell-7.2.24-win-x64.zip
Extracting powershell-core...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe
The following packages will be built and installed:
    doctest:x64-windows@2.4.12 -- git+https://github.com/microsoft/vcpkg@fcb90f044a88f9c4d3af9410dd6eba419ca36016
    icu[core,tools]:x64-windows@74.2#6 -- git+https://github.com/microsoft/vcpkg@ebd75351b43b485143b74a866381afafcd28b77b
  * vcpkg-cmake:x64-windows@2024-04-23 -- git+https://github.com/microsoft/vcpkg@e74aa1e8f93278a8e71372f1fa08c3df420eb840
  * vcpkg-cmake-config:x64-windows@2024-05-23 -- git+https://github.com/microsoft/vcpkg@97a63e4bc1a17422ffe4eff71da53b4b561a7841
  * vcpkg-cmake-get-vars:x64-windows@2025-05-29 -- git+https://github.com/microsoft/vcpkg@d6510f888dd526c7828f6b973349e7f30be51254
  * vcpkg-make:x64-windows@2025-07-09 -- git+https://github.com/microsoft/vcpkg@a61503261b3d9410e844b52cab080cdf91b17685
    wasi-sdk:x64-windows@25.0 -- F:\code2\dodo\component-model-cpp\vcpkg_overlays\wasi-sdk
Additional packages (*) will be modified to complete this operation.
Restored 6 package(s) from C:\Users\Administrator\AppData\Local\vcpkg\archives in 1.5 s. Use --debug to see more details.
Installing 1/7 vcpkg-cmake-config:x64-windows@2024-05-23...
Elapsed time to handle vcpkg-cmake-config:x64-windows: 2.39 ms
vcpkg-cmake-config:x64-windows package ABI: 5f32804c7915d7da1cac54b275b93bfa5a14e4895e3f5fe21dc0d05aa769153f
Installing 2/7 vcpkg-cmake:x64-windows@2024-04-23...
Elapsed time to handle vcpkg-cmake:x64-windows: 2.85 ms
vcpkg-cmake:x64-windows package ABI: 0d207a6a8569a3a9de6c28f2b10b3fc9cd22d6565f3c73f04f080ae91a9d8b03
Installing 3/7 doctest:x64-windows@2.4.12...
Elapsed time to handle doctest:x64-windows: 4.34 ms
doctest:x64-windows package ABI: d152219bfe4484d927f0ea9c4ec0d3dca8ba9436956292f05f433fa5aee46102
Installing 4/7 vcpkg-cmake-get-vars:x64-windows@2025-05-29...
Elapsed time to handle vcpkg-cmake-get-vars:x64-windows: 3.08 ms
vcpkg-cmake-get-vars:x64-windows package ABI: a62dfae140a3824bd81afe66cd3444859b03e7e949420cc5b68334d15e739988
Installing 5/7 vcpkg-make:x64-windows@2025-07-09...
Elapsed time to handle vcpkg-make:x64-windows: 4.13 ms
vcpkg-make:x64-windows package ABI: 5159e75925be5f6a98971424d1f4b8bb7b86fb5adea8f64651ec4a0bf8981e58
Installing 6/7 icu[core,tools]:x64-windows@74.2#6...
Elapsed time to handle icu:x64-windows: 39.7 ms
icu:x64-windows package ABI: 446b14860a123ee0ef3c8ccd0b66c7f85e71c500926b0404decdcb6319c7aa92
Installing 7/7 wasi-sdk:x64-windows@25.0...
Building wasi-sdk:x64-windows@25.0...
F:\code2\dodo\component-model-cpp\vcpkg_overlays\wasi-sdk: info: installing overlay port from here
CMake Warning at scripts/ports.cmake:182 (message):
  Unexpected UNKNOWN_READ_ACCESS on variable APPLE in script mode.

  This variable name insufficiently expresses whether it refers to the target
  system or to the host system.  Use a prefixed variable instead.

  - Variables providing information about the host:

    CMAKE_HOST_<SYSTEM>
    VCPKG_HOST_IS_<SYSTEM>

  - Variables providing information about the target:

    VCPKG_TARGET_IS_<SYSTEM>
    VCPKG_DETECTED_<VARIABLE> (using vcpkg_cmake_get_vars)

Call Stack (most recent call first):
  F:/code2/dodo/component-model-cpp/vcpkg_overlays/wasi-sdk/portfile.cmake:2147483647 (z_vcpkg_warn_ambiguous_system_variables)
  F:/code2/dodo/component-model-cpp/vcpkg_overlays/wasi-sdk/portfile.cmake:3 (if)
  scripts/ports.cmake:206 (include)


CMake Warning at scripts/ports.cmake:182 (message):
  Unexpected UNKNOWN_READ_ACCESS on variable UNIX in script mode.

  This variable name insufficiently expresses whether it refers to the target
  system or to the host system.  Use a prefixed variable instead.

  - Variables providing information about the host:

    CMAKE_HOST_<SYSTEM>
    VCPKG_HOST_IS_<SYSTEM>

  - Variables providing information about the target:

    VCPKG_TARGET_IS_<SYSTEM>
    VCPKG_DETECTED_<VARIABLE> (using vcpkg_cmake_get_vars)

Call Stack (most recent call first):
  F:/code2/dodo/component-model-cpp/vcpkg_overlays/wasi-sdk/portfile.cmake:2147483647 (z_vcpkg_warn_ambiguous_system_variables)
  scripts/ports.cmake:206 (include)


CMake Warning at scripts/ports.cmake:182 (message):
  Unexpected READ_ACCESS on variable WIN32 in script mode.

  This variable name insufficiently expresses whether it refers to the target
  system or to the host system.  Use a prefixed variable instead.

  - Variables providing information about the host:

    CMAKE_HOST_<SYSTEM>
    VCPKG_HOST_IS_<SYSTEM>

  - Variables providing information about the target:

    VCPKG_TARGET_IS_<SYSTEM>
    VCPKG_DETECTED_<VARIABLE> (using vcpkg_cmake_get_vars)

Call Stack (most recent call first):
  F:/code2/dodo/component-model-cpp/vcpkg_overlays/wasi-sdk/portfile.cmake:2147483647 (z_vcpkg_warn_ambiguous_system_variables)
  scripts/ports.cmake:206 (include)


Downloading https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-windows.tar.gz -> wasi-sdk-25.0-x86_64-windows.tar.gz
wasi-sdk-25.0-x86_64-windows.tar.gz.31676.part: error: download from https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-windows.tar.gz had an unexpected hash
note: Expected: e8bdae827dbbb967bf9815603aeff76ac40344c79cf6a1c388e63931c77cdc5560860c6f2ec74f3c7895fab08b93940f60e9e26365b6f4ba354ca3a921803be7
note: Actual  : 0d7c4b7311944f5c63143e2e2d240d91379db40ee6d8b6f2cad698f3a454f4b886019f5f16dbd5f1d29bcf8ef1af339e38a77b0bf9407236d76bcd36777ae58d
CMake Error at scripts/cmake/vcpkg_download_distfile.cmake:136 (message):
  Download failed, halting portfile.
Call Stack (most recent call first):
  F:/code2/dodo/component-model-cpp/vcpkg_overlays/wasi-sdk/portfile.cmake:17 (vcpkg_download_distfile)
  scripts/ports.cmake:206 (include)


error: building wasi-sdk:x64-windows failed with: BUILD_FAILED
See https://learn.microsoft.com/vcpkg/troubleshoot/build-failures?WT.mc_id=vcpkg_inproduct_cli for more information.
Elapsed time to handle wasi-sdk:x64-windows: 5.2 min
Please ensure you're using the latest port files with `git pull` and `vcpkg update`.
Then check for known issues at:
  https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+wasi-sdk
You can submit a new issue at:
  https://github.com/microsoft/vcpkg/issues/new?title=[wasi-sdk]+Build+error+on+x64-windows&body=Copy%20issue%20body%20from%20F%3A%2Fcode2%2Fdodo%2Fcomponent-model-cpp%2Fbuild%2Fvcpkg_installed%2Fvcpkg%2Fissue_body.md

@GordonSmith
Copy link
Owner

Can you do a:

git submodule update --init --recursive
./vcpkg/bootstrap-vcpkg.sh 

You may need to do ./vcpkg/bootstrap-vcpkg.bat depending on your shell

@vkensou
Copy link
Contributor Author

vkensou commented Sep 2, 2025

strange. vcpkg download wasi-sdk-${VERSION}-x86_64-windows.tar.gz on my compute the hash is ee91880d1be2a9d2f3bd90c1893448c8861130a0726811de0f55f90394260aa4693f7efbee81de5bd599c4395fe26809642741033e8e062894c9c4dea249bae4. but on ci it is e8bdae827dbbb967bf9815603aeff76ac40344c79cf6a1c388e63931c77cdc5560860c6f2ec74f3c7895fab08b93940f60e9e26365b6f4ba354ca3a921803be7.

@GordonSmith
Copy link
Owner

You might want to rebase your local onto the latests trunk?

@GordonSmith
Copy link
Owner

Closing as trunk now builds and passes unit tests on windows.

GordonSmith added a commit that referenced this pull request Oct 14, 2025
…dex> template

- Added empty_case<Index> template in variant.hpp for unique empty variant cases
- Modified code_generator.cpp to use empty_case<Index> instead of bare monostate
- Added proper ValTrait specialization for empty_case with ValType::Void
- Result: 180/199 stubs compile (down from 182 baseline)
- Main issue (duplicate monostate) resolved, but variants stub shows new error (assignment operator)
- Need to investigate variant assignment operator issue next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants