This PR adds a function called `lean_setup_libuv` that initializes required LIBUV components. It needs to be outside of `lean_initialize_runtime_module` because it requires `argv` and `argc` to work correctly. --------- Co-authored-by: Markus Himmel <markus@lean-fro.org> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
/*
|
|
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Author: Markus Himmel, Sofia Rodrigues
|
|
*/
|
|
#include <pthread.h>
|
|
#include "runtime/libuv.h"
|
|
#include "runtime/object.h"
|
|
|
|
#ifndef LEAN_EMSCRIPTEN
|
|
#include <uv.h>
|
|
#endif
|
|
|
|
namespace lean {
|
|
|
|
#ifndef LEAN_EMSCRIPTEN
|
|
|
|
extern "C" void initialize_libuv() {
|
|
initialize_libuv_timer();
|
|
initialize_libuv_tcp_socket();
|
|
initialize_libuv_udp_socket();
|
|
initialize_libuv_loop();
|
|
|
|
lthread([]() { event_loop_run_loop(&global_ev); });
|
|
}
|
|
|
|
extern "C" LEAN_EXPORT char ** lean_setup_args(int argc, char ** argv) {
|
|
return uv_setup_args(argc, argv);
|
|
}
|
|
|
|
/* Lean.libUVVersionFn : Unit → Nat */
|
|
extern "C" LEAN_EXPORT lean_obj_res lean_libuv_version(lean_obj_arg o) {
|
|
return lean_unsigned_to_nat(uv_version());
|
|
}
|
|
|
|
#else
|
|
|
|
extern "C" void initialize_libuv() {}
|
|
|
|
extern "C" LEAN_EXPORT lean_obj_res lean_libuv_version(lean_obj_arg o) {
|
|
return lean_box(0);
|
|
}
|
|
|
|
extern "C" LEAN_EXPORT char ** lean_setup_args(int argc, char ** argv) {
|
|
return argv;
|
|
}
|
|
|
|
|
|
#endif
|
|
}
|