diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c626c9..5ee0d96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,8 +19,56 @@ env: LIBUV_CACHE_VERSION: 1 jobs: - build: - name: 'Build' + build_docker: + name: 'Build Docker' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: [ release, debug ] + bits: [ 64, 32 ] + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Get godot-cpp submodule commit hash + shell: bash + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + run: | + echo ::set-env name=GODOT_CPP_COMMIT_HASH::$(git ls-tree HEAD addons/godot_xterm/native/thirdparty/godot-cpp -l | cut -d\ -f3) + - name: Cache godot-cpp bindings + uses: actions/cache@v2 + id: cache + env: + cache-name: cache-godot-cpp + with: + path: addons/godot_xterm/native/thirdparty/godot-cpp + key: godot-cpp-${{ matrix.platform }}-${{ matrix.target }}-${{ matrix.bits }}-${{ env.GODOT_CPP_COMMIT_HASH }}-v${{ env.GODOT_CPP_CACHE_VERSION }} + - name: Get libuv submodule commit hash + shell: bash + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + run: | + echo ::set-env name=LIBUV_COMMIT_HASH::$(git ls-tree HEAD addons/godot_xterm/native/thirdparty/libuv -l | cut -d\ -f3) + + # Build inside docker container in order to target older GLIBC versions. + - name: Run build script + run: | + cd addons/godot_xterm/native + /bin/bash ./build.sh --target ${{ matrix.target }} --bits ${{ matrix.bits }} --docker + + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: libgodot-xterm-${{ matrix.target }} + path: | + addons/godot_xterm/native/bin/*.so + + + build_native: + name: 'Build Native' runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -154,10 +202,10 @@ jobs: - name: Upload build artifacts uses: actions/upload-artifact@v2 + if: ${{ matrix.platform != 'linux' }} with: name: libgodot-xterm-${{ matrix.target }} path: | - addons/godot_xterm/native/bin/*.so addons/godot_xterm/native/bin/*.wasm addons/godot_xterm/native/bin/*.dylib addons/godot_xterm/native/bin/*.dll @@ -219,7 +267,7 @@ jobs: html5_export: name: 'HTML5 Export' - needs: [ build, export_template ] + needs: [ build_docker, build_native, export_template ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -254,7 +302,7 @@ jobs: test: name: 'Test' - needs: [ install_plugins, build ] + needs: [ install_plugins, build_docker, build_native ] runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/CHANGELOG.md b/CHANGELOG.md index e0aa06b..5c9677b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- `--docker` option to `build.sh` script, in order to build Linux binaries inside a docker container with an older GLIBC version. + +### Changed +- GitHub Actions workflow to build Linux debug/release binaries inside docker container in order to target older GLIBC versions. ### Fixed - Registered `pipe.close()` method, so `kill()` can be called when using unix PTY node. diff --git a/addons/godot_xterm/native/.dockerignore b/addons/godot_xterm/native/.dockerignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/addons/godot_xterm/native/.dockerignore @@ -0,0 +1 @@ +* diff --git a/addons/godot_xterm/native/Dockerfile b/addons/godot_xterm/native/Dockerfile new file mode 100644 index 0000000..094ac65 --- /dev/null +++ b/addons/godot_xterm/native/Dockerfile @@ -0,0 +1,4 @@ +FROM kroggen/ubuntu-16.04-gcc +RUN apt-get update -y +RUN apt-get install -y python3 python3-pip gcc-multilib g++-multilib +RUN pip3 install scons diff --git a/addons/godot_xterm/native/SConstruct b/addons/godot_xterm/native/SConstruct index c483f95..e28838e 100644 --- a/addons/godot_xterm/native/SConstruct +++ b/addons/godot_xterm/native/SConstruct @@ -277,7 +277,7 @@ else: else: #sources.append('src/node_pty/win/conpty.cc') env.Append(LIBS=[ - env.File(f'thirdparty/libuv/build/{env["target"].capitalize()}/uv_a.lib'), + env.File('thirdparty/libuv/build/{}/uv_a.lib'.format(env["target"].capitalize())), 'Advapi32.lib', 'Iphlpapi.lib', 'user32.lib', diff --git a/addons/godot_xterm/native/build.sh b/addons/godot_xterm/native/build.sh index 1da7cab..1b6427b 100755 --- a/addons/godot_xterm/native/build.sh +++ b/addons/godot_xterm/native/build.sh @@ -11,26 +11,43 @@ while [[ $# -gt 0 ]]; do shift shift ;; + -b|--bits) + bits="$2" + shift + shift + ;; --disable-pty) disable_pty="yes" shift ;; + --docker) + docker="yes" + shift + ;; *) - echo "Usage: ./build.sh [-t|--target ] [--disable_pty]"; + echo "Usage: ./build.sh [-t|--target ] [-b|--bits <32|64>] [--disable_pty] [--docker]"; exit 128 shift ;; esac done + # Set defaults. target=${target:-debug} +bits=${bits:-64} disable_pty=${disable_pty:-no} nproc=$(nproc || sysctl -n hw.ncpu) - -#GODOT_DIR Get the absolute path to the directory this script is in. +# Get the absolute path to the directory this script is in. NATIVE_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +if [ -n "$docker" ]; then + # Run build script inside docker container. + cd ${NATIVE_DIR} + UID_GID="0:0" TARGET=$target BITS=$bits docker-compose build linux + UID_GID="$(id -u):$(id -g)" TARGET=$target BITS=$bits docker-compose run linux + exit 0 +fi # Run script inside a nix shell if it is available. if command -v nix-shell && [ $NIX_PATH ] && [ -z $IN_NIX_SHELL ]; then @@ -39,7 +56,6 @@ if command -v nix-shell && [ $NIX_PATH ] && [ -z $IN_NIX_SHELL ]; then exit fi - # Update git submodules. updateSubmodules() { eval $1=$2 # E.g LIBUV_DIR=${NATIVE_DIR}/thirdparty/libuv @@ -54,15 +70,14 @@ updateSubmodules LIBUV_DIR ${NATIVE_DIR}/thirdparty/libuv updateSubmodules LIBTSM_DIR ${NATIVE_DIR}/thirdparty/libtsm updateSubmodules GODOT_CPP_DIR ${NATIVE_DIR}/thirdparty/godot-cpp - # Build godot-cpp bindings. cd ${GODOT_CPP_DIR} echo "scons generate_bindings=yes target=$target -j$nproc" -scons generate_bindings=yes target=$target -j$nproc +scons generate_bindings=yes target=$target bits=$bits -j$nproc # Build libuv as a static library. cd ${LIBUV_DIR} -mkdir build || true +mkdir -p build cd build args="-DCMAKE_BUILD_TYPE=$target -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE" if [ "$target" == "release" ]; then @@ -70,13 +85,14 @@ if [ "$target" == "release" ]; then else args="$args -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL" fi +if [[ "$bits" -eq 32 ]]; then args="$args -DCMAKE_SYSTEM_PROCESSOR=i686 -DCMAKE_C_FLAGS=-m32"; fi cmake .. $args cd .. -cmake --build build --config $target -j$nproc +cmake --build build --config $target # Build libgodot-xterm. cd ${NATIVE_DIR} -scons target=$target disable_pty=$disable_pty -j$nproc +scons target=$target bits=$bits disable_pty=$disable_pty -j$nproc # Use Docker to build libgodot-xterm javascript. if [ -x "$(command -v docker-compose)" ]; then diff --git a/addons/godot_xterm/native/docker-compose.yaml b/addons/godot_xterm/native/docker-compose.yaml index abb5e8b..5be3101 100644 --- a/addons/godot_xterm/native/docker-compose.yaml +++ b/addons/godot_xterm/native/docker-compose.yaml @@ -12,3 +12,14 @@ services: scons platform=javascript target=$${TARGET:-debug} -j$$(nproc) cd /src scons platform=javascript target=$${TARGET:-debug} -j$$(nproc) + linux: + build: . + user: ${UID_GID} + volumes: + - .:/src + command: + - /bin/bash + - -c + - | + cd /src + /bin/bash ./build.sh --target ${TARGET} --bits ${BITS}