From bf26bcc7cb20a9f95238e9c556ff854292c57925 Mon Sep 17 00:00:00 2001 From: Boleyn Su Date: Thu, 19 Dec 2024 07:32:53 +0800 Subject: [PATCH] windows launcher: Make the launcher compile under mingw TEST: bazel build --platforms=//:windows_x86_64 --extra_toolchains=@llvm_mingw_linux_x86_64//:cc-toolchain-linux_x86_64-windows_x86_64 //src/tools/launcher:launcher --- src/main/native/windows/file.cc | 2 +- src/main/native/windows/process.cc | 2 +- src/tools/launcher/java_launcher.cc | 2 +- src/tools/launcher/launcher_main.cc | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/native/windows/file.cc b/src/main/native/windows/file.cc index 70809bde048900..e882f7bef303f4 100644 --- a/src/main/native/windows/file.cc +++ b/src/main/native/windows/file.cc @@ -18,11 +18,11 @@ #include "src/main/native/windows/file.h" -#include #include // uint8_t #include #include #include +#include #include #include diff --git a/src/main/native/windows/process.cc b/src/main/native/windows/process.cc index e01c3b7df39d44..bc89594223cea1 100644 --- a/src/main/native/windows/process.cc +++ b/src/main/native/windows/process.cc @@ -18,8 +18,8 @@ #include "src/main/native/windows/process.h" +#include #include -#include #include #include diff --git a/src/tools/launcher/java_launcher.cc b/src/tools/launcher/java_launcher.cc index 3f96654ad855ef..bc65144d61c2c8 100644 --- a/src/tools/launcher/java_launcher.cc +++ b/src/tools/launcher/java_launcher.cc @@ -250,7 +250,7 @@ wstring JavaBinaryLauncher::CreateClasspathJar(const wstring& classpath) { binary_base_path + rand_id + L".jar_manifest"; blaze_util::AddUncPrefixMaybe(&jar_manifest_file_path); #if (__cplusplus >= 201703L) - wofstream jar_manifest_file(std::filesystem::path(jar_manifest_file_path)); + wofstream jar_manifest_file{std::filesystem::path(jar_manifest_file_path)}; #else wofstream jar_manifest_file(jar_manifest_file_path); #endif diff --git a/src/tools/launcher/launcher_main.cc b/src/tools/launcher/launcher_main.cc index bcf7d89e5dadeb..33a08f20f6d45a 100644 --- a/src/tools/launcher/launcher_main.cc +++ b/src/tools/launcher/launcher_main.cc @@ -29,6 +29,9 @@ #endif #include +#include +#include +#include #include #include @@ -64,6 +67,20 @@ static std::wstring GetExecutableFileName() { return buffer.substr(0, length); } +#if defined(__MINGW32__) && not defined(BAZEL_MINGW_UNICODE) +int wmain(int argc, wchar_t* argv[]); +int main() { + int argc = 0; + wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc); + if (argv == nullptr) { + die(L"CommandLineToArgvW failed."); + } + int result = wmain(argc, argv); + LocalFree(argv); + return result; +} +#endif + int wmain(int argc, wchar_t* argv[]) { // In case the given binary path is a shortened Windows 8dot3 path, we convert // it back to its long path form so that path manipulations (e.g. appending