Skip to content

Commit

Permalink
Fix Windows builds (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaOrtner authored Dec 7, 2023
2 parents c741572 + 37c65ae commit 8c08ca3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 80 deletions.
12 changes: 6 additions & 6 deletions core/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
// Defines the main "branch" version.
// Patch versions in this branch should be forward-compatible.
// Example: "1.1"
#define VERSION_BRANCH "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR)
#define VERSION_BRANCH _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR)
#if VERSION_PATCH
// Example: "1.1.1"
#define VERSION_NUMBER "" VERSION_BRANCH "." _MKSTR(VERSION_PATCH)
#define VERSION_NUMBER VERSION_BRANCH "." _MKSTR(VERSION_PATCH)
#else // VERSION_PATCH == 0
// we don't include it in the "pretty" version number.
// Example: "1.1" instead of "1.1.0"
#define VERSION_NUMBER "" VERSION_BRANCH
#define VERSION_NUMBER VERSION_BRANCH
#endif // VERSION_PATCH

// Version number encoded as hexadecimal int with one byte for each number.
Expand All @@ -37,15 +37,15 @@
// potential module-specific features (e.g. mono).
// Example: "1.1.stable.mono"
#define VERSION_FULL_CONFIG \
"" VERSION_NUMBER "." VERSION_STATUS VERSION_MODULE_CONFIG
VERSION_NUMBER "." VERSION_STATUS VERSION_MODULE_CONFIG

// Similar to VERSION_FULL_CONFIG, but
// also includes the (potentially custom) VERSION_BUILD description (e.g.
// official, custom_build, etc.). Example: "1.1.stable.mono.official"
#define VERSION_FULL_BUILD "" VERSION_FULL_CONFIG "." VERSION_BUILD
#define VERSION_FULL_BUILD VERSION_FULL_CONFIG "." VERSION_BUILD

// Same as above, but prepended with Rebel Engine's name and a cosmetic "v" for
// "version". Example: "Rebel Engine v1.1.stable.mono.official"
#define VERSION_FULL_NAME "" VERSION_NAME " v" VERSION_FULL_BUILD
#define VERSION_FULL_NAME VERSION_NAME " v" VERSION_FULL_BUILD

#endif // VERSION_H
1 change: 1 addition & 0 deletions misc/hooks/messagebox.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if ($file -ne "") {
$textBox.Multiline = $true
$textBox.ReadOnly = $true
$textBox.Autosize = $true
$textBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical
$textBox.Select(0, 0)
$form.Controls.Add($textBox)
}
Expand Down
83 changes: 43 additions & 40 deletions platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def setup_msvc_manual(env):
argument (example: scons p=windows) and SCons will attempt to detect what MSVC compiler will be executed and inform you.
"""
)
raise SCons.Errors.UserError(
"Bits argument should not be used when using VCINSTALLDIR"
)
raise SystemExit("Bits argument should not be used when using VCINSTALLDIR")

# Force bits arg
# (Actually msys2 mingw can support 64-bit, we could detect that)
Expand All @@ -159,6 +157,9 @@ def setup_msvc_manual(env):
"Failed to manually detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup, or avoid setting VCINSTALLDIR."
)

if env["use_llvm"]:
setup_msvc_llvm(env)


def setup_msvc_auto(env):
"""Set up MSVC using SCons's auto-detection logic"""
Expand Down Expand Up @@ -194,12 +195,37 @@ def setup_msvc_auto(env):
if env["TARGET_ARCH"] in ("amd64", "x86_64"):
env["x86_libtheora_opt_vc"] = False

if env["use_llvm"]:
setup_msvc_llvm(env)


def setup_msvc_llvm(env):
env["CC"] = "clang-cl"
env.extra_suffix = ".llvm" + env.extra_suffix


def setup_mingw(env):
"""Set up env for use with mingw"""
# Nothing to do here
print("Using MinGW")

if env["bits"] == "32":
mingw_prefix = env["mingw_prefix_32"]
else:
mingw_prefix = env["mingw_prefix_64"]

if env["use_llvm"]:
env["CC"] = mingw_prefix + "clang"
env["CXX"] = mingw_prefix + "clang++"
env["AR"] = mingw_prefix + "ar"
env["RANLIB"] = mingw_prefix + "ranlib"
env.extra_suffix = ".llvm" + env.extra_suffix
else:
env["CC"] = mingw_prefix + "gcc"
env["CXX"] = mingw_prefix + "g++"
env["AS"] = mingw_prefix + "as"
env["AR"] = mingw_prefix + "gcc-ar"
env["RANLIB"] = mingw_prefix + "gcc-ranlib"


def configure_msvc(env, manual_msvc_config):
"""Configure env to work with MSVC"""
Expand Down Expand Up @@ -317,7 +343,7 @@ def configure_msvc(env, manual_msvc_config):

# Sanitizers
if env["use_asan"]:
env.extra_suffix += ".s"
env.extra_suffix += "s"
env.Append(LINKFLAGS=["/INFERASANLIBS"])
env.Append(CCFLAGS=["/fsanitize=address"])

Expand Down Expand Up @@ -378,31 +404,14 @@ def configure_mingw(env):
else: # default to 64-bit on Linux
env["bits"] = "64"

mingw_prefix = ""

if env["bits"] == "32":
if env["use_static_cpp"]:
env.Append(LINKFLAGS=["-static"])
env.Append(LINKFLAGS=["-static-libgcc"])
env.Append(LINKFLAGS=["-static-libstdc++"])
mingw_prefix = env["mingw_prefix_32"]
else:
if env["use_static_cpp"]:
env.Append(LINKFLAGS=["-static"])
mingw_prefix = env["mingw_prefix_64"]

if env["use_llvm"]:
env["CC"] = mingw_prefix + "clang"
env["CXX"] = mingw_prefix + "clang++"
env["AS"] = mingw_prefix + "as"
env["AR"] = mingw_prefix + "ar"
env["RANLIB"] = mingw_prefix + "ranlib"
else:
env["CC"] = mingw_prefix + "gcc"
env["CXX"] = mingw_prefix + "g++"
env["AS"] = mingw_prefix + "as"
env["AR"] = mingw_prefix + "gcc-ar"
env["RANLIB"] = mingw_prefix + "gcc-ranlib"

env["x86_libtheora_opt_gcc"] = True

Expand Down Expand Up @@ -488,23 +497,17 @@ def configure(env):
] = os.environ # this makes build less repeatable, but simplifies some things
env["ENV"]["TMP"] = os.environ["TMP"]

