Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emscripten config #6503

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 105 additions & 11 deletions cfg/emscripten.cfg
Original file line number Diff line number Diff line change
@@ -1,14 +1,108 @@
<?xml version="1.0"?>
<def format="2">
<define name="EM_ASM(...)" value=""/>
<define name="EM_ASM_DOUBLE(...)" value=""/>
<define name="EM_ASM_INT(...)" value=""/>
<define name="EM_ASM_PTR(...)" value=""/>
<define name="EM_JS(...)" value=""/>
<define name="MAIN_THREAD_ASYNC_EM_ASM(...)" value=""/>
<define name="MAIN_THREAD_EM_ASM(...)" value=""/>
<define name="MAIN_THREAD_EM_ASM_DOUBLE(...)" value=""/>
<define name="MAIN_THREAD_EM_ASM_INT(...)" value=""/>
<define name="MAIN_THREAD_EM_ASM_PTR(...)" value=""/>
<define name="EMSCRIPTEN_BINDINGS(...)" value=""/>
<function name="emscripten_asm_const_int">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="int" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_double">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="double" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_ptr">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="void*" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_async_on_main_thread">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<returnValue type="void" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_int_sync_on_main_thread">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="int" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_double_sync_on_main_thread">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="int" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<function name="emscripten_asm_const_ptr_sync_on_main_thread">
<arg nr="1" direction="in">
<not-null/>
</arg>
<arg nr="2" direction="in">
<not-null/>
</arg>
<arg nr="variadic" direction="in" />
<use-retval/>
<returnValue type="void*" unknownValues="all"/>
<noreturn>false</noreturn>
</function>
<resource>
<alloc init="true">emscripten_asm_const_ptr</alloc>
<alloc init="true">emscripten_asm_const_ptr_sync_on_main_thread</alloc>
<dealloc>free</dealloc>
</resource>

<!-- macros from em_asm.h -->
<define name="EM_ASM(code, ...)" value="((void)emscripten_asm_const_int(#code, __VA_ARGS__))"/>
<define name="EM_ASM_DOUBLE(code, ...)" value="emscripten_asm_const_double(#code, __VA_ARGS__)"/>
<define name="EM_ASM_INT(code, ...)" value="emscripten_asm_const_int(#code, __VA_ARGS__)"/>
<define name="EM_ASM_PTR(code, ...)" value="emscripten_asm_const_ptr(#code, __VA_ARGS__)"/>
<define name="MAIN_THREAD_ASYNC_EM_ASM(code, ...)" value="emscripten_asm_const_async_on_main_thread(#code, __VA_ARGS__)"/>
<define name="MAIN_THREAD_EM_ASM(code, ...)" value="((void)emscripten_asm_const_int_sync_on_main_thread(#code, __VA_ARGS__))"/>
<define name="MAIN_THREAD_EM_ASM_DOUBLE(code, ...)" value="emscripten_asm_const_double_sync_on_main_thread(#code, __VA_ARGS__)"/>
<define name="MAIN_THREAD_EM_ASM_INT(code, ...)" value="emscripten_asm_const_int_sync_on_main_thread(#code, __VA_ARGS__)"/>
<define name="MAIN_THREAD_EM_ASM_PTR(code, ...)" value="emscripten_asm_const_ptr_sync_on_main_thread(#code, __VA_ARGS__)"/>

<!-- macros from bind.h -->
<define name="EMSCRIPTEN_BINDINGS(name)" value=""/>

<!-- macros from em_js.h -->
<define name="EM_JS(return_type, function_name, arguments, code)" value="return_type function_name(arguments)"/>
</def>
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ if (BUILD_TESTS)
add_cfg(bsd.c)
add_cfg(cairo.c)
add_cfg(cppunit.cpp)
add_cfg(emscripten.cpp)
# TODO: posix needs to specified first or it has a different mmap() config
# TODO: get rid of posix dependency
add_cfg(gnu.c ADD_LIBRARY posix)
Expand Down
91 changes: 91 additions & 0 deletions test/cfg/emscripten.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

