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

WASM CI #445

Merged
merged 83 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
f90b548
Not yet working: find_package fails to discover transpiled boost desp…
nickpdemarco Jun 20, 2022
de4845a
Update from main
nickpdemarco Jun 21, 2022
aaa92d3
Merge branch 'main' into demarco/wasm-ci
nickpdemarco Jun 21, 2022
5161d65
Merge branch 'main' into demarco/wasm-ci
nickpdemarco Jun 28, 2022
0f88917
Stlab tests compiling under wasm, but not linking due to duplicate sy…
nickpdemarco Jun 28, 2022
00f62b5
Despite adding -pthread in all the right places, we're still missing …
nickpdemarco Jun 29, 2022
a89d322
manually set threading, task system, and executor settings to get bui…
nickpdemarco Jun 29, 2022
957bb11
Merge branch 'main' into demarco/wasm-ci
nickpdemarco Jun 30, 2022
4ba23e0
building/installing boost with cmake, but linking stlab to boost unit…
nickpdemarco Jul 20, 2022
81c64d4
Merge remote-tracking branch 'origin/main' into demarco/wasm-ci
nickpdemarco Jul 20, 2022
0609132
Remove check for Boost_USE_STATIC_LIBS and add pthread flag to boost …
nickpdemarco Jul 20, 2022
825b49d
Let emscripten use PORTABLE system_timer
nickpdemarco Jul 21, 2022
c310b3d
Fix violations of -Wunqualified-std-cast-call and -Wunused-but-set-va…
nickpdemarco Jul 21, 2022
b97db7b
Docker image can now be run with a test suite, e.g. 'future' or 'chan…
nickpdemarco Jul 21, 2022
2e6ae4b
Abandon emrun; some tests passing
nickpdemarco Jul 21, 2022
f9afd6c
emrun returns
nickpdemarco Jul 25, 2022
e7edcbf
remove STLAB_TASK_SYSTEM(EMSCRIPTEN) and use PORTABLE instead
nickpdemarco Jul 25, 2022
c7b3a17
Unpretty if/else on emscripten test config
nickpdemarco Jul 25, 2022
106334f
First draft of wasm ci action
nickpdemarco Jul 26, 2022
1b608d6
typo
nickpdemarco Jul 26, 2022
b7981a7
typo2
nickpdemarco Jul 26, 2022
bea6cb5
odd github actions negation syntax
nickpdemarco Jul 26, 2022
8f96321
misunderstood github actions expression syntax... clunky "== false" t…
nickpdemarco Jul 26, 2022
c560e8b
missed save of matrix.json which caused confusion
nickpdemarco Jul 26, 2022
e47e234
missed a sudo
nickpdemarco Jul 26, 2022
7ed6666
Use open source action to setup emsdk
nickpdemarco Jul 26, 2022
a1ed4a0
cleverness to get emsdk root for boost install
nickpdemarco Jul 26, 2022
8dd4bdc
simplify boost root path. emscripten sysroot appears unnecessary on l…
nickpdemarco Jul 26, 2022
552866f
consolidate steps and improve reuse. build boost before configuring s…
nickpdemarco Jul 26, 2022
f148360
Put back emsdk sysroot
nickpdemarco Jul 26, 2022
271f872
try replacing ~ with $HOME
nickpdemarco Jul 26, 2022
c7baafe
Fix logic error in StlabUtil.cmake
nickpdemarco Jul 26, 2022
d300ae8
Fix path typo in stlab.yml
nickpdemarco Jul 26, 2022
8155eae
remove stale requirement for matching main executor and task system
nickpdemarco Jul 26, 2022
7f8fa1d
remove unused dockerfile
nickpdemarco Jul 26, 2022
34b45ae
remove unused dockerignore
nickpdemarco Jul 26, 2022
bbcbb82
Add newline to stlab.yml
nickpdemarco Jul 26, 2022
2d7a78d
Remove unnecessary install prefix and boost_root settings.
nickpdemarco Jul 27, 2022
78310a8
remove redundant parens
nickpdemarco Jul 27, 2022
bb1ae72
Use --shallow-submodules and --jobs=8 to speed up boost clone
nickpdemarco Jul 27, 2022
a02dc0e
Move emcc verification step into cmake file, out of github action
nickpdemarco Jul 27, 2022
05b3f4d
Attempt minimal install of emsdk over mymindstorm dependency
nickpdemarco Jul 27, 2022
243a70b
Use bash -l /Users/demarco/emsdk/emsdk_env.sh on steps that require e…
nickpdemarco Jul 27, 2022
c2c35af
Attempt alternative way of installing emsdk to bash profile
nickpdemarco Jul 27, 2022
f481a8f
Yet another attempt at setting up emsdk manually
nickpdemarco Jul 27, 2022
a1aa05c
Explicitly source at each step
nickpdemarco Jul 27, 2022
f0b95c2
Did I really just miss an ?
nickpdemarco Jul 27, 2022
ef13a38
Did I really just miss an activate?
nickpdemarco Jul 27, 2022
e084ac7
Merge branch 'demarco/wasm-ci' of https://github.com/stlab/libraries …
nickpdemarco Jul 27, 2022
28ae72d
Wrap source in quotes
nickpdemarco Jul 27, 2022
d6c00fe
-sPTHREAD_POOL_SIZE to 32 from 100
nickpdemarco Jul 27, 2022
09505e0
Add cmake/ExperimentalEmscripten.cmake, a toolchain for using the min…
nickpdemarco Jul 29, 2022
227025f
Merge branch 'main' into demarco/wasm-ci
nickpdemarco Jul 29, 2022
3460534
missing newline in ExperimentalEmscripten.cmake
nickpdemarco Jul 29, 2022
da996f5
revert trivial changes to test/CMakeLists.txt
nickpdemarco Jul 29, 2022
d83968e
Remove now unnecessary emscripten conditional
nickpdemarco Jul 29, 2022
76fa5fe
stlab.yml cleanup
nickpdemarco Jul 29, 2022
dffd22b
nit in ExperimentalEmscripten.cmake
nickpdemarco Jul 29, 2022
4c9e290
Absolute paths to ExperimentalEmscripten.cmake in stlab.yml
nickpdemarco Jul 29, 2022
3bf3b5c
-Wno-deprecated-builtins for boost to quiet our build output.
nickpdemarco Jul 29, 2022
19c2a18
Checking if BOOST_INCLUDE_LIBRARIES is breaking my include paths
nickpdemarco Jul 29, 2022
40024ad
Fix check for node version. Add --output-on-failure to ctest
nickpdemarco Jul 29, 2022
4f89847
Override Emsdk's bundled node with the system installation, since the…
nickpdemarco Jul 29, 2022
9778f92
Logging for debugging
nickpdemarco Jul 29, 2022
a8351bb
missing quotes
nickpdemarco Jul 29, 2022
9ffc1a9
Putting back comment in emscripten main executor
nickpdemarco Jul 29, 2022
88ebfa1
Add exception handling comment to emscripten main executor
nickpdemarco Jul 29, 2022
27cc788
Make .emscripten overwrite more terse
nickpdemarco Jul 29, 2022
dd8bb92
Use consistent naming for action steps
nickpdemarco Jul 29, 2022
2aa73a3
Attempt a leaner boost library set to reduce compile time
nickpdemarco Jul 29, 2022
a6514f6
Add boost::multiprecision dependency
nickpdemarco Jul 29, 2022
9560cfd
consistency in platform titles in gh actions
nickpdemarco Jul 29, 2022
d8dc072
Apply suggestions from code review
nickpdemarco Aug 1, 2022
6c3fdb7
Remove noop git pull command
nickpdemarco Aug 1, 2022
760fb51
Make cmake formatting consistent in emscripten snippet
nickpdemarco Aug 1, 2022
9a52929
Put back $HOME to see if it fixes CI
nickpdemarco Aug 2, 2022
9cf3d86
Move emcc version printout to the emscripten toolchain file
nickpdemarco Aug 2, 2022
e809c54
Move cmake/ExperimentalEmscripten.cmake to cmake/Platform/Emscripten-…
nickpdemarco Aug 2, 2022
5d8e0da
Make emscripten include work with system installations
nickpdemarco Aug 2, 2022
fd3d55c
Respond to various review comments in Emscripten-STLab.cmake
nickpdemarco Aug 2, 2022
362d148
Attempt to standardize naming of github actions steps
nickpdemarco Aug 2, 2022
cf994bb
Apply suggestions from code review
nickpdemarco Aug 2, 2022
b662df6
Apply suggestions from code review
nickpdemarco Aug 2, 2022
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
5 changes: 5 additions & 0 deletions .github/matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"version": "16",
"os": "windows-2019",
"cmake_toolset": "Visual Studio 16 2019"
},
{
"name": "Linux Webassembly",
"compiler": "emscripten",
"os": "ubuntu-22.04"
}
]
}
55 changes: 50 additions & 5 deletions .github/workflows/stlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
id: set-matrix
# Note: The json in this variable must be a single line for parsing to succeed.
run: echo "::set-output name=matrix::$(cat .github/matrix.json | scripts/flatten_json.py)"

