Starting to work on tests for ffi

This commit is contained in:
Luigi Rosso
2022-10-25 12:15:56 -07:00
parent 44f0f39254
commit 8c0db243bd
6 changed files with 178 additions and 57 deletions

32
.lua-format Normal file
View File

@ -0,0 +1,32 @@
column_limit: 80
indent_width: 4
use_tab: false
tab_width: 4
continuation_indent_width: 4
spaces_before_call: 1
keep_simple_control_block_one_line: true
keep_simple_function_one_line: true
align_args: true
break_after_functioncall_lp: false
break_before_functioncall_rp: false
spaces_inside_functioncall_parens: false
spaces_inside_functiondef_parens: false
align_parameter: true
chop_down_parameter: false
break_after_functiondef_lp: false
break_before_functiondef_rp: false
align_table_field: true
break_after_table_lb: true
break_before_table_rb: true
chop_down_table: true
chop_down_kv_table: true
table_sep: ","
column_table_limit: column_limit
extra_sep_at_table_end: false
spaces_inside_table_braces: false
break_after_operator: true
double_quote_to_single_quote: false
single_quote_to_double_quote: false
spaces_around_equals_in_field: true
line_breaks_after_function_body: 1
line_separator: input

View File

@ -6,20 +6,26 @@ sheenbidi = dependency.github('Tehreer/SheenBidi', 'v2.6')
workspace 'rive_text'
configurations {'debug', 'release'}
source = os.isdir('../../../packages/runtime') and '../../../packages/runtime' or '../macos/rive-cpp'
source = os.isdir('../../packages/runtime') and '../../packages/runtime' or 'macos/rive-cpp'
project 'rive_sheenbidi'
do
kind 'StaticLib'
language 'C'
toolset 'clang'
targetdir 'build/bin/%{cfg.buildcfg}/'
objdir 'build/obj/%{cfg.buildcfg}/'
targetdir 'shared_lib/build/bin/%{cfg.buildcfg}/'
objdir 'shared_lib/build/obj/%{cfg.buildcfg}/'
includedirs {
sheenbidi .. '/Headers'
}
filter {'options:wasm'}
do
targetdir 'wasm/build/bin/%{cfg.buildcfg}/'
objdir 'wasm/build/obj/%{cfg.buildcfg}/'
end
filter 'configurations:debug'
do
files {
@ -54,23 +60,28 @@ do
buildoptions {
'-Wall',
'-ansi',
'-pedantic'
'-pedantic',
'-DANSI_DECLARATORS'
}
buildoptions {
'-s STRICT=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'-DSINGLE',
'-DANSI_DECLARATORS',
'-Wno-c++17-extensions',
'-fno-exceptions',
'-fno-rtti',
'-fno-unwind-tables',
'--no-entry',
'-Wno-deprecated-builtins'
}
filter {'options:wasm'}
do
buildoptions {
'-s STRICT=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'--no-entry'
}
end
filter 'configurations:debug'
do
defines {'DEBUG'}
@ -97,12 +108,12 @@ end
project 'rive_text'
do
kind 'ConsoleApp'
kind 'SharedLib'
language 'C++'
cppdialect 'C++17'
toolset 'clang'
targetdir('build/bin/%{cfg.buildcfg}')
objdir('build/obj/%{cfg.buildcfg}')
targetdir('shared_lib/build/bin/%{cfg.buildcfg}')
objdir('shared_lib/build/obj/%{cfg.buildcfg}')
dependson {
'rive_sheenbidi'
@ -123,8 +134,9 @@ do
}
files {
'rive_text_bindings.cpp',
source .. '/src/renderer.cpp',
source .. '/src/rive_counter.cpp',
source .. '/src/math/mat2d.cpp',
source .. '/src/math/raw_path.cpp',
source .. '/src/text/font_hb.cpp',
source .. '/src/text/line_breaker.cpp',
@ -189,68 +201,77 @@ do
}
buildoptions {
'-s STRICT=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'-DSINGLE',
'-DANSI_DECLARATORS',
'-Wno-c++17-extensions',
'-fno-exceptions',
'-fno-rtti',
'-fno-unwind-tables',
'--no-entry',
'-Wno-deprecated-builtins'
'-Wno-deprecated-builtins',
'-DANSI_DECLARATORS'
}
linkoptions {
'--closure 1',
'--closure-args="--externs ./js/externs.js"',
'--bind',
'-s FORCE_FILESYSTEM=0',
'-s MODULARIZE=1',
'-s NO_EXIT_RUNTIME=1',
'-s STRICT=1',
'-s ALLOW_MEMORY_GROWTH=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-s WASM=1',
-- "-s EXPORT_ES6=1",
'-s USE_ES6_IMPORT_META=0',
'-s EXPORT_NAME="RiveText"',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'-DANSI_DECLARATORS',
'-Wno-c++17-extensions',
'-fno-exceptions',
'-fno-rtti',
'-fno-unwind-tables',
'--no-entry',
'--pre-js ./js/rive_text.js'
}
filter {'options:single_file'}
filter {'options:wasm'}
do
targetdir 'wasm/build/bin/%{cfg.buildcfg}/'
objdir 'wasm/build/obj/%{cfg.buildcfg}/'
kind 'ConsoleApp'
files {
'wasm/rive_text_bindings.cpp'
}
buildoptions {
'-s STRICT=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'--no-entry'
}
linkoptions {
'-o %{cfg.targetdir}/rive_text_single.js'
'--closure 1',
'--closure-args="--externs ./wasm/js/externs.js"',
'--bind',
'-s FORCE_FILESYSTEM=0',
'-s MODULARIZE=1',
'-s NO_EXIT_RUNTIME=1',
'-s STRICT=1',
'-s ALLOW_MEMORY_GROWTH=1',
'-s DISABLE_EXCEPTION_CATCHING=1',
'-s WASM=1',
'-s USE_ES6_IMPORT_META=0',
'-s EXPORT_NAME="RiveText"',
'-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0',
'--no-entry',
'--pre-js ./wasm/js/rive_text.js'
}
end
filter {'options:not single_file'}
linkoptions {
'-Wno-c++17-extensions',
'-fno-exceptions',
'-fno-rtti',
'-fno-unwind-tables'
}
filter {'options:wasm', 'options:single_file'}
do
linkoptions {
'-o %{cfg.targetdir}/rive_text_single.js',
'-s SINGLE_FILE=1'
}
end
filter {'options:wasm', 'options:not single_file'}
do
linkoptions {
'-o %{cfg.targetdir}/rive_text.js'
}
end
filter 'options:single_file'
do
linkoptions {
'-s SINGLE_FILE=1'
}
end
filter 'configurations:debug'
do
defines {'DEBUG'}
symbols 'On'
end
filter {'configurations:debug', 'options:wasm'}
do
linkoptions {'-s ASSERTIONS=1'}
end
@ -259,6 +280,10 @@ do
defines {'RELEASE'}
defines {'NDEBUG'}
optimize 'On'
end
filter {'configurations:release', 'options:wasm'}
do
linkoptions {'-s ASSERTIONS=0'}
end
@ -274,7 +299,13 @@ do
'-flto'
}
end
newoption {
trigger = 'single_file',
description = 'Set when the wasm should be packed in with the js code.'
}
newoption {
trigger = 'wasm',
description = 'Set when the wasm should be packed in with the js code.'
}

