Skip to content

Commit

Permalink
Merge branch 'v3.8.6' into refactor-2d-assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Dec 18, 2024
2 parents 5c4920c + 0738856 commit 6ba6723
Show file tree
Hide file tree
Showing 707 changed files with 32,030 additions and 21,564 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build-wasm-libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build wasm/asmjs libraryies

on:
workflow_dispatch:
inputs:
environment:
description: "Select a library"
required: true
default: "Spine"
type: choice
options:
- Spine

jobs:
build_spine_wasm_asmjs:
name: "Build spine wasm/asmjs libs"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup emsdk
uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846
with:
version: 3.1.41
actions-cache-folder: 'emsdk-cache-3.1.41'

- name: Verify
run: |
which emcc
emcc -v
- name: Install ninja
run: |
if ! command -v ninja &> /dev/null; then
echo "Ninja not found, installing..."
# sudo apt update
sudo apt install ninja-build
else
echo "Ninja is already installed."
fi
which ninja
- name: Apply emscripten patches
run: |
echo "--------------------------------- Save bind.cpp ---------------------------------"
cp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak
echo "--------------------------------- Apply embind bind.cpp patches ---------------------------------"
cp -f .github/workflows/emscripten-patches/embind/bind.cpp $EMSDK/upstream/emscripten/system/lib/embind/
echo "--------------------------------- Apply patches DONE! ---------------------------------"
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
- name: Build Spine WASM
run: |
cd ./native/cocos/editor-support/spine-wasm
mkdir build-wasm
cd build-wasm
emcmake cmake .. -GNinja
ninja
ls -l
- name: Build Spine ASMJS
run: |
cd ./native/cocos/editor-support/spine-wasm
sed -i 's/set(BUILD_WASM 1)/set(BUILD_WASM 0)/g' CMakeLists.txt
mkdir build-asmjs
cd build-asmjs
emcmake cmake .. -GNinja
ninja
ls -l
- name: Copy files to dist directory
run: |
mkdir dist
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.wasm ./dist/
cp ./native/cocos/editor-support/spine-wasm/build-wasm/spine.js ./dist/spine.wasm.js
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js.mem ./dist/
cp ./native/cocos/editor-support/spine-wasm/build-asmjs/spine.js ./dist/spine.asm.js
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: spine-emscripten
path: dist

- name: Restore patches
run: |
echo "-------------------------- Restore patches ---------------------------------"
rm $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
mv $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp.bak $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
echo "-------------------------- Restore patches DONE! ---------------------------------"
cat $EMSDK/upstream/emscripten/system/lib/embind/bind.cpp
205 changes: 205 additions & 0 deletions .github/workflows/emscripten-patches/embind/bind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Copyright 2012 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <emscripten/bind.h>
#ifdef USE_CXA_DEMANGLE
#include <../lib/libcxxabi/include/cxxabi.h>
#endif
#include <algorithm>
#include <climits>
#include <emscripten/emscripten.h>
#include <emscripten/wire.h>
#include <limits>
#include <list>
#include <typeinfo>
#include <vector>

using namespace emscripten;
using namespace internal;

static char* pointerToHexString(const void* ptr) {
static const char hexDigits[] = "0123456789abcdef";
uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
char str[20] = "0x"; // Includes the "0x" prefix
int index = 2;
bool leadingZero = true; // Used to skip leading zeros

// Convert the address to a hexadecimal string
for (int i = (sizeof(address) * 2) - 1; i >= 0; --i) {
char hexChar = hexDigits[(address >> (i * 4)) & 0xF];
if (hexChar != '0' || !leadingZero || i == 0) { // Ensures at least one zero in the final character
str[index++] = hexChar;
leadingZero = false;
}
}
str[index] = '\0';

return strdup(str);
}

extern "C" {
const char* EMSCRIPTEN_KEEPALIVE __getTypeName(const std::type_info* ti) {
if (has_unbound_type_names) {
#ifdef USE_CXA_DEMANGLE
int stat;
char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
if (stat == 0 && demangled) {
return demangled;
}

switch (stat) {
case -1:
return strdup("<allocation failure>");
case -2:
return strdup("<invalid C++ symbol>");
case -3:
return strdup("<invalid argument>");
default:
return strdup("<unknown error>");
}
#else
return strdup(ti->name());
#endif
} else {
//cjh char str[80];
// sprintf(str, "%p", reinterpret_cast<const void*>(ti));
// return strdup(str);
return pointerToHexString(reinterpret_cast<const void*>(ti));
}
}

static InitFunc* init_funcs = nullptr;

EMSCRIPTEN_KEEPALIVE void _embind_initialize_bindings() {
for (auto* f = init_funcs; f; f = f->next) {
f->init_func();
}
}

void _embind_register_bindings(InitFunc* f) {
f->next = init_funcs;
init_funcs = f;
}

}