builds:
needs: generate-matrix
runs-on: ${{ matrix.config.os }}
Expand All @@ -30,6 +30,14 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: mymindstorm/setup-emsdk@v11
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider using apt-get to install enscripten rather than take on this dependency on mymindstorm/setup-emsdk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither apt nor apt-get have an emscripten or emsdk package, but I've removed this dependency in favor of a manual installation of emsdk.

Notably, it requires we modify bash_profile, so you'll see all subsequent emscripten steps will use shell: bash -l {0}, in order to override GitHub Actions' default of a --noprofile shell. See here for more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it installed on my Ubuntu machine. See: https://packages.ubuntu.com/jammy/emscripten

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are considered unofficial packages by the Emscripten team, and are not officially supported. I've opted to stick strictly to their installation guidelines and clone/install their repo instead of adding the aforementioned dependency.


- name: Verify emsdk installation (emscripten)
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
run: |
which emcc
emcc -v
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dependencies (macos)
if: ${{ startsWith(matrix.config.os, 'macos') }}
Expand All @@ -39,7 +47,7 @@ jobs:
shell: bash

- name: Install dependencies (ubuntu)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this "Install dependencies (Linux GCC/Clang)" and the new one "Install dependencies (Linux Webassembly)"? I'm going off the names in the matrix file. It'd be good if we could figure out something consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I also mulled this over and I'm craving consistency. I'll take another crack at it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a crack at it, not satisfied but it crossed my 80/20 threshold. Let me know what you think.

