Skip to content

Commit

Permalink
Fix the web demo on windows. (#58)
Browse files Browse the repository at this point in the history
* Fix the web demo on windows.

* Fix autotest.
  • Loading branch information
domchen authored Nov 30, 2023
1 parent 5fcc513 commit 1dc405b
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 143 deletions.
87 changes: 22 additions & 65 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
path: ios

android:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
Expand All @@ -99,18 +99,16 @@ jobs:
key: third-party-android-${{ hashFiles('DEPS') }}-${{ hashFiles('vendor.json') }}
restore-keys: third-party-android-

- uses: seanmiddleditch/gha-setup-ninja@master

- name: Run depsync
run: |
npm install depsync -g
depsync
shell: bash
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r19c
link-to-sdk: true
local-cache: true

- uses: actions/setup-java@v3
Expand All @@ -123,8 +121,6 @@ jobs:
run: |
cd android
./gradlew assembleRelease -Parm64-only
env:
NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
- name: Save Third-Party Cache
if: ${{ (github.event_name == 'push') && (steps.third-party-cache.outputs.cache-hit != 'true') }}
Expand All @@ -139,10 +135,10 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: android_build
path: android/app/build
path: android

web:
runs-on: macos-latest
runs-on: windows-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v3
Expand All @@ -154,34 +150,9 @@ jobs:
uses: actions/cache/restore@v3
with:
path: |
/usr/local/Cellar/ninja
/usr/local/Cellar/icu4c
/usr/local/bin/ninja
/usr/local/Cellar/yasm
/usr/local/bin/yasm
/usr/local/Cellar/emsdk
/usr/local/bin/em++
/usr/local/bin/em-config
/usr/local/bin/emar
/usr/local/bin/embuilder
/usr/local/bin/emcc
/usr/local/bin/emcmake
/usr/local/bin/emconfigure
/usr/local/bin/emdump
/usr/local/bin/emdwp
/usr/local/bin/emmake
/usr/local/bin/emnm
/usr/local/bin/emrun
/usr/local/bin/emprofile
/usr/local/bin/emscons
/usr/local/bin/emsize
/usr/local/bin/emstrip
/usr/local/bin/emsymbolizer
/usr/local/bin/emcc.py
/usr/local/bin/emcmake.py
/usr/local/bin/emar.py
web/emsdk
web/node_modules
key: tgfx-environment-web-20231129
key: tgfx-environment-web-20231130
restore-keys: tgfx-environment-web-

- name: Get Third-Party Cache
Expand All @@ -193,51 +164,37 @@ jobs:
key: third-party-web-${{ hashFiles('DEPS') }}-${{ hashFiles('vendor.json') }}
restore-keys: third-party-web-

- name: Install Build Tools
if: ${{ (steps.environment-cache.outputs.cache-hit != 'true') }}
run: |
cd web
npm install
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 3.1.20
./emsdk activate 3.1.20
shell: bash

- name: Run depsync
run: |
chmod +x sync_deps.sh
./sync_deps.sh
npm install depsync -g
depsync
shell: bash

- name: Build Web
run: |
cd web
npm install
emsdk/emsdk_env
npm run build
- name: Save Environment Cache
if: ${{ (github.event_name == 'push') && (steps.environment-cache.outputs.cache-hit != 'true') }}
uses: actions/cache/save@v3
with:
path: |
/usr/local/Cellar/ninja
/usr/local/Cellar/icu4c
/usr/local/bin/ninja
/usr/local/Cellar/yasm
/usr/local/bin/yasm
/usr/local/Cellar/emsdk
/usr/local/bin/em++
/usr/local/bin/em-config
/usr/local/bin/emar
/usr/local/bin/embuilder
/usr/local/bin/emcc
/usr/local/bin/emcmake
/usr/local/bin/emconfigure
/usr/local/bin/emdump
/usr/local/bin/emdwp
/usr/local/bin/emmake
/usr/local/bin/emnm
/usr/local/bin/emrun
/usr/local/bin/emprofile
/usr/local/bin/emscons
/usr/local/bin/emsize
/usr/local/bin/emstrip
/usr/local/bin/emsymbolizer
/usr/local/bin/emcc.py
/usr/local/bin/emcmake.py
/usr/local/bin/emar.py
web/emsdk
web/node_modules
key: tgfx-environment-web-20231129
key: tgfx-environment-web-20231130

- name: Save Third-Party Cache
if: ${{ (github.event_name == 'push') && (steps.third-party-cache.outputs.cache-hit != 'true') }}
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ elseif (NOT ANDROID)
option(TGFX_USE_WEBP_ENCODE "Enable embedded WEBP encoding support" ON)
endif ()

string(FIND ${CMAKE_COMMAND} "/CLion.app/" CLionPosition)

if ($ENV{CLION_IDE})
set(CLION_IDE ON)
else ()
set(CLION_IDE OFF)
endif ()
get_directory_property(HasParent PARENT_DIRECTORY)
if (MACOS AND CLionPosition GREATER -1 AND NOT HasParent)
if (MACOS AND CLION_IDE AND NOT HasParent)
# CLion project needs test targets.
option(TGFX_BUILD_TESTS "Build tgfx tests" ON)
endif ()
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"common": [
{
"url": "${PAG_GROUP}/vendor_tools.git",
"commit": "46eb9e91897055bc42e8b86b50cf8d7232f02dc4",
"commit": "2250e9dadc86680ce4fb1c763b58995768040037",
"dir": "third_party/vendor_tools"
},
{
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ necessary steps to configure your development environment.
### Android Demo

The android demo project requires the **Android NDK**. We recommend using the **19.2.5345600**
version, which has been fully tested with the tgfx library. You can download it from
[NDK Downloads](https://developer.android.com/ndk/downloads) or by Android Studio.
version, which has been fully tested with the tgfx library. If you open the project with Android
Studio, it will automatically download the NDK during Gradle synchronization. Alternatively, you
can download it from the [NDK Downloads](https://developer.android.com/ndk/downloads) page.

If you choose to manually download the Android NDK, please extract it to the default location.
On macOS, this would be:
Expand All @@ -131,8 +132,7 @@ On Windows, it would be:
C:\Users\yourname\AppData\Local\Android\Sdk\ndk\19.2.5345600
```

Alternatively, you can set one of
the following environment variables for tgfx to locate the NDK:
Alternatively, you can set one of the following environment variables for tgfx to locate the NDK:

```
["ANDROID_NDK_HOME", "ANDROID_NDK_ROOT", "ANDROID_NDK", "NDK_HOME", "NDK_ROOT", "NDK_PATH"]
Expand Down Expand Up @@ -209,10 +209,10 @@ At last, launch XCode and open the `mac/Hello2D.xcworkspace`. You'll be ready to
The web demo project requires the **Emscripten SDK**. You can download and install
it from the [official website](https://emscripten.org/). We recommend using the **3.1.20** version,
which has been fully tested with the tgfx library. If you are on macOS, you can also install it
using the following command:
using the following script:

```
brew install emscripten
web/script/install-emscripten.sh
```

To begin, navigate to the `web/` directory and execute the following command to install the
Expand Down
13 changes: 6 additions & 7 deletions drawers/src/SimpleText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ void SimpleText::onDraw(tgfx::Canvas* canvas, const drawers::AppHost* host) cons
auto oldMatrix = canvas->getMatrix();
canvas->concat(matrix);
tgfx::Paint paint = {};
paint.setColor({1.0f, 1.0f, 1.0f, 1.0f});
paint.setStyle(tgfx::PaintStyle::Stroke);
paint.setStrokeWidth(2 * scale);
canvas->drawSimpleText(text, 0, 0, font, paint);
paint.setStyle(tgfx::PaintStyle::Fill);
tgfx::Color cyan = {0.0f, 1.0f, 1.0f, 1.0f};
tgfx::Color magenta = {1.0f, 0.0f, 1.0f, 1.0f};
tgfx::Color yellow = {1.0f, 1.0f, 0.0f, 1.0f};
auto startPoint = tgfx::Point::Make(0.0f, 0.0f);
auto endPoint = tgfx::Point::Make(screenWidth, 0.0f);
auto shader =
tgfx::Shader::MakeLinearGradient(startPoint, endPoint, {cyan, magenta, yellow}, {});
auto shader = tgfx::Shader::MakeLinearGradient(startPoint, endPoint, {cyan, magenta, yellow}, {});
paint.setShader(shader);
canvas->drawSimpleText(text, 0, 0, font, paint);
paint.setShader(nullptr);
paint.setColor({1.0f, 1.0f, 1.0f, 1.0f});
paint.setStyle(tgfx::PaintStyle::Stroke);
paint.setStrokeWidth(scale);
canvas->drawSimpleText(text, 0, 0, font, paint);
canvas->setMatrix(oldMatrix);

std::string emojis = "🤡👻🐠🤩😃🤪🙈🙊🐒";
Expand Down
2 changes: 1 addition & 1 deletion test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"GridBackground": "2ae64df",
"ImageWithMipmap": "5a1fb11",
"ImageWithShadow": "5a1fb11",
"SimpleText": "2ae64df",
"SimpleText": "46b2963",
"SweepGradient": "5a1fb11"
},
"ImageReaderTest": {
Expand Down
4 changes: 2 additions & 2 deletions update_baseline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
echo $CMAKE_COMMAND

if [[ $1 == "1" ]]; then
$CMAKE_COMMAND -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -g -O0" -DTGFX_USE_SWIFTSHADER=ON -DTGFX_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ../
$CMAKE_COMMAND -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -g -O0" -DTGFX_USE_SWIFTSHADER=ON -DTGFX_BUILD_TESTS=ON -DTGFX_SKIP_BASELINE_CHECK=ON -DCMAKE_BUILD_TYPE=Debug ../
else
$CMAKE_COMMAND -DTGFX_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ../
$CMAKE_COMMAND -DTGFX_BUILD_TESTS=ON -DTGFX_SKIP_BASELINE_CHECK=ON -DCMAKE_BUILD_TYPE=Debug ../
fi

$CMAKE_COMMAND --build . --target UpdateBaseline -- -j 12
Expand Down
6 changes: 5 additions & 1 deletion web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ types
*.js.map
demo/*.js
demo/wasm
src/wasm
demo/build-hello2d
demo/.hello2d.wasm.md5
src/wasm
emsdk/

8 changes: 8 additions & 0 deletions web/demo/hello2d.hash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
src/
CMakeLists.txt
../../include/
../../src/
../../drawers/
../../CMakeLists.txt
../../vendor.json
../../DEPS
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"clean:tgfx": "rimraf lib/ types/",
"clean": "npm run clean:tgfx && rimraf demo/build demo/wasm demo/*.js demo/*.map demo/cmake-build-*",
"build:tgfx": "npm run clean:tgfx && tsc -p ./tsconfig.type.json && rollup -c ./script/rollup.tgfx.js",
"build": "node script/build.demo.js && npm run build:tgfx && rollup -c ./script/rollup.demo.js",
"build:debug": "node script/build.demo.js --debug && npm run build:tgfx && rollup -c ./script/rollup.demo.js",
"build": "node script/cmake.demo.js && npm run build:tgfx && rollup -c ./script/rollup.demo.js",
"build:debug": "node script/cmake.demo.js --debug && npm run build:tgfx && rollup -c ./script/rollup.demo.js",
"dev": "npm run build:tgfx && rollup -c ./script/rollup.dev.js -w",
"server": "http-server -p 8081 ../ -g -c-1 --cors -o web/demo"
},
Expand Down
56 changes: 0 additions & 56 deletions web/script/build.demo.js

This file was deleted.

12 changes: 12 additions & 0 deletions web/script/cmake.demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node
process.chdir(__dirname);

process.argv.push("-s");
process.argv.push("../demo");
process.argv.push("-o");
process.argv.push("../demo");
process.argv.push("-p");
process.argv.push("web");
process.argv.push("hello2d");
require("../../build_tgfx");

0 comments on commit 1dc405b

Please sign in to comment.