Use default export templates for HTML5

Changes Emscripten SDK version to match that used to compile the default export
templates used by Godot 3.5 (in this case 3.1.14 as can be seen here:
https://github.com/godotengine/build-containers/blob/3.5/Dockerfile.javascript).

This means we no longer need to compile custom export templates when
exporting HTML5 for Godot 3.5. Exports from other Godot versions may
requiring compiling the GDNative library with a different version of the
Emscripten SDK.

- Changes renderer from GLES3 -> GLES2 and reduces MSAA level to better
  support HTML5 export.
- Updates GitHub Action to export HTML5 and upload as a build artifact.
- Adds Cypress test to smoke test HTML5 export.
This commit is contained in:
Leroy Hopson 2022-08-01 19:56:43 +12:00
parent b31861f171
commit fae6317eb7
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
26 changed files with 4895 additions and 118 deletions

21
.github/import_assets.tscn vendored Normal file
View file

@ -0,0 +1,21 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="GDScript" id=1]
script/source = "tool
extends Timer
func _enter_tree():
start()
func _on_timeout():
get_tree().quit(0)
"
[node name="Timer" type="Timer"]
process_mode = 0
wait_time = 10.0
one_shot = true
autostart = true
script = SubResource( 1 )
[connection signal="timeout" from="." to="." method="_on_timeout"]

View file