https://github.com/stlab/libraries/runs/7640371961?check_suite_focus=true

if: ${{ startsWith(matrix.config.os, 'ubuntu') }}
if: ${{ startsWith(matrix.config.os, 'ubuntu') && !startsWith(matrix.config.compiler, 'emscripten') }}
run: |
sudo apt-get install -y ninja-build
sudo apt-get install -y libboost-all-dev
Expand All @@ -52,6 +60,14 @@ jobs:
vcpkg install boost-test:x64-windows boost-multiprecision:x64-windows boost-variant:x64-windows
shell: cmd

- name: Install dependencies (emscripten ubuntu)
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
sudo apt-get install -y ninja-build
sudo apt update -y && sudo apt install firefox -y
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
git clone --depth 1 --recurse-submodules https://github.com/boostorg/boost.git $HOME/boost
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved

- name: Set enviroment variables (Linux+GCC)
if: ${{ matrix.config.compiler == 'gcc' }}
shell: bash
Expand All @@ -66,13 +82,34 @@ jobs:
echo "CC=clang-${{matrix.config.version}}" >> $GITHUB_ENV
echo "CXX=clang++-${{matrix.config.version}}" >> $GITHUB_ENV

- name: Configure (Unix)
if: ${{ startsWith(matrix.config.os, 'ubuntu') || startsWith(matrix.config.os, 'macos') }}
- name: Compile Boost (Ubuntu emscripten)
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
mkdir -p ../build-boost
emcmake cmake -S $HOME/boost -B ../build-boost -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 \
-DCMAKE_CXX_FLAGS="-pthread" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this is needed? My expectation is that if this flag is needed, it comes from the FindThreads CMake module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also surprised this was needed. Without it, the boost sources are not passed -pthread during compilation. Below is a sample (without -DCMAKE_CXX_FLAGS="-pthread")

