From 37aff9b107e3b29a82633b063b7e54b55f16808d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 15 Jul 2019 18:32:00 +0300 Subject: [PATCH] hot reload: no -sanitize is needed anymore, -live is now enough on both Linux and MacOS X * hot reload for GL programs: force the main executable (the shared library loader) to be build with -rdynamic flag, when -live is passed to v compiler. * hot reload: optimize away a redundant load_so/0 call at the start of the reload_so thread. * hot code reload for MacOSX requires -flat_namespace flag instead of -rdynamic (on linux). --- compiler/main.v | 11 ++++++++++- examples/hot_code_reloading/bounce.v | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 4d42e408df..6b862e3157 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -390,7 +390,7 @@ int load_so(byteptr path) { cgen.genln('return 1; } void reload_so() { - int last = 0; + int last = os__file_last_mod_unix(tos2("$file")); while (1) { // TODO use inotify int now = os__file_last_mod_unix(tos2("$file")); @@ -536,6 +536,15 @@ fn (v mut V) cc() { else { a << '-g' } + if v.pref.is_live || v.pref.is_so { + // See 'man dlopen', and test running a GUI program compiled with -live + if (v.os == .linux || os.user_os() == 'linux'){ + a << '-rdynamic' + } + if (v.os == .mac || os.user_os() == 'mac'){ + a << '-flat_namespace' + } + } mut libs := ''// builtin.o os.o http.o etc if v.pref.build_mode == .build { a << '-c' diff --git a/examples/hot_code_reloading/bounce.v b/examples/hot_code_reloading/bounce.v index f4a0bd8c03..9659348baf 100644 --- a/examples/hot_code_reloading/bounce.v +++ b/examples/hot_code_reloading/bounce.v @@ -1,5 +1,5 @@ // Build this example with -// v -live -sanitize bounce.v +// v -live bounce.v module main import gx