Skip to content

Conversation

@nathandelisle
Copy link

@nathandelisle nathandelisle commented Oct 9, 2025

Fixes #95

bug:
Windows/clang-cl build of training tools failed with:
error: call to deleted constructor of 'std::future<...>'

caused by a lambda capturing std::vector<std::future<...>> by value while MSVC’s std::packaged_task copies the callable internally (copy move-only type)

Fix:
tools/training/utils/thread_pool.h: implement run(...) via perfect-forwarding + std::apply; capture callable/args by move
tools/training/clustering/compression_utils.cpp: capture futures via std::shared_ptr<std::vector<std::future>> initialized with std::move; iterate over *futures_ptr

@meta-cla meta-cla bot added the cla signed label Oct 9, 2025
@Cyan4973
Copy link
Contributor

Cyan4973 commented Oct 9, 2025

This is likely a follow-up of #96 .
We'll try to deal with it in the same effort.

Don't worry about clang-format requirement.
We'll take care of that.

At this point, I mostly need the reviews of @kevinjzhang and @Victor-C-Zhang , since they own the code being modified.

#include <unordered_set>
#include "openzl/common/a1cbor_helpers.h"
#include "openzl/common/allocation.h"
#include <future>
Copy link
Contributor

Choose a reason for hiding this comment

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

@kevinjzhang
this PR proposes adding <future> to this unit.
Does that sound correct to you ?

Copy link
Contributor

@kevinjzhang kevinjzhang Oct 9, 2025

Choose a reason for hiding this comment

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

This include seems fine to me considering they are already used. I'm surprised this is necessary tho because a transitive dependency thread_pool.h includes future

#include <queue>
#include <thread>
#include <vector>
#include <mutex>
Copy link
Contributor

Choose a reason for hiding this comment

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

@kevinjzhang @Victor-C-Zhang
This PR adds quite a number of dependencies to thread_pool.h.
What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

These are all part of libstdc++ so I think it's fine. I think most of these should be transitive dependencies anyways.

std::future<ReturnType> result = task->get_future();
template <class F, class... Args>
auto run(F&& f, Args&&... args)
-> std::future<std::invoke_result_t<std::decay_t<F>, std::decay_t<Args>...>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@terrelln or @felixhandte could you take a look at this?

meta-codesync bot pushed a commit that referenced this pull request Dec 20, 2025
Summary:
Adds missing STL headers required for Windows/clang-cl builds:

- `<string>` for `std::to_string` in `Logger.h`
- `<numeric>` for `std::accumulate`, `std::iota` in test and training files
- `<stdexcept>` for `std::runtime_error` in `InputSet*.cpp`
- `<array>` for `std::array` in `test_functionGraphs.cpp`
- `<optional>` for `std::optional` in `InputSetBuilder.h`
- `<chrono>` for `std::chrono::high_resolution_clock` in trainer files
- Added MSVC detection (`_MSC_VER`) for IEEE 754 floating-point support in `portability.h`

These headers are implicitly included via transitive dependencies on GCC/Clang but MSVC requires explicit includes. **No runtime or performance impact** - purely compile-time fixes.

Fixes #95

**Note:** I have also validated that #97 (std::future move-only fix) works correctly on my Windows setup.

## Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)

Pull Request resolved: #299

Test Plan:
Built the project

cmake -S . -B build -G "Visual Studio 14 2015" -T ClangCL
cmake --build build --config Release

build is now successful
The only error is for libzstd_shared.vcxproj (the shared/DLL version of zstd):
```fatal error RC1012: mismatched parenthesis : missing '```
This is a resource compiler issue with Clang headers when building the shared library. But this is non-blocking

After build successful, subsequent fix is about passing test, correcting ```std::future``` using PR from #97 and std::uniform distribution #301

### Test Configuration

- **Compiler:** clang-cl (ClangCL toolset)
- **Generator:** Visual Studio 14 2015 with ClangCL toolset (`-T ClangCL`)
- **Build type:** Release
- **Platform:** Windows 11 x64

Reviewed By: Cyan4973

Differential Revision: D89547335

Pulled By: zhiningli

fbshipit-source-id: 9fef41317cd73e9505c4fbef59b6041a5ad2a848
@meta-codesync meta-codesync bot closed this in 3924936 Dec 20, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 20, 2025

@zhiningli merged this pull request in 3924936.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows/clang-cl tools fail to build — missing includes + copying move-only std::future

6 participants