@ -102,7 +102,7 @@ jobs:
if: ${{ matrix.platform == 'javascript' }}
uses: mymindstorm/setup-emsdk@v11
with:
version: 3.1.5
version: 3.1.14
actions-cache-folder: emsdk-cache-${{ matrix.target }}
- name: Install additional javascript build dependencies
if: ${{ matrix.platform == 'javascript' }}
@ -168,43 +168,9 @@ jobs:
addons/godot_xterm/native/bin/*.dylib
addons/godot_xterm/native/bin/*.dll
# GDNative HTML5 export templates aren't provided so we must build them
export_template:
name: 'Export Template'
runs-on: ubuntu-latest
strategy:
matrix:
target: [ release, debug ]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Get godot submodule commit hash
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: |
echo ::set-env name=GODOT_COMMIT_HASH::$(git ls-tree HEAD misc/export_templates/godot -l | cut -d\ -f3)
- name: Cache export template
uses: actions/cache@v2
id: cache-export-template
env:
cache-name: cache-export-template
with:
path: misc/export_templates/godot/bin
key: godot-${{ env.GODOT_COMMIT_HASH }}-${{ matrix.target }}-v${{ env.EXPORT_TEMPLATE_CACHE_VERSION }}
- name: Build template in docker container
if: steps.cache-export-template.outputs.cache-hit != 'true'
run: cd misc/export_templates && ./build.sh -t ${{ matrix.target }}
- name: Upload export template
uses: actions/upload-artifact@v2
with:
name: html5-gdnative-export-templates
path: misc/export_templates/godot/bin/webassembly_gdnative_${{matrix.target}}.zip
html5_export:
name: 'HTML5 Export'
needs: [ build_docker, build_native, export_template ]
needs: [ build_docker, build_native ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@ -217,23 +183,39 @@ jobs:
with:
name: libgodot-xterm-release
path: addons/godot_xterm/native/bin
- name: Install html5 export templates
uses: actions/download-artifact@v2
- name: Import assets
shell: bash
# The GodotXterm plugin will be disabled the first time we run the editor as resources that it depends
# (e.g. icons) will not have been imported yet so the plugin will fail to load. Without the plugin
# enabled resources imported by GodotXterm import plugins (e.g. .cast) will not be imported. Therefore,
# we need to re-enable the plugin by checking out project.godot and running the editor again.
run: godot --editor .github/import_assets.tscn && git checkout project.godot && godot --editor .github/import_assets.tscn
- name: Export HTML5
run: godot --no-window --export HTML5
- name: NPM cache
uses: c-hive/gha-npm-cache@v1
with:
name: html5-gdnative-export-templates
path: misc/export_templates/godot/bin
- name: Create export directory
run: mkdir -p docs/demo
- name: Export html5
run: godot --export HTML5
# FIXME: HTML5 Exports not properly exporting .cast files.
# So skip upload for now.
#- name: Upload export
# uses: actions/upload-artifact@v2
# with:
# name: html5-demo
# path: docs/demo
directory: test/html5
- name: Smoke test HTML5 export
shell: bash
working-directory: test/html5
run: |
npm ci
npx serve ../../docs/demo -p 3000 &
npx cypress run
- name: Upload cypress artifacts (on failure)
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: cypress-artifacts
path: |-
test/html5/cypress/screenshots
test/html5/cypress/videos
- name: Upload export
uses: actions/upload-artifact@v2
with:
name: html5-demo
path: docs/demo
test:
name: 'Test'

3
.gitmodules vendored
View file

@ -7,6 +7,3 @@
[submodule "addons/godot_xterm/native/thirdparty/libtsm"]
path = addons/godot_xterm/native/thirdparty/libtsm
url = https://github.com/lihop/libtsm
[submodule "misc/export_templates/godot"]
path = misc/export_templates/godot
url = https://github.com/godotengine/godot

View file

@ -82,5 +82,5 @@ scons target=$target macos_arch=$(uname -m) disable_pty=$disable_pty -j$nproc
# Use Docker to build libgodot-xterm javascript.
if [ -x "$(command -v docker-compose)" ]; then
UID_GID="0:0" TARGET=$target docker-compose build javascript
UID_GID="$(id -u):$(id -g)" TARGET=$target docker-compose run javascript
UID_GID="$(id -u):$(id -g)" TARGET=$target docker-compose run --rm javascript
fi

View file

@ -1,6 +1,8 @@
services:
javascript:
build: ../../../misc/docker
build:
context: .
dockerfile: javascript.Dockerfile
user: ${UID_GID}
volumes:
- .:/src

View file

@ -1,4 +1,4 @@
# For convenient building of the library and gdnative export templates targeted at the javacript platform.
FROM emscripten/emsdk:3.1.5
FROM emscripten/emsdk:3.1.14
RUN apt-get update && apt-get install pkg-config python3 -y
RUN pip3 install scons

View file

@ -31,7 +31,7 @@ void Terminal::_populate_key_list() {
#define GLOBAL_CONSTANT(VAR) GlobalConstants::VAR
#else
#define GLOBAL_CONSTANT(VAR) get_constant(#VAR)
const godot_dictionary _constants = godot_get_global_constants();
const godot_dictionary _constants = godot::api->godot_get_global_constants();
const Dictionary *constants = (Dictionary *)&_constants;
auto get_constant = [constants](std::string name) -> int64_t {

View file

@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/lihop/godot-xterm/compare/v2.2.0...HEAD)
### Changed
- Custom export templates are no longer required when exporting to HTML5 from Godot v3.5.x.
## [v2.2.0](https://github.com/lihop/godot-xterm/compare/v2.1.1...v2.2.0) - 2022-08-26

View file

@ -91,7 +91,8 @@ Are you using GodotXterm in your project and want it listed here? Please [open a
## Supported Godot Versions
GodotXterm aims to support the current stable release of Godot, but may lag slightly.
Currently, Godot versions 3.5.x and 3.4.x are supported.
Currently, Godot versions 3.5.x and 3.4.x are supported, but custom export templates
are required for HTML5 exports from versions < 3.5.
Versions 3.3.x are no longer officially supported but *may* work if the GDNative libraries are
compiled using an older version of godot-cpp.

0
docs/demo/.gitkeep Normal file
View file

View file

@ -13,8 +13,8 @@ script_encryption_key=""
[preset.0.options]
custom_template/debug="./misc/export_templates/godot/bin/webassembly_gdnative_debug.zip"
custom_template/release="./misc/export_templates/godot/bin/webassembly_gdnative_release.zip"
custom_template/debug=""
custom_template/release=""
variant/export_type=2
vram_texture_compression/for_desktop=true
vram_texture_compression/for_mobile=false

View file

@ -1,41 +0,0 @@
set -e
# Parse args.
args=$@
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-t|--target)
target="$2"
shift
shift
;;
*)
echo "Usage: ./build.sh [-t|--target <release|debug>]";
exit 128
shift
;;
esac
done
# Set defaults.
target=${target:-debug}
# Get the absolute path to the directory this script is in.
EXPORT_TEMPLATES_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Update git submodules.
GODOT_DIR=${EXPORT_TEMPLATES_DIR}/godot
if [ -z "$(ls -A -- "$GODOT_DIR")" ]; then
cd ${EXPORT_TEMPLATES_DIR}
git submodule update --init --recursive -- $GODOT_DIR
fi
# Use Docker to build HTML5 GDNative export templates.
UID_GID="0:0" docker-compose build javascript
UID_GID="$(id -u):$(id -g)" docker-compose run -e TARGET=$target javascript
if [ "$target" == "debug" ]; then
mv godot/bin/godot.javascript.debug.gdnative.zip godot/bin/webassembly_gdnative_debug.zip
else
mv godot/bin/godot.javascript.opt.gdnative.zip godot/bin/webassembly_gdnative_release.zip
fi

View file

@ -1,12 +0,0 @@
services:
javascript:
build: ../docker
user: ${UID_GID}
volumes:
- ./godot:/src
command:
- /bin/bash
- -c
- |
cd src
scons platform=javascript tools=no gdnative_enabled=yes target=$${TARGET} -j$$(nproc)

@ -1 +0,0 @@
Subproject commit 419e713a29f20bd3351a54d1e6c4c5af7ef4b253

View file

@ -1 +0,0 @@
HTML5 GDNative export templates are not provided, this is just a convient script/docker-compose file for building them locally.

View file

@ -40,6 +40,6 @@ enabled=PoolStringArray( "res://addons/godot_xterm/plugin.cfg" )
[rendering]
quality/driver/driver_name="GLES2"
quality/filters/anisotropic_filter_level=16
quality/filters/msaa=4
environment/default_environment="res://default_env.tres"

0
test/html5/.gdignore Normal file
View file

4
test/html5/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
cypress-visual-screenshots/
cypress/screenshots/
cypress/videos/
node_modules/

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,10 @@
const { defineConfig } = require("cypress");
const getCompareSnapshotsPlugin = require('cypress-image-diff-js/dist/plugin');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
getCompareSnapshotsPlugin(on, config);
},
},
});

View file

@ -0,0 +1,21 @@
Cypress.on('window:before:load', win => {
cy.spy(win.console, 'error')
cy.spy(win.console, 'warn')
cy.spy(win.console, 'log')
})
describe('GodotXterm HTML5 export', () => {
it('Loads and runs without error', () => {
cy.visit('http://localhost:3000')
cy.compareSnapshot('menu', 0.9, {
limit: 100, delay: 200, timeout: 20000,
})
cy.get('body').type('{downArrow}{enter}')
cy.get('body').type('window.console.log("It works!"){enter}')
cy.window().then(win => {
cy.expect(win.console.error).to.have.callCount(0)
cy.expect(win.console.warn).to.have.callCount(0)
cy.expect(win.console.log).to.be.calledWith("It works!")
})
})
})

View file

@ -0,0 +1,2 @@
import compareSnapshotCommand from 'cypress-image-diff-js/dist/command';
compareSnapshotCommand();

View file

@ -0,0 +1 @@
import './commands'

4764
test/html5/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

11
test/html5/package.json Normal file
View file

@ -0,0 +1,11 @@
{
"scripts": {
"start": "npx serve ../../docs/demo",
"test": "npx cypress run"
},
"devDependencies": {
"cypress": "^10.4.0",
"cypress-image-diff-js": "^1.21.1",
"serve": "^14.0.1"
}
}

14
test/html5/shell.nix Normal file
View file

@ -0,0 +1,14 @@
let
pkgs = import <nixpkgs> {};
in pkgs.mkShell {
buildInputs = with pkgs; [
cypress
nodejs-16_x
xsel
];
shellHook = ''
export CYPRESS_INSTALL_BINARY=0
export CYPRESS_RUN_BINARY=${pkgs.cypress}/bin/Cypress
'';
}