40
shared_lib/build_shared.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
set -e
CONFIG=debug
SINGLE=
for var in "$@"; do
if [[ $var = "release" ]]; then
CONFIG=release
fi
done
pushd ../
./update_dependencies.sh
popd
if [[ ! -f "bin/premake5" ]]; then
mkdir -p bin
pushd bin
echo Downloading Premake5
curl https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-macosx.tar.gz -L -o premake_macosx.tar.gz
# Export premake5 into bin
tar -xvf premake_macosx.tar.gz 2>/dev/null
# Delete downloaded archive
rm premake_macosx.tar.gz
popd
fi
export PREMAKE=bin/premake5
$PREMAKE --scripts=../macos/rive-cpp/build --file=../premake5_rive_plugin.lua gmake2
cd ..
for var in "$@"; do
if [[ $var = "clean" ]]; then
make clean
make config=release clean
fi
done
make config=$CONFIG -j$(($(sysctl -n hw.physicalcpu) + 1))

BIN
test/assets/RobotoFlex.ttf Normal file

Binary file not shown.

17
test/text_test.dart Normal file
View File

@ -0,0 +1,17 @@
import 'dart:ffi';
import 'package:flutter_test/flutter_test.dart';
// ignore: implementation_imports
import 'package:rive/src/rive_text.dart';
import 'src/utils.dart';
void main() {
test('simple shaping', () {
final bytes = loadFile('assets/RobotoFlex.ttf');
expect(bytes.lengthInBytes, 1654412);
DynamicLibrary.open('shared_lib/build/bin/debug/librive_text.dylib');
var roboto = Font.decode(bytes.buffer.asUint8List());
expect(roboto, isNotNull);
});
}

View File

@ -42,7 +42,7 @@ source ./bin/emsdk/emsdk_env.sh
export PREMAKE=bin/premake5
$PREMAKE --scripts=../macos/rive-cpp/build --file=./premake5_wasm.lua gmake2 $SINGLE
$PREMAKE --scripts=../macos/rive-cpp/build --file=../premake5_rive_plugin.lua gmake2 $SINGLE --wasm
for var in "$@"; do
if [[ $var = "clean" ]]; then
@ -51,6 +51,7 @@ for var in "$@"; do
fi
done
cd ..
AR=emar CC=emcc CXX=em++ make config=$CONFIG -j$(($(sysctl -n hw.physicalcpu) + 1))
du -hs build/bin/$CONFIG/rive_text.wasm
du -hs wasm/build/bin/$CONFIG/rive_text.wasm