-
Notifications
You must be signed in to change notification settings - Fork 10
Browser changes #39
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
Open
thomasballinger
wants to merge
5
commits into
master
Choose a base branch
from
endless-web
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Browser changes #39
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d8dea4
Emscripten build support
thomasballinger 8678fa5
Single-threaded mode and disable music for Emscripten
thomasballinger d0c676e
Web frontend: HTML shell, JavaScript, and assets
thomasballinger 4c27b67
CI: Add browser build workflow
thomasballinger a5f7246
Fix asset hashing so deploys can't ship a stale wasm
thomasballinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ indent_size = 1 | |
|
|
||
| # Credits file | ||
| [credits.txt] | ||
| charset = UTF-8 | ||
| indent_style = space | ||
| indent_size = 2 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| name: browser | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| types: | ||
| - synchronize | ||
| - opened | ||
|
|
||
| env: | ||
| EM_VERSION: 6.0.6 | ||
| EM_CACHE_FOLDER: 'emsdk-cache' | ||
|
|
||
| jobs: | ||
| build: | ||
| environment: aws-deploy | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: ccache | ||
| uses: hendrikmuhs/ccache-action@v1 | ||
| with: | ||
| key: ${{ runner.os }}-${{ env.EM_VERSION }} | ||
|
|
||
| - name: Cache emscripten | ||
| id: cache-emscripten | ||
| uses: actions/cache@v4 | ||
| env: | ||
| cache-name: cache-emscripten | ||
| with: | ||
| path: emsdk | ||
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.EM_VERSION }} | ||
|
|
||
| - name: install emsdk | ||
| if: steps.cache-emscripten.outputs.cache-hit != 'true' | ||
| run: | | ||
| git clone https://github.com/emscripten-core/emsdk.git | ||
| ./emsdk/emsdk install ${{ env.EM_VERSION }} | ||
| ./emsdk/emsdk activate ${{ env.EM_VERSION }} | ||
|
|
||
| - name: Cache libjpegturbo | ||
| id: cache-libjpegturbo | ||
| uses: actions/cache@v4 | ||
| env: | ||
| cache-name: cache-libjpegturbo | ||
| with: | ||
| path: | | ||
| libjpeg-turbo-2.1.0/ | ||
| 2.1.0.tar.gz | ||
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.EM_VERSION }} | ||
|
|
||
| - name: Cache build directory | ||
| id: cache-build | ||
| uses: actions/cache@v4 | ||
| env: | ||
| cache-name: cache-build | ||
| with: | ||
| path: build | ||
| key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.EM_VERSION }} | ||
|
|
||
| - name: Configure AWS Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: us-east-1 | ||
|
|
||
| - name: Build | ||
| run: source emsdk/emsdk_env.sh; make output/index.html | ||
| - name: Deploy | ||
| if: ${{ github.ref == 'refs/heads/endless-web' && github.event_name == 'push' }} | ||
| run: source emsdk/emsdk_env.sh; make deploy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| EMSCRIPTEN_ENV := $(shell command -v emmake 2> /dev/null) | ||
| CXX := $(shell command -v ccache 2> /dev/null > /dev/null && echo ccache em++ || echo em++) | ||
|
|
||
| all: dev | ||
| clean: | ||
| rm -f endless-sky.js | ||
| rm -f endless-sky.data | ||
| rm -f endless-sky.wasm | ||
| rm -f dataversion.js | ||
| rm -rf output | ||
| rm -f endless-sky.wasm.map | ||
| rm -f lib/emcc/libendless-sky.a | ||
| rm -rf build/emcc | ||
| # favicon.ico and Ubuntu-Regular.ttf are downloaded, not built. Removing them in | ||
| # 'clean' means any local serve after a clean silently loses the font until | ||
| # something re-fetches them, so they are only removed by 'distclean'. | ||
| distclean: clean | ||
| rm -rf lib/emcc | ||
| rm -rf libjpeg-turbo-2.1.0 | ||
| rm -f favicon.ico | ||
| rm -f Ubuntu-Regular.ttf | ||
| 2.1.0.tar.gz: | ||
| wget -nv https://github.com/libjpeg-turbo/libjpeg-turbo/archive/refs/tags/2.1.0.tar.gz | ||
| libjpeg-turbo-2.1.0: 2.1.0.tar.gz | ||
| tar xzf 2.1.0.tar.gz | ||
| libjpeg-turbo-2.1.0/libturbojpeg.a: | libjpeg-turbo-2.1.0 | ||
| ifndef EMSCRIPTEN_ENV | ||
| $(error "emmake is not available, activate the emscripten env first") | ||
| endif | ||
| # ENABLE_SHARED=0: without it libjpeg-turbo also builds libjpeg.so, which '-l jpeg' | ||
| # prefers over the static archive. Since emscripten 6.0.0 disabled FAKE_DYLIBS by | ||
| # default that .so is a real dynamic library, which implies -sMAIN_MODULE=2 and | ||
| # fails the link with "relocation ... cannot be used against symbol; recompile with -fPIC". | ||
| cd libjpeg-turbo-2.1.0; emcmake cmake -G"Unix Makefiles" -DENABLE_SHARED=0 -DWITH_SIMD=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -Wno-dev | ||
| cd libjpeg-turbo-2.1.0; sed 's/SIZEOF_SIZE_T [0-9]*/SIZEOF_SIZE_T 4/' jconfigint.h > jconfigint.h.tmp && mv jconfigint.h.tmp jconfigint.h | ||
| cd libjpeg-turbo-2.1.0; emmake $(MAKE) | ||
| dev: endless-sky.js dataversion.js Ubuntu-Regular.ttf favicon.ico | ||
| emrun --serve_after_close --serve_after_exit --browser chrome --private_browsing endless-sky.html | ||
| Ubuntu-Regular.ttf: | ||
| curl -Ls 'https://github.com/google/fonts/blob/main/ufl/ubuntu/Ubuntu-Regular.ttf?raw=true' > Ubuntu-Regular.ttf | ||
| favicon.ico: | ||
| wget -nv https://endless-sky.github.io/favicon.ico | ||
|
|
||
| COMMON_FLAGS = -O3\ | ||
| -s USE_SDL=2\ | ||
| -s USE_LIBPNG=1\ | ||
| -s DISABLE_EXCEPTION_CATCHING=0 | ||
|
|
||
| CFLAGS = $(COMMON_FLAGS)\ | ||
| -s USE_ZLIB=1\ | ||
| -Duuid_generate_random=uuid_generate\ | ||
| -std=c++20\ | ||
| -Wall\ | ||
| -Werror\ | ||
| -Wold-style-cast\ | ||
| -DES_GLES\ | ||
| -gsource-map\ | ||
| -I libjpeg-turbo-2.1.0\ | ||
|
|
||
| LINK_FLAGS = $(COMMON_FLAGS)\ | ||
| -s USE_ZLIB=1\ | ||
| -L libjpeg-turbo-2.1.0\ | ||
| -l jpeg\ | ||
| -lopenal\ | ||
| -lidbfs.js\ | ||
| --source-map-base http://localhost:6931/\ | ||
| -s USE_WEBGL2=1\ | ||
| -s ASSERTIONS=2\ | ||
| -s GL_ASSERTIONS=1\ | ||
| -s ASYNCIFY\ | ||
| -s MIN_WEBGL_VERSION=2\ | ||
| -s MAX_WEBGL_VERSION=2\ | ||
| -s MAXIMUM_MEMORY=2147483648\ | ||
| -s INITIAL_MEMORY=1347289088\ | ||
| -s ALLOW_MEMORY_GROWTH=1\ | ||
| --preload-file data\ | ||
| --preload-file images\ | ||
| --preload-file sounds\ | ||
| --preload-file shaders\ | ||
| --preload-file credits.txt\ | ||
| --preload-file keys.txt\ | ||
| -s EXPORTED_RUNTIME_METHODS=['callMain']\ | ||
| --emrun | ||
|
|
||
| # Source files: all .cpp in source subdirs except test/, windows/, and excluded audio suppliers | ||
| # Also exclude ZipFile.cpp (no minizip in emscripten) | ||
| CPPS := $(filter-out source/ZipFile.cpp,$(shell ls source/*.cpp)) \ | ||
| $(shell ls source/text/*.cpp) \ | ||
| $(shell ls source/ship/*.cpp) \ | ||
| $(shell ls source/audio/*.cpp) \ | ||
| $(shell ls source/audio/player/*.cpp) \ | ||
| $(shell ls source/audio/supplier/AudioSupplier.cpp source/audio/supplier/WavSupplier.cpp source/audio/supplier/effect/Fade.cpp) \ | ||
| $(shell ls source/image/*.cpp) \ | ||
| $(shell ls source/shader/*.cpp) \ | ||
| $(shell ls source/comparators/*.cpp 2>/dev/null) \ | ||
| $(shell ls source/orders/*.cpp 2>/dev/null) \ | ||
| $(shell ls source/test/*.cpp 2>/dev/null) | ||
| CPPS_EXCEPT_MAIN := $(filter-out source/main.cpp,$(CPPS)) | ||
| TEMP := $(subst source/,build/emcc/,$(CPPS)) | ||
| OBJS := $(subst .cpp,.o,$(TEMP)) | ||
| TEMP := $(subst source/,build/emcc/,$(CPPS_EXCEPT_MAIN)) | ||
| OBJS_EXCEPT_MAIN := $(subst .cpp,.o,$(TEMP)) | ||
| HEADERS := $(shell find source -name '*.h' -o -name '*.hpp' | grep -v windows/) | ||
|
|
||
| BUILD_DIRS := build/emcc build/emcc/text build/emcc/ship build/emcc/audio \ | ||
| build/emcc/audio/player build/emcc/audio/supplier build/emcc/audio/supplier/effect \ | ||
| build/emcc/image build/emcc/shader build/emcc/comparators build/emcc/orders build/emcc/test | ||
|
|
||
| build/emcc/%.o: source/%.cpp $(HEADERS) libjpeg-turbo-2.1.0/libturbojpeg.a | ||
| @mkdir -p $(BUILD_DIRS) | ||
| $(CXX) $(CFLAGS) -c $< -o $@ | ||
|
|
||
| lib/emcc/libendless-sky.a: $(OBJS_EXCEPT_MAIN) | ||
| @mkdir -p lib/emcc | ||
| emar rcs lib/emcc/libendless-sky.a $(OBJS_EXCEPT_MAIN) | ||
|
|
||
| endless-sky.js: Makefile libjpeg-turbo-2.1.0/libturbojpeg.a lib/emcc/libendless-sky.a build/emcc/main.o | ||
| ifndef EMSCRIPTEN_ENV | ||
| $(error "em++ is not available, activate the emscripten env first") | ||
| endif | ||
| em++ -o endless-sky.js $(LINK_FLAGS) build/emcc/main.o lib/emcc/libendless-sky.a | ||
|
|
||
| dataversion.js: endless-sky.js | ||
| ./hash-data.py endless-sky.data dataversion.js | ||
| output/index.html: endless-sky.js endless-sky.html favicon.ico Ubuntu-Regular.ttf dataversion.js js/cached-resource.js js/plugins.js js/save-games.js | ||
| rm -rf output | ||
| mkdir -p output | ||
| cp endless-sky.html to-be-modified-endless-sky.html | ||
| cp endless-sky.js to-be-modified-endless-sky.js | ||
| ./copy-to-hashed-location.py endless-sky.wasm endless-sky.data output/ | ||
| mkdir output/js | ||
| ./copy-to-hashed-location.py js/* output/ | ||
| ./copy-to-hashed-location.py dataversion.js output/ | ||
| ./copy-to-hashed-location.py loading.mp3 output/ | ||
| ./copy-to-hashed-location.py Ubuntu-Regular.ttf output/ | ||
| cp favicon.ico output/ | ||
| # Hash endless-sky.js only after its .wasm and .data references have been | ||
| # rewritten, so the filename reflects the bytes that actually ship. Hashing it | ||
| # beforehand meant two builds differing only in C++ produced an identical | ||
| # filename of identical length, so 'aws s3 sync --size-only' silently skipped | ||
| # uploading the newer one and the site kept loading the previous wasm. | ||
| mv endless-sky.js endless-sky.js.prehash | ||
| mv to-be-modified-endless-sky.js endless-sky.js | ||
| ./copy-to-hashed-location.py endless-sky.js output/ | ||
| mv endless-sky.js.prehash endless-sky.js | ||
| mv to-be-modified-endless-sky.html output/index.html | ||
| test: output/index.html | ||
| cd output; emrun --serve_after_close --serve_after_exit --browser chrome --private_browsing index.html | ||
| deploy: output/index.html | ||
| aws s3 sync --size-only --exclude index.html output s3://play-endless-sky.com/live --cache-control 'public, max-age=604800, immutable' | ||
| aws s3 sync --exclude '*' --include index.html output s3://play-endless-sky.com/live --cache-control 'max-age=0' | ||
| aws cloudfront create-invalidation --distribution-id E2TZUW922XPLEF --paths / /index.html | ||
| aws cloudfront create-invalidation --distribution-id E3D0Y4DMGSVPWC --paths / /index.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import shutil | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def copy_and_add_hash(target_directory, source, files_to_modify): | ||
| import hashlib | ||
| hash_md5 = hashlib.md5() | ||
| length = 0 | ||
| with open(source, "rb") as f: | ||
| for chunk in iter(lambda: f.read(4096), b""): | ||
| length += len(chunk) | ||
| hash_md5.update(chunk) | ||
| hash = hash_md5.hexdigest() | ||
| if '.' in os.path.basename(source): | ||
| base, extensions = os.path.basename(source).split('.', 1) | ||
| extensions = '.' + extensions | ||
| else: | ||
| base = source | ||
| extensions = '' | ||
| dest = base + '-' + hash + extensions | ||
| copy_dest = os.path.join(target, dest) | ||
| print(source, '->', dest) | ||
|
|
||
| total_count = 0 | ||
| for to_modify in files_to_modify: | ||
| with open(to_modify, "r+") as f: | ||
| data = f.read() | ||
| f.seek(0) | ||
| count = data.count(source) | ||
| if count: | ||
| print("replacing", count, "occurrence" + ('' if count == 1 else 's'), "of", source, 'in', to_modify) | ||
| output = data.replace(source, dest) | ||
| f.write(output) | ||
| f.truncate() | ||
| total_count += count | ||
| if total_count == 0: | ||
| raise ValueError(repr(files_to_modify) + " do not contain source '"+source+"' to modify!") | ||
|
|
||
| shutil.copy(source, copy_dest) | ||
|
|
||
| if __name__ == '__main__': | ||
| FILES_TO_MODIFY = [ | ||
| "to-be-modified-endless-sky.html", | ||
| "to-be-modified-endless-sky.js" | ||
| ] | ||
|
|
||
| import sys | ||
| target = sys.argv[-1] | ||
| if target[-1] == '/': | ||
| target = target[:-1] | ||
| sources = sys.argv[1:-1] | ||
| if not os.path.isdir(target): | ||
| raise ValueError("dest must be a directory") | ||
| # endless-sky.js is hashed last, after it has itself been rewritten and moved | ||
| # into place, so by then it is no longer available to be modified. Skip any | ||
| # file that has already been consumed, but require at least one to remain. | ||
| FILES_TO_MODIFY = [f for f in FILES_TO_MODIFY if os.path.exists(f)] | ||
| if not FILES_TO_MODIFY: | ||
| raise ValueError("none of the files to modify exist") | ||
| for source in sources: | ||
| copy_and_add_hash(target, source, FILES_TO_MODIFY) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.