namespace {
template <typename T> static void register_integer(const char* name) {
using namespace internal;
_embind_register_integer(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
std::numeric_limits<T>::max());
}

template <typename T> static void register_bigint(const char* name) {
using namespace internal;
_embind_register_bigint(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(),
std::numeric_limits<T>::max());
}

template <typename T> static void register_float(const char* name) {
using namespace internal;
_embind_register_float(TypeID<T>::get(), name, sizeof(T));
}

// matches typeMapping in embind.js
enum TypedArrayIndex {
Int8Array,
Uint8Array,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
// Only available if WASM_BIGINT
Int64Array,
Uint64Array,
};

template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
static_assert(internal::typeSupportsMemoryView<T>(), "type does not map to a typed array");
return std::is_floating_point<T>::value
? (sizeof(T) == 4 ? Float32Array : Float64Array)
: (sizeof(T) == 1
? (std::is_signed<T>::value ? Int8Array : Uint8Array)
: (sizeof(T) == 2 ? (std::is_signed<T>::value ? Int16Array : Uint16Array)
: (sizeof(T) == 4 ? (std::is_signed<T>::value ? Int32Array : Uint32Array)
: (std::is_signed<T>::value ? Int64Array : Uint64Array))));
}

template <typename T> static void register_memory_view(const char* name) {
using namespace internal;
_embind_register_memory_view(TypeID<memory_view<T>>::get(), getTypedArrayIndex<T>(), name);
}
} // namespace

EMSCRIPTEN_BINDINGS(builtin) {
using namespace emscripten::internal;

_embind_register_void(TypeID<void>::get(), "void");

_embind_register_bool(TypeID<bool>::get(), "bool", sizeof(bool), true, false);

register_integer<char>("char");
register_integer<signed char>("signed char");
register_integer<unsigned char>("unsigned char");
register_integer<signed short>("short");
register_integer<unsigned short>("unsigned short");
register_integer<signed int>("int");
register_integer<unsigned int>("unsigned int");
#if __wasm64__
register_bigint<signed long>("long");
register_bigint<unsigned long>("unsigned long");
#else
register_integer<signed long>("long");
register_integer<unsigned long>("unsigned long");
#endif

register_bigint<int64_t>("int64_t");
register_bigint<uint64_t>("uint64_t");

register_float<float>("float");
register_float<double>("double");

/*cjh
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
_embind_register_std_string(
TypeID<std::basic_string<unsigned char>>::get(), "std::basic_string<unsigned char>");
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
_embind_register_std_wstring(TypeID<std::u16string>::get(), sizeof(char16_t), "std::u16string");
_embind_register_std_wstring(TypeID<std::u32string>::get(), sizeof(char32_t), "std::u32string");
*/
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
/*cjh
// Some of these types are aliases for each other. Luckily,
// embind.js's _embind_register_memory_view ignores duplicate
// registrations rather than asserting, so the first
// register_memory_view call for a particular type will take
// precedence.
register_memory_view<char>("emscripten::memory_view<char>");
register_memory_view<signed char>("emscripten::memory_view<signed char>");
register_memory_view<unsigned char>("emscripten::memory_view<unsigned char>");
register_memory_view<short>("emscripten::memory_view<short>");
register_memory_view<unsigned short>("emscripten::memory_view<unsigned short>");
register_memory_view<int>("emscripten::memory_view<int>");
register_memory_view<unsigned int>("emscripten::memory_view<unsigned int>");
register_memory_view<long>("emscripten::memory_view<long>");
register_memory_view<unsigned long>("emscripten::memory_view<unsigned long>");
register_memory_view<int8_t>("emscripten::memory_view<int8_t>");
register_memory_view<uint8_t>("emscripten::memory_view<uint8_t>");
register_memory_view<int16_t>("emscripten::memory_view<int16_t>");
register_memory_view<uint16_t>("emscripten::memory_view<uint16_t>");
register_memory_view<int32_t>("emscripten::memory_view<int32_t>");
register_memory_view<uint32_t>("emscripten::memory_view<uint32_t>");
register_memory_view<int64_t>("emscripten::memory_view<int64_t>");
register_memory_view<uint64_t>("emscripten::memory_view<uint64_t>");
register_memory_view<float>("emscripten::memory_view<float>");
register_memory_view<double>("emscripten::memory_view<double>");
*/
}
2 changes: 1 addition & 1 deletion .github/workflows/generate-emsdk-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: dumganhar/setup-emsdk@997d2cde2deabda085a11f98e86e842915b0e846
with:
version: ${{ github.event.inputs.emsdk_version }}
actions-cache-folder: 'emsdk-cache'
actions-cache-folder: 'emsdk-cache-${{ github.event.inputs.emsdk_version }}'

