* Refactor non working JS tests with feature-based checks.

* Add Emscripten testing to CI.

* Compile Emscripten tests as C++14.

* Update Emscripten generated files naming scheme.

* Disable Emscripten property generation.

* Emscripten testing fixes.

* Add CMake to CI.
This commit is contained in:
João Matos 2024-09-04 10:48:15 +01:00 коммит произвёл GitHub
Родитель 7871125e9c
Коммит c645b047b3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 70 добавлений и 23 удалений

17
.github/workflows/main.yml поставляемый
Просмотреть файл

@ -22,12 +22,24 @@ jobs:
PLATFORM: ${{ matrix.config.platform }}
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
EMSCRIPTEN_VERSION: 3.1.65
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache-${{ runner.os }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.30.x'
- name: Install nbgv
if: startsWith(matrix.config.os, 'macos')
run: |
@ -69,6 +81,11 @@ jobs:
run: tests/quickjs/test.sh
if: runner.os != 'Windows'
- name: Test (Emscripten)
shell: bash
run: tests/emscripten/test.sh
if: runner.os != 'Windows'
- name: Pack
shell: bash
run: build/build.sh prepack -platform $PLATFORM

Просмотреть файл

@ -13,6 +13,16 @@ namespace CppSharp.Generators.Emscripten
{
public EmscriptenGenerator(BindingContext context) : base(context)
{
if (context.Options.GenerateName == null)
{
context.Options.GenerateName = (unit) =>
{
if (unit.FileName == "premake5.lua")
return unit.FileNameWithoutExtension;
else
return $"{unit.Module.LibraryName}_embind_{unit.FileNameWithoutExtension}";
};
}
}
public override List<GeneratorOutput> Generate()
@ -59,7 +69,7 @@ namespace CppSharp.Generators.Emscripten
{
TranslationUnit = new TranslationUnit
{
FilePath = $"{module.LibraryName}_embind_module.cpp",
FilePath = $"__Module.cpp",
Module = module
},
Outputs = new List<CodeGenerator> { moduleGen }

Просмотреть файл

@ -117,6 +117,11 @@ namespace CppSharp.Generators.Emscripten
}
}
public override bool VisitProperty(Property property)
{
return true;
}
public override bool VisitMethodDecl(Method method)
{
Indent();

Просмотреть файл

@ -4,6 +4,7 @@ workspace "emscripten"
location "gen"
symbols "On"
optimize "Off"
cppdialect "C++14"
project "test"
kind "SharedLib"

Просмотреть файл

@ -1,11 +1,14 @@
import wasmModule from "./gen/bin/debug/libtest.mjs";
import { eq, ascii, floateq } from "./utils.mjs"
const test = await wasmModule({
onRuntimeInitialized() {
const test = await wasmModule({ onRuntimeInitialized() {} });
}
});
const features = {
// https://github.com/WebAssembly/proposals/issues/7
// https://github.com/emscripten-core/emscripten/issues/11140
supportsInt64: false,
supportsNull: false,
}
function builtins() {
eq(test.ReturnsVoid(), undefined)
@ -13,8 +16,10 @@ function builtins() {
eq(test.ReturnsBool(), true)
eq(test.PassAndReturnsBool(false), false)
eq(test.ReturnsNullptr(), null)
eq(test.PassAndReturnsNullptr(null), null)
if (features.supportsNull) {
eq(test.ReturnsNullptr(), null)
eq(test.PassAndReturnsNullptr(null), null)
}
eq(test.ReturnsChar(), ascii('a'));
eq(test.ReturnsSChar(), ascii('a'));
@ -41,11 +46,10 @@ function builtins() {
eq(test.ReturnsInt32(), -5);
eq(test.ReturnsUInt32(), 5);
// TODO:
// https://github.com/WebAssembly/proposals/issues/7
// https://github.com/emscripten-core/emscripten/issues/11140
//eq(test.ReturnsInt64(), -5n);
//eq(test.ReturnsUInt64(), 5n);
if (features.supportsInt64) {
eq(test.ReturnsInt64(), -5n);
eq(test.ReturnsUInt64(), 5n);
}
const int8 = { min: -(2 ** 7), max: (2 ** 7) - 1 };
eq(test.PassAndReturnsInt8(int8.min), int8.min);
@ -71,13 +75,15 @@ function builtins() {
eq(test.PassAndReturnsUInt32(uint32.min), uint32.min);
eq(test.PassAndReturnsUInt32(uint32.max), uint32.max);
//const int64 = { min: BigInt(2 ** 63) * -1n, max: BigInt(2 ** 63) - 1n };
//eq(test.PassAndReturnsInt64(int64.min), int64.min);
//eq(test.PassAndReturnsInt64(int64.max), int64.max);
if (features.supportsInt64) {
const int64 = { min: BigInt(2 ** 63) * -1n, max: BigInt(2 ** 63) - 1n };
eq(test.PassAndReturnsInt64(int64.min), int64.min);
eq(test.PassAndReturnsInt64(int64.max), int64.max)
//const uint64 = { min: BigInt(0), max: BigInt(2 ** 64) - 1n };
//eq(test.PassAndReturnsUInt64(uint64.min), uint64.min);
//eq(test.PassAndReturnsUInt64(uint64.max), uint64.max);
const uint64 = { min: BigInt(0), max: BigInt(2 ** 64) - 1n };
eq(test.PassAndReturnsUInt64(uint64.min), uint64.min);
eq(test.PassAndReturnsUInt64(uint64.max), uint64.max);
}
}
function enums() {
@ -94,7 +100,7 @@ function classes() {
eq(typeof (c), "object")
eq(c.ReturnsVoid(), undefined)
eq(c.ReturnsInt(), 0)
eq(c.PassAndReturnsClassPtr(null), null)
//eq(c.PassAndReturnsClassPtr(null), null)
var c1 = new test.ClassWithSingleInheritance();
eq(c1.__proto__.constructor.name, 'ClassWithSingleInheritance')
@ -105,10 +111,9 @@ function classes() {
var classWithField = new test.ClassWithField();
eq(classWithField.ReturnsField(), 10);
eq(classWithField.Field, 10);
//eq(classWithField.Field, 10);
}
builtins();
enums();
classes();

Просмотреть файл

@ -5,7 +5,16 @@ rootdir="$dir/../.."
dotnet_configuration=Release
configuration=debug
platform=x64
jsinterp=node
jsinterp=$(which node)
for arg in "$@"; do
case $arg in
--with-node=*)
jsinterp="${arg#*=}"
shift
;;
esac
done
if [ "$CI" = "true" ]; then
red=""