/Users/demarco/dev/emsdk/upstream/emscripten/em++
-DBOOST_ATOMIC_NO_LIB
-DBOOST_ATOMIC_STATIC_LINK
-DBOOST_FILESYSTEM_HAS_FDOPENDIR_NOFOLLOW
-DBOOST_FILESYSTEM_HAS_INIT_PRIORITY
-DBOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE
-DBOOST_FILESYSTEM_HAS_STAT_ST_MTIM
-DBOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF
-DBOOST_FILESYSTEM_NO_LIB
-DBOOST_FILESYSTEM_SOURCE
-DBOOST_FILESYSTEM_STATIC_LINK=1
-I/Users/demarco/dev/boost/libs/filesystem/include
# various boost includes elided...
-g
-std=gnu++11
-MD
-MT libs/filesystem/CMakeFiles/boost_filesystem.dir/src/portability.cpp.o
-MF libs/filesystem/CMakeFiles/boost_filesystem.dir/src/portability.cpp.o.d
-o libs/filesystem/CMakeFiles/boost_filesystem.dir/src/portability.cpp.o
-c /Users/demarco/dev/boost/libs/filesystem/src/portability.cpp

Subsequently, we fail to link with this error:

wasm-ld: error: --shared-memory is disallowed by decorator.cpp.o because it was not compiled with 'atomics' or 'bulk-memory' features.

The first google for that error suggested a missing -pthread was the cause.

I do not know why FindThreads does not do this automatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some more investigation is warranted here. Adding this to the top-level of the Boost build may work, but it doesn't solve the problem in the right place. Perhaps the CMakeLists.txt in filesystem needs an adjustment. Did you figure out which piece of code is brining in the -pthread requirement?

Also, I didn't see this in my own experiments. When in the build process are you seeing a linker error?

-DCMAKE_INSTALL_PREFIX=`which emsdk`/../upstream/emscripten/cache/sysroot/$HOME/boost-release-emscripten-install \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed when reading through Emscripten.cmake that CMAKE_INSTALL_PREFIX is by default set to blah/cache/sysroot. This line may not actually be needed.

Another thing I noticed in that file is that you can use em-config CACHE to get the cache directory in a more direct way.

-DBOOST_EXCLUDE_LIBRARIES="asio;beast;context;coroutine;fiber;log"

cmake --build ../build-boost
cmake --install ../build-boost