- name: Verify
run: |
Expand Down
47 changes: 6 additions & 41 deletions .github/workflows/generate-oh-sdk-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@ name: <Native> Generate OH SDK Cache

on:
workflow_dispatch:
inputs:
oh_sdk_version:
description: 'Openharmony SDK version'
type: string
default: '9'
required: true

jobs:
generate_oh_sdk_cache:
name: "Generate OH SDK cache"
runs-on: ubuntu-latest
steps:
- uses: actions/setup-java@v4
id: setup-jdk
with:
distribution: 'zulu'
java-version: '17'

- name: Get oh sdk cache directory path
id: oh-sdk-cache-dir-path
run: |
Expand All @@ -34,47 +22,24 @@ jobs:
id: cache-oh-sdk
uses: actions/cache@v4
env:
cache-name: cache-oh-sdk-${{ github.event.inputs.oh_sdk_version }}
cache-name: cache-oh-sdk-12
with:
path: ${{ steps.oh-sdk-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-build-${{ env.cache-name }}

- name: Add package.json
run: |
echo "{}" > package.json
echo "{\"name\": \"tests\",\"lockfileVersion\": 3,\"requires\": true,\"packages\": {}}" > package-lock.json
- uses: actions/setup-node@v4
with:
node-version: 14
cache: 'npm'

- if: ${{ steps.cache-oh-sdk.outputs.cache-hit != 'true' }}
name: No Cache found, install oh sdk
continue-on-error: false
run: |
if [ ! -d "$HOME/openharmony" ]; then
mkdir -p $HOME/openharmony
echo "Download commandline-tools-linux.zip ..."
curl -o commandline-tools-linux.zip "https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_package_901_9/b1/v3/E6zhv5UFQ2-inIwNJhTN6Q/commandline-tools-linux-2.0.0.2.zip?HW-CC-KV=V1&HW-CC-Date=20230621T074401Z&HW-CC-Expire=315360000&HW-CC-Sign=621224257B02079B1E76C0A56FDF21483400B1E3556213F88DC79BC9BE7D595D"
wget -q https://github.com/dumganhar/oh-sdk-for-ci/releases/download/api-12/commandline-tools-linux-x64-5.0.3.906.zip.001
wget -q https://github.com/dumganhar/oh-sdk-for-ci/releases/download/api-12/commandline-tools-linux-x64-5.0.3.906.zip.002
echo "Unzip commandline-tools-linux.zip ..."
unzip commandline-tools-linux.zip -d $HOME/openharmony > /dev/null
7z x commandline-tools-linux-x64-5.0.3.906.zip.001 -o$HOME/openharmony > /dev/null
cd $HOME/openharmony
ls -l
cd command-line-tools
echo "=============== PATCHING sdkmanager/bin/sdkmgr file ==============="
sed -i "[email protected][email protected]=UTF-8 -Duser.country=CN@g" ./sdkmanager/bin/sdkmgr
cd bin
./sdkmgr list
echo "=============== INSTALL HOS toolchains:${{ github.event.inputs.oh_sdk_version }} ==============="
./sdkmgr install toolchains:${{ github.event.inputs.oh_sdk_version }} --accept-license > /dev/null
echo "=============== INSTALL OH SDK ets:${{ github.event.inputs.oh_sdk_version }} ==============="
./sdkmgr install OpenHarmony/ets:${{ github.event.inputs.oh_sdk_version }} --accept-license > /dev/null
echo "=============== INSTALL OH SDK js:${{ github.event.inputs.oh_sdk_version }} ==============="
./sdkmgr install OpenHarmony/js:${{ github.event.inputs.oh_sdk_version }} --accept-license > /dev/null
echo "=============== INSTALL OH SDK native:${{ github.event.inputs.oh_sdk_version }} ==============="
./sdkmgr install OpenHarmony/native:${{ github.event.inputs.oh_sdk_version }} --accept-license > /dev/null
echo "=============== INSTALL OH SDK toolchains:${{ github.event.inputs.oh_sdk_version }} ==============="
./sdkmgr install OpenHarmony/toolchains:${{ github.event.inputs.oh_sdk_version }} --accept-license > /dev/null
echo "=============== INSTALL OH SDK DONE ==============="
./sdkmgr list
cd commandline-tools-linux-x64-5.0.3.906
ls -l
fi
Loading

0 comments on commit 6ba6723

Please sign in to comment.