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

Fix x86 build on Visual Studio (C++ 20 only) #220

Closed
wants to merge 1 commit into from

Conversation

reupen
Copy link
Contributor

@reupen reupen commented Dec 14, 2024

Hi,

I noticed that 32-bit builds with Visual Studio failed due to the use of _BitScanForward64(), which is only available in 64-bit builds.

This tweaks things so that std::countr_zero() is used for Visual Studio when C++ 20 or newer is targetted. That fixes things for 32-bit builds in VS when C++ 20 is used, but 32-bit VS builds targetting C++ 17 remain unsupported.

This fix is good enough for me, though I imagine you'd want to tweak things a bit (write access is enabled on the head branch).

@@ -94,7 +95,7 @@ jobs:
- name: Configure
shell: bash
working-directory: build/
run: cmake $GITHUB_WORKSPACE -G"Visual Studio 16 2019" -T ${{matrix.toolset}}
run: cmake $GITHUB_WORKSPACE -G"Visual Studio 17 2022" -T ${{matrix.toolset}} -A ${{matrix.arch}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this as C++ 20 wasn't being used with the old Clang version in VS 2019, and also to add the v143 toolset to the matrix.

@@ -132,7 +132,7 @@ struct pt_node_token : pt_node<Reader>
if constexpr (_optimize_end)
{
static_assert(!std::is_pointer_v<typename Reader::iterator>
|| sizeof(pt_node_token) == 3 * sizeof(void*));
|| sizeof(pt_node_token) == 2 * sizeof(void*) + 8);
Copy link
Contributor Author

@reupen reupen Dec 14, 2024

Choose a reason for hiding this comment

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

I saw some fixed size things in here and so updated this static assertion to let the 32-bit build compile, but it needs double-checking really.

This gets the Visual Studio build working for 32-bit builds for C++ 20 only.

Previously, the `_BitScanForward64()` function was being used for Visual Studio, which is only available in 64-bit builds.

This switches from `_BitScanForward64()` to `std::countr_zero()` for Visual Studio when C++ 20 or newer is used.

C++ 17 remains unsupported for 32-bit builds in Visual Studio.
@reupen reupen marked this pull request as ready for review December 14, 2024 14:49
foonathan added a commit that referenced this pull request Jan 7, 2025
@foonathan foonathan closed this in 21728ab Jan 7, 2025
@foonathan
Copy link
Owner

Thanks for reporting! I've decided to fix it for x86 without support, too.

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