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

windows launcher: Make the launcher compile under mingw #24752

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/native/windows/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#include "src/main/native/windows/file.h"

#include <WinIoCtl.h>
#include <stdint.h> // uint8_t
#include <versionhelpers.h>
#include <winbase.h>
#include <windows.h>
#include <winioctl.h>

#include <memory>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion src/main/native/windows/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "src/main/native/windows/process.h"

#include <versionhelpers.h>
#include <windows.h>
#include <VersionHelpers.h>

#include <memory>
#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/launcher/java_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to use curly brackets here to declare a variable.

#else
wofstream jar_manifest_file(jar_manifest_file_path);
#endif
Expand Down
21 changes: 21 additions & 0 deletions src/tools/launcher/launcher_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#endif

#include <windows.h>
#include <processenv.h>
#include <shellapi.h>
#include <winbase.h>

#include <memory>
#include <string>
Expand Down Expand Up @@ -64,6 +67,24 @@ static std::wstring GetExecutableFileName() {
return buffer.substr(0, length);
}

#if defined(__MINGW32__) && not defined(BAZEL_MINGW_UNICODE)
// MinGW requires linkopt=-municode to use wmain as entry point.
// The below allows fallback to main when BAZEL_MINGW_UNICODE is not defined.
// Otherwise, to use wmain directly, one needs to use both linkopt=-municode and
// copt=-DBAZEL_MINGW_UNICODE.
int wmain(int argc, wchar_t* argv[]);
int main() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mingw requires linkopt -municode to use wmain.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add this comment in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do it later. I am on a train currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments added. PTAL.

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
Expand Down
Loading