- name: Configure (Unix && !emscripten)
if: ${{ (startsWith(matrix.config.os, 'ubuntu') || startsWith(matrix.config.os, 'macos')) && !startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
mkdir ../build
cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23

- name: Configure (Ubuntu emscripten)
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
mkdir ../build
emcmake cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 \
-DBOOST_ROOT=$HOME/boost-release-emscripten-install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my above comment, I think BOOST_ROOT may not be needed here.


- name: Configure (Windows)
if: ${{ startsWith(matrix.config.os, 'windows') }}
shell: cmd
Expand All @@ -82,7 +119,7 @@ jobs:
cmake -S. -B../build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_CXX_STANDARD=23

- name: Build (Unix)
if: ${{ startsWith(matrix.config.os, 'ubuntu') || startsWith(matrix.config.os, 'macos') }}
if: ${{ (startsWith(matrix.config.os, 'ubuntu') || startsWith(matrix.config.os, 'macos')) }}
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
cmake --build ../build/
Expand All @@ -95,7 +132,15 @@ jobs:
cmake --build ../build/

- name: Test
if: ${{ !startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
cd ../build/
ctest

- name: Test (emscripten)
if: ${{ startsWith(matrix.config.compiler, 'emscripten') }}
shell: bash
run: |
find ../build/test -name "stlab.test.*.html" -exec \
emrun --browser_args="--headless" --browser firefox --kill_start --kill_exit {} \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider using ctest with the default node-based runner for these tests?

Copy link
Member Author

@nickpdemarco nickpdemarco Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I tried to get ctest to work with this, but I made little progress.

First, we'd need to change the output type from .html to the default .js. If we don't, the ctest node runner tries to parse the HTML as javascript, and dies.

If we make that change, and run ctest, we fail with the following:

Test project /Users/demarco/build/stlab-debug
    Start 1: stlab.test.channel
1/9 Test #1: stlab.test.channel ...............***Failed    0.56 sec
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): unexpected section <Exception> @+37542
Aborted(CompileError: WebAssembly.instantiate(): unexpected section <Exception> @+37542)
Aborted(Assertion failed: native function `__trap` called before runtime initialization)
Aborted(Assertion failed: native function `__trap` called before runtime initialization)
Aborted(Assertion failed: native function `__trap` called before runtime initialization)
Aborted(Assertion failed: native function `__trap` called before runtime initialization)

That __trap error is repeated until you kill it with CTRL-C.

The culprit seems to be unexpected section <Exception> @+37542, which presumably is introduced to the binary due to our use of -fwasm-exceptions at compile and link time. This flag is required for the stlab tests to make progress.

To the best of my knowledge, neither ctest nor node are supported environments for running code transpiled with emscripten. The only "running" documentation is here, which suggests the use of emrun.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. In that case I think going with your own toolchain makes sense. You can set CMAKE_CROSSCOMPILING_EMULATOR to an emrun launch.

I don't think it is true that CTest isn't a supported environment from running code transpiled with emscripten. It is a general tool that can be used to run any cross-compiled code provided an appropriate emulator.

Node must be a supported environment for at least some emscripten since that is what they explicitly set in Emscripten.cmake.

16 changes: 2 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ stlab_detect_thread_system(STLAB_DEFAULT_THREAD_SYSTEM)
set( STLAB_THREAD_SYSTEM ${STLAB_DEFAULT_THREAD_SYSTEM} CACHE STRING "Thread system to use (win32|pthread|pthread-emscripten|pthread-apple|none)")

stlab_detect_task_system(STLAB_DEFAULT_TASK_SYSTEM)
set(STLAB_TASK_SYSTEM ${STLAB_DEFAULT_TASK_SYSTEM} CACHE STRING "Select the task system (portable|libdispatch|emscripten|windows).")
set(STLAB_TASK_SYSTEM ${STLAB_DEFAULT_TASK_SYSTEM} CACHE STRING "Task system to use (portable|libdispatch|windows).")

stlab_detect_main_executor(STLAB_DEFAULT_MAIN_EXECUTOR)
set(STLAB_MAIN_EXECUTOR ${STLAB_DEFAULT_MAIN_EXECUTOR} CACHE STRING "Select the main executor variant (qt|libdispatch|emscripten|none).")
set(STLAB_MAIN_EXECUTOR ${STLAB_DEFAULT_MAIN_EXECUTOR} CACHE STRING "Main executor to use (qt|libdispatch|emscripten|none).")

if( BUILD_TESTING AND NOT Boost_unit_test_framework_FOUND )
message( SEND_ERROR "BUILD_TESTING is enabled, but an installation of Boost.Test was not found." )
Expand All @@ -49,10 +49,6 @@ if( (STLAB_MAIN_EXECUTOR STREQUAL "libdispatch") AND NOT libdispatch_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"libdispatch\", but a libdispatch installation was not found." )
endif()

if( (STLAB_MAIN_EXECUTOR STREQUAL "emscripten") AND NOT (STLAB_TASK_SYSTEM STREQUAL "emscripten") )
message( SEND_ERROR "If STLAB_MAIN_EXECUTOR is set to \"emscripten\", STLAB_TASK_SYSTEM must also be." )
endif()

if( (STLAB_MAIN_EXECUTOR STREQUAL "qt") AND NOT Qt6Core_FOUND )
message( SEND_ERROR "STLAB_MAIN_EXECUTOR is set to \"qt\", but a Qt6 installation was not found." )
endif()
Expand Down Expand Up @@ -130,14 +126,6 @@ if ( BUILD_TESTING )
stlab::development
stlab::stlab )

#
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
# Linking to the Boost unit test framework requires an additional
# preprocessor definition when the unit test compiled resources are
# provided by a shared library rather than a static library.
#
target_compile_definitions( testing INTERFACE
$<$<NOT:$<BOOL:${Boost_USE_STATIC_LIBS}>>:BOOST_TEST_DYN_LINK>)

add_subdirectory( test )
endif()

Expand Down
21 changes: 8 additions & 13 deletions cmake/StlabUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,19 @@ endfunction()
# to the result. The following table shows the correspondence between result
# values and task systems.
#
# | Result value | Task system |
# |--------------+--------------------------------------------|
# | libdispatch | libdispatch (aka. Grand Central Dispatch ) |
# | portable | A portable task system provided by stlab |
# | emscripten | Emscripten's task system |
# | windows | Windows's task system |
# | Result value | Task system |
# |--------------+----------------------------------------------------------------|
# | libdispatch | libdispatch (aka. Grand Central Dispatch ) |
# | portable | A portable task system provided by stlab (supports Emscripten) |
# | windows | Windows's task system |
function( stlab_detect_task_system result_var )
find_package( Threads QUIET )
if( APPLE )
set( result "libdispatch")
elseif( CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
if( Threads_FOUND )
set( result "emscripten")
else()
set( result "portable")
endif()
elseif( WIN32 )
set( result "windows")
elseif( CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
set( result "portable")
else()
find_package( libdispatch )
if( libdispatch_FOUND )
Expand Down Expand Up @@ -159,7 +154,7 @@ function( stlab_detect_main_executor result_var )

if( task_system STREQUAL "libdispatch" )
set( result "libdispatch")
elseif( task_system STREQUAL "emscripten" )
elseif( CMAKE_SYSTEM_NAME STREQUAL "Emscripten" )
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
set( result "emscripten")
elseif( Qt6Core_FOUND )
set( result "qt")
Expand Down
27 changes: 0 additions & 27 deletions stlab/concurrency/default_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@

#if STLAB_TASK_SYSTEM(LIBDISPATCH)
#include <dispatch/dispatch.h>
#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
#include <emscripten.h>
#elif STLAB_TASK_SYSTEM(WINDOWS)
#include <Windows.h>
#include <memory>
#elif STLAB_TASK_SYSTEM(PORTABLE)

#include <algorithm>
#include <atomic>
#include <climits>
#include <condition_variable>
#include <thread>
#include <vector>

#endif

/**************************************************************************************************/
Expand Down Expand Up @@ -111,29 +107,6 @@ struct executor_type {

/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)

template <executor_priority P = executor_priority::medium>
struct executor_type {
using result_type = void;

template <typename F>
void operator()(F f) const {
// REVISIT (sparent) : Using a negative timeout may give better performance. Need to test.
using f_t = decltype(f);

emscripten_async_call(
[](void* f_) {
auto f = static_cast<f_t*>(f_);
(*f)();
delete f;
},
new f_t(std::move(f)), 0);
}
};

/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(WINDOWS)

constexpr auto platform_priority(executor_priority p)
Expand Down
23 changes: 22 additions & 1 deletion stlab/concurrency/main_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,28 @@ struct main_executor_type {

#elif STLAB_MAIN_EXECUTOR(EMSCRIPTEN)

using main_executor_type = default_executor_type;
struct main_scheduler_type {
camio marked this conversation as resolved.
Show resolved Hide resolved
using result_type = void;

template <class F>
void operator()(F&& f) const {
using function_type = typename std::remove_reference<F>::type;
auto p = new function_type(std::forward<F>(f));

emscripten_async_run_in_main_runtime_thread(
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
EM_FUNC_SIG_VI,
camio marked this conversation as resolved.
Show resolved Hide resolved
static_cast<void(*)(void*)>([](void* f_) {
camio marked this conversation as resolved.
Show resolved Hide resolved
emscripten_async_call(
camio marked this conversation as resolved.
Show resolved Hide resolved
[](void* f_) {
auto f = static_cast<function_type*>(f_);
(*f)();
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
delete f;
},
f_, 0);
}),
p);
}
};

#elif STLAB_MAIN_EXECUTOR(NONE)

Expand Down
6 changes: 0 additions & 6 deletions stlab/concurrency/system_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#if STLAB_TASK_SYSTEM(LIBDISPATCH)
#include <dispatch/dispatch.h>
#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)
#include <emscripten.h>
#elif STLAB_TASK_SYSTEM(WINDOWS)
#include <Windows.h>
#include <memory>
Expand Down Expand Up @@ -84,10 +82,6 @@ struct system_timer_type {

/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)

/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(WINDOWS)

class system_timer {
Expand Down
2 changes: 1 addition & 1 deletion stlab/forest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class forest {
return *this = forest(x);
}
forest& operator=(forest&& x) noexcept {
auto tmp{move(x)}; // this is `release()`
auto tmp{std::move(x)}; // this is `release()`
clear(); // these two lines are `reset()`
splice(end(), tmp);
return *this;
Expand Down
43 changes: 34 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,40 @@ add_test(
# tests are compiled without compiler extensions to ensure the stlab headers
# are not dependent upon any such extension.
#
set_target_properties(
stlab.test.channel
stlab.test.future
stlab.test.serial_queue
stlab.test.cow
stlab.test.task
stlab.test.tuple
stlab.test.traits
PROPERTIES CXX_EXTENSIONS OFF )

if (EMSCRIPTEN)
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
set_target_properties(
stlab.test.channel
stlab.test.future
stlab.test.serial_queue
stlab.test.cow
stlab.test.task
stlab.test.tuple
stlab.test.traits
stlab.test.forest
PROPERTIES
CXX_EXTENSIONS OFF
SUFFIX ".html"
COMPILE_OPTIONS "-pthread;-fwasm-exceptions"
LINK_OPTIONS "--emrun;-pthread;-fwasm-exceptions;-sINITIAL_MEMORY=300MB;-sPTHREAD_POOL_SIZE=100;-sPROXY_TO_PTHREAD"
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
)
else()
set_target_properties(
stlab.test.channel
stlab.test.future
stlab.test.serial_queue
stlab.test.cow
stlab.test.task
stlab.test.tuple
stlab.test.traits
stlab.test.forest
PROPERTIES
CXX_EXTENSIONS OFF
)
endif()




#
# Many of the stlab tests are executed using the system executor which defaults
Expand Down
3 changes: 1 addition & 2 deletions test/future_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,7 @@ BOOST_AUTO_TEST_CASE(future_reduction_with_mutable_void_task) {
BOOST_TEST_MESSAGE("future reduction with mutable task");

std::atomic_int check{0};
auto func = [i = int{0}, &check]() mutable {
i++;
auto func = [&check]() mutable {
nickpdemarco marked this conversation as resolved.
Show resolved Hide resolved
++check;
};

Expand Down
Loading