Skip to content

Commit

Permalink
RCORE-1992 Add emscripten debug/release compile tasks to evergreen (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Michael Wilkerson-Barker authored Jul 30, 2024
1 parent 14bbdf1 commit f93e758
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-----------

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

----------------------------------------------

Expand Down
78 changes: 78 additions & 0 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,48 @@ functions:
-j ${max_jobs|$(grep -c proc /proc/cpuinfo)} \
$target
"compile emscripten":
- command: shell.exec
params:
working_dir: realm-core
shell: bash
script: |-
set -o errexit
set -o pipefail
set -o verbose
if [ -n "${cmake_bindir|}" ]; then
export CMAKE="$(./evergreen/abspath.sh "${cmake_bindir}/cmake")"
else
export CMAKE="cmake"
fi
# Check out the Emscripten SDK and activate the specified version
echo "Activating emscripten SDK version: ${emsdk_version|latest}"
git clone https://github.com/emscripten-core/emsdk.git
pushd emsdk/ > /dev/null # realm-core/emsdk
./emsdk install ${emsdk_version|latest}
./emsdk activate ${emsdk_version|latest}
source ./emsdk_env.sh
popd > /dev/null # realm-core
if [[ "$(uname -s)" =~ Darwin* ]]; then
NPROC="$(sysctl -n hw.ncpu)"
else
NPROC="$(nproc)"
fi
mkdir -p build-emscripten
pushd build-emscripten > /dev/null # realm-core/build-emscripten
# shellcheck disable=SC2086,SC2090
emcmake $CMAKE -D CMAKE_BUILD_TYPE="${cmake_build_type|Debug}" \
..
make "-j$NPROC" 2>&1
popd > /dev/null # realm-core
"run benchmark":
- command: shell.exec
params:
Expand Down Expand Up @@ -749,6 +791,12 @@ tasks:
commands:
- func: "compile"

- name: compile-emscripten
exec_timeout_secs: 1800
tags: [ "for_pull_requests" ]
commands:
- func: "compile emscripten"

- name: package
exec_timeout_secs: 1800
commands:
Expand Down Expand Up @@ -1297,6 +1345,15 @@ task_groups:
- compile
- .test_suite

- name: compile_emscripten
max_hosts: 1
setup_group_can_fail_task: true
setup_group:
- func: "fetch source"
- func: "fetch binaries"
tasks:
- compile-emscripten

# Runs object-store-tests against baas running on remote host and runs
# the network simulation tests as a separate task for nightly builds
- name: network_tests
Expand Down Expand Up @@ -1648,6 +1705,27 @@ buildvariants:
tasks:
- name: fuzzer-tests

- name: ubuntu-emscripten
display_name: "Ubuntu (Emscripten x86_64)"
run_on: ubuntu2204-large
expansions:
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-linux-x86_64.tar.gz"
cmake_bindir: "./cmake_binaries/bin"
emsdk_version: "3.1.37"
tasks:
- name: compile_emscripten

- name: ubuntu-emscripten-release
display_name: "Ubuntu (Emscripten x86_64 Release build)"
run_on: ubuntu2204-large
expansions:
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.26.3-linux-x86_64.tar.gz"
cmake_bindir: "./cmake_binaries/bin"
cmake_build_type: RelWithDebInfo
emsdk_version: "3.1.37"
tasks:
- name: compile_emscripten

# disable these builders since there are constantly failing and not yet ready for nightly builds
# - name: ubuntu2004-network-nonideal
# display_name: "Ubuntu 20.04 x86_64 (Utunbu2004 - nonideal transfer)"
Expand Down
6 changes: 3 additions & 3 deletions src/realm/alloc_slab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class SlabAlloc : public Allocator {
/// This can happen if the conflicting thread (or process) terminates or
/// crashes before the next retry.
///
/// \throw FileAccessError
/// \throw SlabAlloc::Retry
/// \throw FileAccessError if unable to access the file
/// \throw SlabAlloc::Retry if the request cannot be completed right now
ref_type attach_file(const std::string& file_path, Config& cfg, util::WriteObserver* write_observer = nullptr);

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

void init_in_memory_buffer();
Expand Down
22 changes: 16 additions & 6 deletions src/realm/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,27 @@ SharedApp App::get_app(CacheMode mode, const AppConfig& config) NO_THREAD_SAFETY
std::lock_guard lock(s_apps_mutex);
auto& app = s_apps_cache[config.app_id][base_url_from_app_config(config)];
if (!app) {
app = std::make_shared<App>(Private(), config);
app = App::make_app(config);
}
return app;
}
REALM_ASSERT(mode == CacheMode::Disabled);
return App::make_app(config);
}

