Skip to content

Commit f93e758

Browse files
author
Michael Wilkerson-Barker
authored
RCORE-1992 Add emscripten debug/release compile tasks to evergreen (#7916)
* Fixed emscripten compilation errors; added emscripten to cross_compile.sh * Fixed emscripten warning * Updates for build; added debug and release builds * Updated emscripten variant names; Disabled warnings in cross_compile.sh * Updated emscripten errors when emcmake was not found * Updates to emscripten build * Build using emscripten SDK instead of docker * Reverted/removed REALM_COMBINED_TESTS cmake flag * Updated cross_compile to not build tests and moved emscripten build steps to config.yml
1 parent 14bbdf1 commit f93e758

File tree

9 files changed

+193
-59
lines changed

9 files changed

+193
-59
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-----------
1717

1818
### Internals
19-
* None.
19+
* Fix emscripten build and add emscripten debug/release compile tasks to evergreen. ([PR #7916](https://github.com/realm/realm-core/pull/7916))
2020

2121
----------------------------------------------
2222

evergreen/config.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,48 @@ functions:
197197
-j ${max_jobs|$(grep -c proc /proc/cpuinfo)} \
198198
$target
199199
200+
"compile emscripten":
201+
- command: shell.exec
202+
params:
203+
working_dir: realm-core
204+
shell: bash
205+
script: |-
206+
set -o errexit
207+
set -o pipefail
208+
set -o verbose
209+
210+
if [ -n "${cmake_bindir|}" ]; then
211+
export CMAKE="$(./evergreen/abspath.sh "${cmake_bindir}/cmake")"
212+
else
213+
export CMAKE="cmake"
214+
fi
215+
216+
# Check out the Emscripten SDK and activate the specified version
217+
echo "Activating emscripten SDK version: ${emsdk_version|latest}"
218+
git clone https://github.com/emscripten-core/emsdk.git
219+
220+
pushd emsdk/ > /dev/null # realm-core/emsdk
221+
./emsdk install ${emsdk_version|latest}
222+
./emsdk activate ${emsdk_version|latest}
223+
source ./emsdk_env.sh
224+
popd > /dev/null # realm-core
225+
226+
if [[ "$(uname -s)" =~ Darwin* ]]; then
227+
NPROC="$(sysctl -n hw.ncpu)"
228+
else
229+
NPROC="$(nproc)"
230+
fi
231+
232+
mkdir -p build-emscripten
233+
pushd build-emscripten > /dev/null # realm-core/build-emscripten
234+
235+
# shellcheck disable=SC2086,SC2090
236+
emcmake $CMAKE -D CMAKE_BUILD_TYPE="${cmake_build_type|Debug}" \
237+
..
238+
239+
make "-j$NPROC" 2>&1
240+
popd > /dev/null # realm-core
241+
200242
"run benchmark":
201243
- command: shell.exec
202244
params:
@@ -749,6 +791,12 @@ tasks:
749791
commands:
750792
- func: "compile"
751793

794+
- name: compile-emscripten
795+
exec_timeout_secs: 1800
796+
tags: [ "for_pull_requests" ]
797+
commands:
798+
- func: "compile emscripten"
799+
752800
- name: package
753801
exec_timeout_secs: 1800
754802
commands:
@@ -1297,6 +1345,15 @@ task_groups:
12971345
- compile
12981346
- .test_suite
12991347

1348+
- name: compile_emscripten
1349+
max_hosts: 1
1350+
setup_group_can_fail_task: true
1351+
setup_group:
1352+
- func: "fetch source"
1353+
- func: "fetch binaries"
1354+
tasks:
1355+
- compile-emscripten
1356+
13001357
# Runs object-store-tests against baas running on remote host and runs
13011358
# the network simulation tests as a separate task for nightly builds
13021359
- name: network_tests
@@ -1648,6 +1705,27 @@ buildvariants:
16481705
tasks:
16491706
- name: fuzzer-tests
16501707

1708+
- name: ubuntu-emscripten
1709+
display_name: "Ubuntu (Emscripten x86_64)"
1710+
run_on: ubuntu2204-large
1711+
expansions:
1712+
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-linux-x86_64.tar.gz"
1713+
cmake_bindir: "./cmake_binaries/bin"
1714+
emsdk_version: "3.1.37"
1715+
tasks:
1716+
- name: compile_emscripten
1717+
1718+
- name: ubuntu-emscripten-release
1719+
display_name: "Ubuntu (Emscripten x86_64 Release build)"
1720+
run_on: ubuntu2204-large
1721+
expansions:
1722+
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-linux-x86_64.tar.gz"
1723+
cmake_bindir: "./cmake_binaries/bin"
1724+
cmake_build_type: RelWithDebInfo
1725+
emsdk_version: "3.1.37"
1726+
tasks:
1727+
- name: compile_emscripten
1728+
16511729
# disable these builders since there are constantly failing and not yet ready for nightly builds
16521730
# - name: ubuntu2004-network-nonideal
16531731
# display_name: "Ubuntu 20.04 x86_64 (Utunbu2004 - nonideal transfer)"

src/realm/alloc_slab.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class SlabAlloc : public Allocator {
147147
/// This can happen if the conflicting thread (or process) terminates or
148148
/// crashes before the next retry.
149149
///
150-
/// \throw FileAccessError
151-
/// \throw SlabAlloc::Retry
150+
/// \throw FileAccessError if unable to access the file
151+
/// \throw SlabAlloc::Retry if the request cannot be completed right now
152152
ref_type attach_file(const std::string& file_path, Config& cfg, util::WriteObserver* write_observer = nullptr);
153153

154154
/// @brief Expand or contract file
@@ -179,7 +179,7 @@ class SlabAlloc : public Allocator {
179179
///
180180
/// \sa own_buffer()
181181
///
182-
/// \throw InvalidDatabase
182+
/// \throw InvalidDatabase if an error occurs while attaching the allocator
183183
ref_type attach_buffer(const char* data, size_t size);
184184

185185
void init_in_memory_buffer();

src/realm/object-store/sync/app.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,27 @@ SharedApp App::get_app(CacheMode mode, const AppConfig& config) NO_THREAD_SAFETY
210210
std::lock_guard lock(s_apps_mutex);
211211
auto& app = s_apps_cache[config.app_id][base_url_from_app_config(config)];
212212
if (!app) {
213-
app = std::make_shared<App>(Private(), config);
213+
app = App::make_app(config);
214214
}
215215
return app;
216216
}
217217
REALM_ASSERT(mode == CacheMode::Disabled);
218+
return App::make_app(config);
219+
}
220+
221+
SharedApp App::make_app(const AppConfig& config)
222+
{
223+
#ifdef __EMSCRIPTEN__
224+
if (!config.transport) {
225+
// Make a copy and provide a default transport if not provided
226+
AppConfig config_copy = config;
227+
config_copy.transport = std::make_shared<_impl::EmscriptenNetworkTransport>();
228+
return std::make_shared<App>(Private(), config_copy);
229+
}
218230
return std::make_shared<App>(Private(), config);
231+
#else
232+
return std::make_shared<App>(Private(), config);
233+
#endif
219234
}
220235

221236
SharedApp App::get_cached_app(const std::string& app_id, const std::optional<std::string>& base_url)
@@ -257,11 +272,6 @@ App::App(Private, const AppConfig& config)
257272
, m_metadata_store(create_metadata_store(config, *m_file_manager))
258273
, m_sync_manager(SyncManager::create(config.sync_client_config))
259274
{
260-
#ifdef __EMSCRIPTEN__
261-
if (!m_config.transport) {
262-
m_config.transport = std::make_shared<_impl::EmscriptenNetworkTransport>();
263-
}
264-
#endif
265275
REALM_ASSERT(m_config.transport);
266276

267277
// if a base url is provided, then verify the value

src/realm/object-store/sync/app.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ class App : public std::enable_shared_from_this<App>,
449449
private:
450450
const AppConfig m_config;
451451

452+
static SharedApp make_app(const AppConfig& config);
453+
452454
util::CheckedMutex m_route_mutex;
453455
// The following variables hold the different paths to Atlas, depending on the
454456
// request being performed

src/realm/sync/instruction_applier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ void InstructionApplier::operator()(const Instruction::Update& instr)
373373
field_name, table_name, col.get_type(), mixed_ptr->get_type());
374374
}
375375
}
376-
else if (const auto obj_val_ptr = mpark::get_if<Instruction::Payload::ObjectValue>(&arg)) {
376+
else if (mpark::get_if<Instruction::Payload::ObjectValue>(&arg)) {
377377
if (obj.is_null(col)) {
378378
obj.create_and_set_linked_object(col);
379379
}
380380
}
381-
else if (const auto erase_ptr = mpark::get_if<Instruction::Payload::Erased>(&arg)) {
381+
else if (mpark::get_if<Instruction::Payload::Erased>(&arg)) {
382382
m_applier->bad_transaction_log("Update: Dictionary erase at object field");
383383
}
384384
else if (mpark::get_if<Instruction::Payload::Dictionary>(&arg)) {

src/realm/util/file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ bool File::MapBase::try_extend_to(size_t size) noexcept
17741774
#ifndef _WIN32
17751775
char* extension_start_addr = (char*)m_addr + m_size;
17761776
size_t extension_size = size - m_size;
1777-
size_t extension_start_offset = m_offset + m_size;
1777+
size_t extension_start_offset = static_cast<size_t>(m_offset) + m_size;
17781778
#if REALM_ENABLE_ENCRYPTION
17791779
if (m_encrypted_mapping) {
17801780
void* got_addr = ::mmap(extension_start_addr, extension_size, PROT_READ | PROT_WRITE,

test/util/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ if(UNIX AND NOT APPLE)
5858
find_library(LIBRT rt)
5959
if(LIBRT)
6060
target_link_libraries(TestUtil ${LIBRT})
61-
# Android has librt included in libc
62-
elseif(NOT ANDROID)
61+
# Android and Emscripten have librt included in libc
62+
elseif(NOT ANDROID AND NOT EMSCRIPTEN)
6363
message(WARNING "librt was not found. This means that the benchmarks will not be able to link properly.")
6464
endif()
6565
endif()

0 commit comments

Comments
 (0)