Support building for Windows using MinGW compiler

- Adds docker support for building Windows binaries on Linux.
- Update libuv to version 1.44.1.
- Use MinGW compiled 64bit Windows binaries for distribution.
This commit is contained in:
Leroy Hopson 2022-06-29 20:48:12 +07:00
parent cceffd4edf
commit e4fdf70bca
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
10 changed files with 115 additions and 36 deletions

View file

@ -17,7 +17,7 @@ runs:
working-directory: addons/godot_xterm/native/thirdparty
shell: bash
run: |
cache_version=1 # Increment this number to invalidate the cache.
cache_version=2 # Increment this number to invalidate the cache.
godot_cpp_rev=$(git ls-tree HEAD godot-cpp --object-only)
libuv_rev=$(git ls-tree HEAD libuv --object-only)
libtsm_rev=$(git ls-tree HEAD libtsm --object-only)

View file

@ -14,13 +14,17 @@ env:
jobs:
build_docker:
name: 'Build Docker (linux, ${{ matrix.target }}, ${{ matrix.bits }})'
name: 'Build Docker (${{ matrix.platform }}, ${{ matrix.target }}, ${{ matrix.bits }})'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [ linux, windows ]
target: [ release, debug ]
bits: [ 64, 32 ]
exclude:
- platform: windows
bits: 32 # 32-bit MinGW builds not currently working.
steps:
- uses: actions/checkout@v2
with:
@ -29,7 +33,7 @@ jobs:
uses: ./.github/actions/cache-submodules
id: cache-submodules
with:
platform: linux
platform: ${{ matrix.platform }}
target: ${{ matrix.target }}
bits: ${{ matrix.bits }}
- name: Pull docker images
@ -42,20 +46,21 @@ jobs:
if: steps.cache-submodules.outputs.cache-hit != 'true'
working-directory: addons/godot_xterm/native
run: |
docker-compose build godot-cpp-linux
UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} godot-cpp-linux
docker-compose build godot-cpp-${{ matrix.platform }}
UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} godot-cpp-${{ matrix.platform }}
- name: Build libuv
if: steps.cache-submodules.outputs.cache-hit != 'true'
working-directory: addons/godot_xterm/native
run: UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} libuv-linux
run: UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} libuv-${{ matrix.platform }}
- name: Build libgodot-xterm
working-directory: addons/godot_xterm/native
run: UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} libgodot-xterm-linux
run: UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=${{ matrix.target }} -e BITS=${{ matrix.bits }} libgodot-xterm-${{ matrix.platform }}
- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: libgodot-xterm-${{ matrix.target }}
path: |
addons/godot_xterm/native/bin/*.dll
addons/godot_xterm/native/bin/*.so
build_native:
@ -125,7 +130,7 @@ jobs:
scons platform=${{ matrix.platform }} target=${{ matrix.target }} bits=${{ matrix.bits }} generate_bindings=yes -j2
- name: Setup cmake
if: steps.cache-submodules.outputs.cache-hit != 'true'
uses: jwlawson/actions-setup-cmake@v1.9
uses: jwlawson/actions-setup-cmake@v1
with:
cmake-version: '3.23.2'
use-32bit: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }}
@ -160,13 +165,14 @@ jobs:
cd addons/godot_xterm/native
scons platform=${{ matrix.platform }} target=${{ matrix.target }} bits=${{ matrix.bits }} -j2
- name: Upload binaries
if: ${{ matrix.os != 'windows-latest' && matrix.bits != '64' }}
uses: actions/upload-artifact@v2
with:
name: libgodot-xterm-${{ matrix.target }}
path: |
addons/godot_xterm/native/bin/*.dll
addons/godot_xterm/native/bin/*.wasm
addons/godot_xterm/native/bin/*.dylib
addons/godot_xterm/native/bin/*.dll
html5_export:
name: 'HTML5 Export'

View file

@ -62,6 +62,8 @@ opts.Add(EnumVariable(
allowed_values=('debug', 'release'),
ignorecase=2
))
opts.Add(BoolVariable("use_mingw",
"Use the MinGW compiler instead of MSVC - only effective on Windows", False))
opts.Add(EnumVariable("macos_arch", "Target macOS architecture",
"universal", ["universal", "x86_64", "arm64"]))
opts.Add(BoolVariable(
@ -255,7 +257,7 @@ env.Append(LIBS=[
env['target'],
'wasm' if env['platform'] == 'javascript' else env['macos_arch'] if (
env['macos_arch'] != 'universal' and env['platform'] == 'osx') else env['bits'],
env['LIBSUFFIX'],
'.a' if env['use_mingw'] else env['LIBSUFFIX'],
)),
env.File('thirdparty/libtsm/build/bin/libtsm.{}.{}.{}{}'.format(
env['platform'],
@ -280,15 +282,26 @@ else:
sources.append('src/node_pty/unix/pty.cc')
env.Append(LIBS=['util', env.File('thirdparty/libuv/build/libuv_a.a')])
else:
#sources.append('src/node_pty/win/path_util.cc')
#sources.append('src/node_pty/win/conpty.cc')
env.Append(LIBS=[
env.File('thirdparty/libuv/build/{}/uv_a.lib'.format(env["target"].capitalize())),
'Advapi32.lib',
'Iphlpapi.lib',
'user32.lib',
'userenv.lib',
'Ws2_32.lib',
])
#sources.append('src/node_pty/win/winpty.cc')
if env['use_mingw'] and not env["disable_pty"]:
env.Append(LIBS=[
env.File('thirdparty/libuv/build/libuv.dll.a'),
'-lshlwapi'
])
Execute([
Copy('bin/libuv.dll', 'thirdparty/libuv/build/libuv.dll'),
])
else:
env.Append(LIBS=[
env.File('thirdparty/libuv/build/{}/uv_a.lib'.format(env["target"].capitalize())),
'Advapi32.lib',
'Iphlpapi.lib',
'user32.lib',
'userenv.lib',
'Ws2_32.lib',
])
if env['platform'] == 'linux':
libsuffix = "a"

View file

@ -36,7 +36,7 @@ services:
- |
target=$${TARGET:-release}
bits=$${BITS:-'64'}
mkdir build 2>/dev/null ;
mkdir build 2>/dev/null
args="-DCMAKE_BUILD_TYPE=$$target \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE"
@ -57,3 +57,57 @@ services:
volumes:
- .:/godot-xterm
working_dir: /godot-xterm
godot-cpp-windows:
user: ${UID_GID}
build:
context: .
dockerfile: windows.Dockerfile
volumes:
- ./thirdparty/godot-cpp:/godot-cpp
working_dir: /godot-cpp
command:
- /bin/bash
- -c
- |
scons platform=windows use_mingw=yes generate_bindings=yes target=$${TARGET:-release} bits=$${BITS:-64} -j$$(nproc)
libuv-windows:
user: ${UID_GID}
build:
context: .
dockerfile: windows.Dockerfile
volumes:
- ./thirdparty/libuv:/libuv
working_dir: /libuv
command:
- /bin/bash
- -c
- |
target=$${TARGET:-release}
bits=$${BITS:-'64'}
mkdir build 2>/dev/null
args="-DCMAKE_BUILD_TYPE=$$target \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE"
if [[ $$bits -eq 32 ]]; then
args="$$args -DCMAKE_SYSTEM_PROCESSOR=i686 -DCMAKE_C_FLAGS=-m32"
args="$$args -DCMAKE_TOOLCHAIN_FILE=/mingw-w64-i686.cmake"
else
args="$$args -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DCMAKE_C_FLAGS="
args="$$args -DCMAKE_TOOLCHAIN_FILE=/mingw-w64-x86_64.cmake"
fi
pushd build
cmake .. $$args
popd
cmake --build build
libgodot-xterm-windows:
user: ${UID_GID}
build:
context: .
dockerfile: windows.Dockerfile
volumes:
- .:/godot-xterm
working_dir: /godot-xterm
command:
- /bin/bash
- -c
- scons platform=windows use_mingw=yes target=$${TARGET:-release} bits=$${BITS:-64} -j$$(nproc)

View file

@ -18,7 +18,7 @@ X11.32="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.32.so"
HTML5.wasm32=[ ]
OSX.64=[ ]
Windows.64=[ ]
Windows.64=[ "res://addons/godot_xterm/native/bin/libuv.dll" ]
Windows.32=[ ]
X11.64=[ ]
X11.32=[ ]

View file

@ -5,11 +5,12 @@
#include "pipe.h"
#if defined(__linux__) || defined(__APPLE__)
#include "node_pty/unix/pty.h"
#endif
#endif // defined(__linux__) || defined(__APPLE__)
#if defined(__WIN32)
//#include "node_pty/win/conpty.h"
#endif
#endif
//#include "node_pty/win/winpty.h"
#endif // defined(__WIN32)
#endif // !defined(_PTY_DISABLED)
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
@ -31,6 +32,7 @@ extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
#endif
#if defined(__WIN32)
// godot::register_tool_class<godot::ConPTY>();
// godot::register_tool_class<godot::WinPTY>();
#endif
#endif
}

View file

@ -2,22 +2,16 @@
* Copyright (c) 2013-2015, Christopher Jeffrey, Peter Sunde (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
* Copyright (c) 2022, Leroy Hopson (MIT License).
*/
#include <Shlwapi.h> // PathCombine
#include <nan.h>
#include "path_util.h"
#include <shlwapi.h> // PathCombine
#include <vector>
namespace path_util {
const wchar_t *to_wstring(const Nan::Utf8String &str) {
const char *bytes = *str;
unsigned int sizeOfStr = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, NULL, 0);
wchar_t *output = new wchar_t[sizeOfStr];
MultiByteToWideChar(CP_UTF8, 0, bytes, -1, output, sizeOfStr);
return output;
}
const wchar_t *to_wstring(String str) { return str.unicode_str(); }
bool file_exists(std::wstring filename) {
DWORD attr = ::GetFileAttributesW(filename.c_str());

View file

@ -2,18 +2,22 @@
* Copyright (c) 2013-2015, Christopher Jeffrey, Peter Sunde (MIT License)
* Copyright (c) 2016, Daniel Imms (MIT License).
* Copyright (c) 2018, Microsoft Corporation (MIT License).
* Copyright (c) 2022, Leroy Hopson (MIT License).
*/
#ifndef NODE_PTY_PATH_UTIL_H_
#define NODE_PTY_PATH_UTIL_H_
#include <nan.h>
#include <String.hpp>
#include <string>
#define MAX_ENV 65536
using namespace godot;
namespace path_util {
const wchar_t *to_wstring(const Nan::Utf8String &str);
const wchar_t *to_wstring(String str);
bool file_exists(std::wstring filename);
std::wstring get_shell_path(std::wstring filename);

@ -1 +1 @@
Subproject commit f9ad802fa5dd5afe6730f8e00cfdbf98f1d7a969
Subproject commit e8b7eb6908a847ffbe6ab2eec7428e43a0aa53a2

View file

@ -0,0 +1,6 @@
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y cmake mingw-w64 scons
RUN apt-get install -y wget && \
wget https://gist.githubusercontent.com/peterspackman/8cf73f7f12ba270aa8192d6911972fe8/raw/9d775cdff025ab12bdffe9e9a195e306a429bb86/mingw-w64-x86_64.cmake
RUN sed 's/x86_64-w64-mingw32/i686-w64-mingw32/g' /mingw-w64-x86_64.cmake > /mingw-w64-i686.cmake