// Test library configuration for emscripten.cfg
//
// Usage:
// $ cppcheck --check-library --library=emscripten --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/emscripten.cpp
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#include <stdio.h>
#include <emscripten.h>

void em_asm_test()
{
// inline some JavaScript
EM_ASM(alert('hello'););
MAIN_THREAD_EM_ASM(alert('hello main thread'););

// pass parameters to JavaScript
EM_ASM(
{
console.log('I received: ' + [$0, $1]);
},
100, 35.5);

// pass a string to JavaScript
EM_ASM({console.log('hello ' + UTF8ToString($0))}, "world!");
}

void em_asm_int_test()
{
// cppcheck-suppress unreadVariable
const int x = EM_ASM_INT({
return $0 + 42;
}, 100);

// cppcheck-suppress unreadVariable
const int y = MAIN_THREAD_EM_ASM_INT({return 2;});
}

void em_asm_double_test()
{
// cppcheck-suppress unreadVariable
const double x = EM_ASM_DOUBLE({
return $0 + 1.0;
}, 2.0);

// cppcheck-suppress unreadVariable
const double y = MAIN_THREAD_EM_ASM_DOUBLE({return 1.0;});
}

void em_asm_ptr_test()
{
void* ptr = EM_ASM_PTR({
return stringToNewUTF8("Hello");
});
printf("%s", static_cast<const char*>(ptr));
free(ptr);
}

void em_asm_ptr_memleak_test()
{
const char *str = static_cast<char*>(EM_ASM_PTR({
return stringToNewUTF8("Hello");
}));
printf("%s", str);

// cppcheck-suppress memleak
}

void main_thread_em_asm_ptr_test()
{
// cppcheck-suppress leakReturnValNotUsed
MAIN_THREAD_EM_ASM_PTR(
return stringToNewUTF8("Hello");
);
}

EM_JS(void, two_alerts, (), {
alert('hai');
alert('bai');
});
EM_JS(void, take_args, (int x, float y), {
console.log('I received: ' + [x, y]);
});

void em_js_test()
{
two_alerts();
take_args(100, 35.5);
}
11 changes: 11 additions & 0 deletions test/cfg/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ function cppunit_fn {
fi
}

# emscripten.cpp
function emscripten_fn {
# TODO: Syntax check via g++ does not work because it can not find a valid emscripten.h
# ${CXX} "${CXX_OPT[@]}" ${DIR}emscripten.cpp
true
}

function check_file {
f=$(basename "$1")
lib="${f%%.*}"
Expand All @@ -467,6 +474,10 @@ function check_file {
cppunit_fn
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" --library="$lib" "${DIR}""$f"
;;
emscripten.cpp)
emscripten_fn
"${CPPCHECK}" "${CPPCHECK_OPT[@]}" --library="$lib" "${DIR}""$f"
;;
gnu.c)
gnu_fn
# TODO: posix needs to specified first or it has a different mmap() config
Expand Down
3 changes: 2 additions & 1 deletion tools/donate_cpu_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes)
CLIENT_VERSION = "1.3.59"
CLIENT_VERSION = "1.3.60"

# Timeout for analysis with Cppcheck in seconds
CPPCHECK_TIMEOUT = 30 * 60
Expand Down Expand Up @@ -681,6 +681,7 @@ def __init__(self):
'bsd': ['<sys/queue.h>', '<sys/tree.h>', '<sys/uio.h>','<bsd/', '<fts.h>', '<db.h>', '<err.h>', '<vis.h>'],
'cairo': ['<cairo.h>'],
'cppunit': ['<cppunit/'],
'emscripten': ['<emscripten.h>'],
'icu': ['<unicode/', '"unicode/'],
'ginac': ['<ginac/', '"ginac/'],
'googletest': ['<gtest/gtest.h>'],
Expand Down
Loading