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

Compile Godot with Clang 5.0 with the mingw32-64 and posix threading. #11340

Closed
fire opened this issue Sep 16, 2017 · 2 comments
Closed

Compile Godot with Clang 5.0 with the mingw32-64 and posix threading. #11340

fire opened this issue Sep 16, 2017 · 2 comments

Comments

@fire
Copy link
Member

fire commented Sep 16, 2017

Operating system or device, Godot version, GPU Model and driver (if graphics related):
Ubuntu Linux (Bash for Windows); Godot master;

Issue description:
Allow the use of Clang 5.0 with the mingw32-64 ONLY WITH posix threading.

Steps to reproduce:

Now allows:

wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Add the PPA:
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
sudo apt-get update
sudo apt-get install -y mingw-w64 build-essential cmake scons clang-5.0 # ccache distcc
# https://github.com/godotengine/godot/issues/9258
$ sudo update-alternatives --config x86_64-w64-mingw32-gcc
<choose x86_64-w64-mingw32-gcc-posix from the list>
$ sudo update-alternatives --config x86_64-w64-mingw32-g++
<choose x86_64-w64-mingw32-gcc-posix from the list>
# HACK HACK HACK to force posix
sudo mv /usr/lib/gcc/x86_64-w64-mingw32/5.3-win32 /usr/lib/gcc/x86_64-w64-mingw32/5.3-win32-backup
# END HACK HACK HACK
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-5.0 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang-5.0 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang-5.0 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 100
git clone https://github.com/tpoechtrager/wclang.git
cmake .
make
make install
git clone https://github.com/godotengine/godot.git
cd godot
scons p=windows bits=64 target=release_debug use_llvm=yes
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 5bd9a78f4..ea154ee5b 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -249,6 +249,21 @@ def configure(env):
         env['AR'] = mingw_prefix + "ar"
         env['RANLIB'] = mingw_prefix + "ranlib"
         env['LD'] = mingw_prefix + "g++"
+
+        if (env["use_llvm"] == "yes"):
+            env["CC"] = mingw_prefix + "clang"
+            env['AS'] = mingw_prefix + "as"
+            env['CXX'] = mingw_prefix + "clang++"
+            env['AR'] = mingw_prefix + "ar"
+            env['RANLIB'] = mingw_prefix + "ranlib"
+            env['LD'] = mingw_prefix + "clang++"
+            # Allow linking to dlls in mingw32
+            env.Append(CPPFLAGS=['-Xclang', '-flto-visibility-public-std'])
+            env.Append(CPPFLAGS=['-pthread'])
+            # Hack to allow multiple definitions
+            env.Append(LINKFLAGS=['-Wl,--allow-multiple-definition'])
+            env.Append(LINKFLAGS=['-pthread'])
+
         env["x86_libtheora_opt_gcc"] = True

         ## Compile flags

Also depends on #11333.

Issue tracking wclang + posix threading tpoechtrager/wclang#37

Issue tracking clang 4.0 support tpoechtrager/wclang#31

Issue tracking static causes multiple symbols to be defined https://github.com/Alexpux/MINGW-packages/issues/1819

Issue tracking Cannot compile with "-static" when using exceptions tpoechtrager/wclang#32

@fire fire changed the title Clang 5.0 with the mingw32-64 and posix threading. Compile Godot with Clang 5.0 with the mingw32-64 and posix threading. Sep 17, 2017
@fire
Copy link
Member Author

fire commented Dec 3, 2017

wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Add the PPA:
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
sudo apt-get update
sudo apt-get install -y mingw-w64 build-essential cmake scons clang-5.0 # ccache distcc
sudo apt-get install pkg-config libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev -y
git clone https://github.com/tpoechtrager/wclang.git
cmake .
make
sudo make install
git clone https://github.com/godotengine/godot.git
cd godot
scons p=windows bits=64 target=release_debug use_llvm=yes use_lto=no module_etc_enabled=no

I couldn't get lto working.

9678231 Broke ubuntu xenial's mingw.

diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index fbb02c9..8787ac3 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -265,6 +265,18 @@ def configure(env):
             env.Append(CCFLAGS=['-flto'])
             env.Append(LINKFLAGS=['-flto=' + str(env.GetOption("num_jobs"))])

+        if env['use_llvm']:
+            env["CC"] = "x86_64-w64-mingw32-clang"
+            env['AS'] = "as"
+            env['CXX'] = "x86_64-w64-mingw32-clang++"
+            env['AR'] = mingw_prefix + "gcc-ar"
+            env['RANLIB'] = mingw_prefix + "gcc-ranlib"
+            env['LD'] = "x86_64-w64-mingw32-clang++"
+            # Allow linking to dlls in mingw32
+            env.Append(CPPFLAGS=['-Xclang', '-flto-visibility-public-std'])
+            # Hack to allow multiple definitions
+            env.Append(LINKFLAGS=['-Wl,--allow-multiple-definition'])
+
         ## Compile flags

         env.Append(CCFLAGS=['-DWINDOWS_ENABLED', '-mwindows'])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 9bcbb6d..01e0ef5 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1611,15 +1611,15 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han

        DLL_DIRECTORY_COOKIE cookie;

-       if (p_also_set_library_path) {
-               cookie = AddDllDirectory(p_path.get_base_dir().c_str());
-       }
+//     if (p_also_set_library_path) {
+//             cookie = AddDllDirectory(p_path.get_base_dir().c_str());
+//     }

        p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, p_also_set_library_path ? LOAD_LIBRARY_SEARCH_DE
FAULT_DIRS : 0);

-       if (p_also_set_library_path) {
-               RemoveDllDirectory(cookie);
-       }
+//     if (p_also_set_library_path) {
+//             RemoveDllDirectory(cookie);
+//     }

        if (!p_library_handle) {
                ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + format_error_message(GetLastError()));
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index e98f827..18222d2 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -1,3 +1,5 @@
+
+
 /*************************************************************************/
 /*  os_windows.h                                                         */
 /*************************************************************************/

@fire
Copy link
Member Author

fire commented Jan 9, 2020

I was able to compile with mingw clang today.

https://github.com/mstorsjo/llvm-mingw/releases/tag/20191230

Install bin into path

scons p=windows tools=yes use_mingw=yes use_llvm=yes bits=64 use_thinlto=yes target=release_debug -j8```

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

No branches or pull requests

2 participants