Repository navigation
149 lines (134 loc) · 5.47 KB
/
Copy pathwasm.yml
File metadata and controls
149 lines (134 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: wasm
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# gh-pages is a single branch, so let one deployment finish before the next
# starts rather than having two pushes race each other for it.
concurrency:
group: gh-pages
cancel-in-progress: false
env:
# Each Qt minor release targets one specific Emscripten version, and mixing
# them does not work: see "Qt for WebAssembly" in the Qt documentation.
QT_VERSION: 6.10.2
EMSDK_VERSION: 4.0.7
jobs:
build:
name: wasm
runs-on: ubuntu-24.04
permissions:
contents: write # to push the built site to gh-pages
steps:
- uses: actions/checkout@v7
# Cross-compiling needs two Qt installations: the wasm one to link
# against, and a host one of the same version for moc, uic and rcc, which
# have to run on the build machine.
- name: Install Qt (host tools)
uses: jurplel/install-qt-action@v4
with:
version: ${{ env.QT_VERSION }}
host: linux
target: desktop
arch: linux_gcc_64
cache: true
dir: ${{ runner.temp }}/qt-host
# Take note of where that landed before the wasm install overwrites
# QT_ROOT_DIR with its own: QT_HOST_PATH is how the wasm build is told
# which moc, uic and rcc to run, and those have to be the host ones.
- name: Remember the host Qt
run: echo "QT_HOST_PATH=$QT_ROOT_DIR" >> "$GITHUB_ENV"
- name: Install Qt (WebAssembly)
uses: jurplel/install-qt-action@v4
with:
version: ${{ env.QT_VERSION }}
host: all_os
target: wasm
arch: wasm_singlethread
cache: true
dir: ${{ runner.temp }}/qt-wasm
- name: Cache the Emscripten SDK
id: emsdk-cache
uses: actions/cache@v6
with:
path: emsdk
key: emsdk-${{ env.EMSDK_VERSION }}-${{ runner.os }}
- name: Install the Emscripten SDK
if: steps.emsdk-cache.outputs.cache-hit != 'true'
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git
./emsdk/emsdk install "$EMSDK_VERSION"
# Also on a cache hit: activate is what writes the config the compiler
# reads, and it records absolute paths.
- name: Activate the Emscripten SDK
run: ./emsdk/emsdk activate "$EMSDK_VERSION"
- name: Build and install libqgcodeeditor
run: |
source ./emsdk/emsdk_env.sh
# No .deb to install from here, so build the editor widget into a
# staging prefix. Static, so it ends up inside the .wasm rather than
# beside it.
git clone --depth 1 https://github.com/QGCoder/libqgcodeeditor
emcmake cmake -S libqgcodeeditor -B libqgcodeeditor/build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake" \
-DQT_HOST_PATH="$QT_HOST_PATH" \
-DCMAKE_INSTALL_PREFIX="$PWD/qgcodeeditor-prefix" \
-DBUILD_STATIC_LIB=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_DESIGNER_PLUGIN=OFF
cmake --build libqgcodeeditor/build -j"$(nproc)"
cmake --install libqgcodeeditor/build
- name: Build qgcoder
run: |
source ./emsdk/emsdk_env.sh
# CMAKE_FIND_ROOT_PATH, not CMAKE_PREFIX_PATH: the Emscripten toolchain
# sets CMAKE_FIND_ROOT_PATH_MODE_LIBRARY to ONLY, so find_library()
# looks under the find roots and nowhere else - a prefix path alone is
# searched for packages but not for the library itself.
emcmake cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake" \
-DQT_HOST_PATH="$QT_HOST_PATH" \
-DCMAKE_FIND_ROOT_PATH="$PWD/qgcodeeditor-prefix"
cmake --build build -j"$(nproc)"
- name: Assemble the site
run: |
cmake --install build --prefix "$PWD/dist"
mkdir -p site
cp dist/bin/qgcoder.html dist/bin/qgcoder.js \
dist/bin/qgcoder.wasm dist/bin/qtloader.js dist/bin/qtlogo.svg site/
# GitHub Pages serves index.html for a directory, and the Qt shell page
# refers to its own files by relative name, so a copy under both names
# works either way round.
cp site/qgcoder.html site/index.html
# without this, Pages runs the directory through Jekyll, which drops
# files whose names begin with an underscore
touch site/.nojekyll
ls -lh site
- uses: actions/upload-artifact@v7
with:
name: wasm
if-no-files-found: error
path: site
# Only what lands on main gets published; a pull request is built to check
# that it still compiles and no further.
- name: Publish to gh-pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
GIT_AUTHOR_NAME: Github Actions
GIT_AUTHOR_EMAIL: jakob.flierl@gmail.com
GIT_COMMITTER_NAME: Github Actions
GIT_COMMITTER_EMAIL: jakob.flierl@gmail.com
run: |
# A fresh orphan commit every time: the site is a build artifact, and
# keeping a history of one would mean carrying every .wasm ever built -
# about 15 MB apiece - in the repository for good.
cd site
git init -q -b gh-pages
git add -A
git commit -q -m "Deploy ${GITHUB_SHA} to gh-pages"
git push -q --force \
"https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" \
gh-pages