# First figure out which compiler, version, and target arch we're using
if os.getenv("VCINSTALLDIR") and not env["use_mingw"]:
# Manual setup of MSVC
setup_msvc_manual(env)
env.msvc = True
manual_msvc_config = True
elif env.get("MSVC_VERSION", "") and not env["use_mingw"]:
setup_msvc_auto(env)
env.msvc = True
manual_msvc_config = False
else:
if env["use_mingw"]:
setup_mingw(env)
env.msvc = False

# Now set compiler/linker flags
if env.msvc:
configure_msvc(env, manual_msvc_config)

else: # MinGW
configure_mingw(env)
env.msvc = False
env.extra_suffix = ".mingw" + env.extra_suffix
else:
if os.getenv("VCINSTALLDIR"):
setup_msvc_manual(env)
configure_msvc(env, True)
else:
setup_msvc_auto(env)
configure_msvc(env, False)
env.msvc = True
env.extra_suffix = ".msvc" + env.extra_suffix
30 changes: 5 additions & 25 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2551,27 +2551,14 @@ bool OS_Windows::is_window_focused() const {
return window_focused;
}

bool OS_Windows::_is_win11_terminal() const {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
if (GetConsoleMode(hStdOut, &dwMode)) {
return (
(dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
== ENABLE_VIRTUAL_TERMINAL_PROCESSING
);
} else {
return false;
}
}

void OS_Windows::set_console_visible(bool p_enabled) {
if (console_visible == p_enabled) {
return;
}

if (!_is_win11_terminal()) {
// GetConsoleWindow is not supported by the Windows Terminal.
ShowWindow(GetConsoleWindow(), p_enabled ? SW_SHOW : SW_HIDE);
HWND console_window = GetConsoleWindow();
if (console_window != nullptr) {
ShowWindow(console_window, p_enabled ? SW_SHOW : SW_HIDE);
console_visible = p_enabled;
}
}
Expand Down Expand Up @@ -3319,20 +3306,13 @@ Error OS_Windows::execute(
modstr.write[i] = cmdline[i];
}

DWORD creation_flags = NORMAL_PRIORITY_CLASS & CREATE_NO_WINDOW;
if (p_path == get_executable_path() && GetConsoleWindow() != NULL
&& _is_win11_terminal()) {
// Open a new terminal as a workaround for Windows Terminal bug.
creation_flags |= CREATE_NEW_CONSOLE;
}

int ret = CreateProcessW(
NULL,
modstr.ptrw(),
NULL,
NULL,
0,
creation_flags,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
si_w,
Expand Down
4 changes: 0 additions & 4 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,10 @@ class OS_Windows : public OS {

CrashHandler crash_handler;

bool _is_win11_terminal() const;

void _drag_event(float p_x, float p_y, int idx);
void _touch_event(bool p_pressed, float p_x, float p_y, int idx);

void _update_window_style(bool p_repaint = true, bool p_maximized = false);
void _update_window_mouse_passthrough();

void _set_mouse_mode_impl(MouseMode p_mode);

// functions used by main to initialize/deinitialize the OS
Expand Down
9 changes: 4 additions & 5 deletions platform/windows/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ APP_ICON ICON "platform/windows/rebel-icon.ico"
1 VERSIONINFO
FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0
FILEOS 4
FILETYPE 1
FILEOS 4 // VOS__WINDOWS32 = 0x00000004L
FILETYPE 1 // VFT_APP = 0x00000001L

BEGIN
BLOCK "StringFileInfo"
BEGIN
Expand All @@ -21,9 +22,7 @@ BEGIN
VALUE "FileVersion", VERSION_NUMBER
VALUE "ProductName", VERSION_NAME
VALUE "Licence", "MIT"
VALUE "LegalCopyright", "2022-Present, Rebel Engine contributors
2014-2022, Godot Engine contributors.
2007-2022, Juan Linietsky, Ariel Manzur."
VALUE "LegalCopyright", "\xA9 Rebel Engine contributors"
VALUE "ProductVersion", VERSION_FULL_BUILD
END
END
Expand Down

0 comments on commit 8c08ca3

Please sign in to comment.