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

[C++] Windows build support #1294

Merged
merged 2 commits into from
Jan 3, 2024
Merged

[C++] Windows build support #1294

merged 2 commits into from
Jan 3, 2024

Conversation

LiangliangSui
Copy link
Contributor

When compiled using Windows bazel, the following error occurs:

cl: 命令行 warning D9002 :忽略未知选项“-pthread”
cl: 命令行 warning D9002 :忽略未知选项“-std=c++17”
time_util.cc
src/fury/util/time_util.cc(43): warning C4477: “snprintf”: 格式字符串“%03ld”需要类型“long”的参数,但可变参数 1 拥有了类型“_Rep”        with
        [
            _Rep=__int64
        ]
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%lld”
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%Id”
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%I64d”
INFO: From Compiling absl/debugging/failure_signal_handler.cc:
failure_signal_handler.cc
INFO: From Compiling absl/strings/str_replace.cc:
str_replace.cc
INFO: From Compiling absl/strings/match.cc:
match.cc
INFO: From Compiling absl/strings/internal/stringify_sink.cc:
stringify_sink.cc
ERROR: C:/users/sui/desktop/incubator-fury/src/fury/util/BUILD:5:11: Compiling src/fury/util/buffer.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //src/fury/util:fury_util) C:\Program Files (x86)\Microsoft Visual 
Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-opt/bin/src/fury/util/_objs/fury_util/buffer.obj.params
cl: 命令行 warning D9002 :忽略未知选项“-pthread”
cl: 命令行 warning D9002 :忽略未知选项“-std=c++17”
buffer.cc
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(31): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(51): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(56): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(59): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(59): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(66): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(66): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(97): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(105): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(108): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(120): error C7525: 内联变量至少
需要 "/std:c++17"
Target //src/fury/util:fury_util failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 13.649s, Critical Path: 2.07s
INFO: 42 processes: 6 internal, 36 local.
ERROR: Build did NOT complete successfully

The root cause is that in Windows, specifying C++17 requires the use of /std:c++17, while in unix/linux systems, use -std=c++17.
Since the operating system name cannot be determined in fury.bzl to dynamically set COPTS, so I moved them to .bazelrc.

Later, I will solve the warnings generated by compiling in windows, for example src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%lld”.

Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
@LiangliangSui
Copy link
Contributor Author

@chaokunyang PTAL, thanks!

Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

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

Could you add a job to ci.yml for windows build?

Refer to https://github.com/actions/runner-images, you can use windows-2022.

@chaokunyang
Copy link
Collaborator

@LiangliangSui We can use select to add options like this:

COPTS = select({
    "//:opt": ["-DBAZEL_OPT"],
    "//conditions:default": [],
}) + select({
    "@bazel_tools//src/conditions:windows": [
        # TODO(mehrdadn): (How to) support dynamic linking?
        "-DRAY_STATIC",
    ],
    "//conditions:default": [
    ],
}) + select({
    "//:clang-cl": [
        "-Wno-builtin-macro-redefined",  # To get rid of warnings caused by deterministic build macros (e.g. #define __DATE__ "redacted")
    ],
    "//conditions:default": [
    ],
})

But it's OK to add it in .bazelrc.

@LiangliangSui
Copy link
Contributor Author

Could you add a job to ci.yml for windows build?
Refer to https://github.com/actions/runner-images, you can use windows-2022.

@PragmaTwice Should we merge the pr first or wait until the windows ci is written and merged together?

@PragmaTwice
Copy link
Member

Could you add a job to ci.yml for windows build?
Refer to https://github.com/actions/runner-images, you can use windows-2022.

@PragmaTwice Should we merge the pr first or wait until the windows ci is written and merged together?

Looks fine to me.

But BTW, we need to make something like ./ci/run_ci.sh install_bazel/cpp work on windows.

@LiangliangSui
Copy link
Contributor Author

But BTW, we need to make something like ./ci/run_ci.sh install_bazel/cpp work on windows.

Yeah, I will implement it next.

@PragmaTwice PragmaTwice merged commit 9e87851 into apache:main Jan 3, 2024
17 checks passed
@PragmaTwice
Copy link
Member

Thank you for your contribution!

theweipeng pushed a commit to theweipeng/fury that referenced this pull request Jan 6, 2024
When compiled using Windows bazel, the following error occurs:

```
cl: 命令行 warning D9002 :忽略未知选项“-pthread”
cl: 命令行 warning D9002 :忽略未知选项“-std=c++17”
time_util.cc
src/fury/util/time_util.cc(43): warning C4477: “snprintf”: 格式字符串“%03ld”需要类型“long”的参数,但可变参数 1 拥有了类型“_Rep”        with
        [
            _Rep=__int64
        ]
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%lld”
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%Id”
src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%I64d”
INFO: From Compiling absl/debugging/failure_signal_handler.cc:
failure_signal_handler.cc
INFO: From Compiling absl/strings/str_replace.cc:
str_replace.cc
INFO: From Compiling absl/strings/match.cc:
match.cc
INFO: From Compiling absl/strings/internal/stringify_sink.cc:
stringify_sink.cc
ERROR: C:/users/sui/desktop/incubator-fury/src/fury/util/BUILD:5:11: Compiling src/fury/util/buffer.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //src/fury/util:fury_util) C:\Program Files (x86)\Microsoft Visual 
Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-opt/bin/src/fury/util/_objs/fury_util/buffer.obj.params
cl: 命令行 warning D9002 :忽略未知选项“-pthread”
cl: 命令行 warning D9002 :忽略未知选项“-std=c++17”
buffer.cc
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(31): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(50): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(51): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(55): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(56): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(59): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(59): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(61): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(66): error C3533: 参数不能为包 
含“auto”的类型
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(66): note: 非类型模板参数中的“auto”至少需要“/std:c++17”
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(97): error C7525: 内联变量至少 
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(105): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(108): error C7525: 内联变量至少
需要 "/std:c++17"
bazel-out/x64_windows-opt/bin/src/fury/meta/_virtual_includes/fury_meta\fury/meta/type_traits.h(120): error C7525: 内联变量至少
需要 "/std:c++17"
Target //src/fury/util:fury_util failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 13.649s, Critical Path: 2.07s
INFO: 42 processes: 6 internal, 36 local.
ERROR: Build did NOT complete successfully
```


The root cause is that in Windows, specifying C++17 requires the use of
`/std:c++17`, while in unix/linux systems, use `-std=c++17`.
Since the operating system name cannot be determined in fury.bzl to
dynamically set COPTS, so I moved them to .bazelrc.

Later, I will solve the warnings generated by compiling in windows, for
example `src/fury/util/time_util.cc(43): note: 请考虑在格式字符串中使用“%lld”`.

Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
Co-authored-by: Twice <twice@apache.org>
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.

3 participants