SharedApp App::make_app(const AppConfig& config)
{
#ifdef __EMSCRIPTEN__
if (!config.transport) {
// Make a copy and provide a default transport if not provided
AppConfig config_copy = config;
config_copy.transport = std::make_shared<_impl::EmscriptenNetworkTransport>();
return std::make_shared<App>(Private(), config_copy);
}
return std::make_shared<App>(Private(), config);
#else
return std::make_shared<App>(Private(), config);
#endif
}

SharedApp App::get_cached_app(const std::string& app_id, const std::optional<std::string>& base_url)
Expand Down Expand Up @@ -257,11 +272,6 @@ App::App(Private, const AppConfig& config)
, m_metadata_store(create_metadata_store(config, *m_file_manager))
, m_sync_manager(SyncManager::create(config.sync_client_config))
{
#ifdef __EMSCRIPTEN__
if (!m_config.transport) {
m_config.transport = std::make_shared<_impl::EmscriptenNetworkTransport>();
}
#endif
REALM_ASSERT(m_config.transport);

// if a base url is provided, then verify the value
Expand Down
2 changes: 2 additions & 0 deletions src/realm/object-store/sync/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ class App : public std::enable_shared_from_this<App>,
private:
const AppConfig m_config;

static SharedApp make_app(const AppConfig& config);

util::CheckedMutex m_route_mutex;
// The following variables hold the different paths to Atlas, depending on the
// request being performed
Expand Down
4 changes: 2 additions & 2 deletions src/realm/sync/instruction_applier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ void InstructionApplier::operator()(const Instruction::Update& instr)
field_name, table_name, col.get_type(), mixed_ptr->get_type());
}
}
else if (const auto obj_val_ptr = mpark::get_if<Instruction::Payload::ObjectValue>(&arg)) {
else if (mpark::get_if<Instruction::Payload::ObjectValue>(&arg)) {
if (obj.is_null(col)) {
obj.create_and_set_linked_object(col);
}
}
else if (const auto erase_ptr = mpark::get_if<Instruction::Payload::Erased>(&arg)) {
else if (mpark::get_if<Instruction::Payload::Erased>(&arg)) {
m_applier->bad_transaction_log("Update: Dictionary erase at object field");
}
else if (mpark::get_if<Instruction::Payload::Dictionary>(&arg)) {
Expand Down
2 changes: 1 addition & 1 deletion src/realm/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ bool File::MapBase::try_extend_to(size_t size) noexcept
#ifndef _WIN32
char* extension_start_addr = (char*)m_addr + m_size;
size_t extension_size = size - m_size;
size_t extension_start_offset = m_offset + m_size;
size_t extension_start_offset = static_cast<size_t>(m_offset) + m_size;
#if REALM_ENABLE_ENCRYPTION
if (m_encrypted_mapping) {
void* got_addr = ::mmap(extension_start_addr, extension_size, PROT_READ | PROT_WRITE,
Expand Down
4 changes: 2 additions & 2 deletions test/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ if(UNIX AND NOT APPLE)
find_library(LIBRT rt)
if(LIBRT)
target_link_libraries(TestUtil ${LIBRT})
# Android has librt included in libc
elseif(NOT ANDROID)
# Android and Emscripten have librt included in libc
elseif(NOT ANDROID AND NOT EMSCRIPTEN)
message(WARNING "librt was not found. This means that the benchmarks will not be able to link properly.")
endif()
endif()
Loading

0 comments on commit f93e758

Please sign in to comment.