From 8193efb3793bd26609ca6cedcbe51db83680e894 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 12 Apr 2021 09:24:07 +0300 Subject: [PATCH] v.markused: mark all `pub` functions on `-shared -skip-unused` --- examples/dynamic_library_loading/use_test.v | 42 +++++++++++---------- vlib/v/markused/markused.v | 4 ++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/examples/dynamic_library_loading/use_test.v b/examples/dynamic_library_loading/use_test.v index e468cc1d28..7d98d5362c 100644 --- a/examples/dynamic_library_loading/use_test.v +++ b/examples/dynamic_library_loading/use_test.v @@ -11,20 +11,19 @@ const ( ) fn test_vexe() { - dump(vexe) + // dump(vexe) assert vexe != '' - dump(os.executable()) - dump(@FILE) - dump(cfolder) - dump(so_ext) - dump(library_file_name) + // dump(os.executable()) + // dump(@FILE) + // dump(cfolder) + // dump(so_ext) + // dump(library_file_name) } fn test_can_compile_library() { os.chdir(cfolder) - os.rm(library_file_name) or { } - res := v_compile('-d no_backtrace -o library -shared modules/library/library.v') - dump(res) + os.rm(library_file_name) or {} + v_compile('-d no_backtrace -o library -shared modules/library/library.v') assert os.is_file(library_file_name) } @@ -32,21 +31,26 @@ fn test_can_compile_main_program() { os.chdir(cfolder) assert os.is_file(library_file_name) result := v_compile('run use.v') - dump(result) + // dump(result) assert result.output.contains('res: 4') - os.rm(library_file_name) or { } + os.rm(library_file_name) or {} +} + +fn test_can_compile_and_use_library_with_skip_unused() { + os.chdir(cfolder) + os.rm(library_file_name) or {} + v_compile('-skip-unused -d no_backtrace -o library -shared modules/library/library.v') + assert os.is_file(library_file_name) + result := v_compile('run use.v') + assert result.output.contains('res: 4') + os.rm(library_file_name) or {} } fn v_compile(vopts string) os.Result { cmd := '"$vexe" -showcc $vopts' - dump(cmd) + // dump(cmd) res := os.execute_or_panic(cmd) - dump(res) - // assert res.exit_code == 0 - $if windows { - os.system('dir $cfolder /a') - } $else { - os.system('ls -al $cfolder') - } + // dump(res) + assert res.exit_code == 0 return res } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 5d1e03e522..ec208303f5 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -143,6 +143,10 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.Fi continue } } + if mfn.is_pub && pref.is_shared { + all_fn_root_names << k + continue + } } if pref.is_debug { all_fn_root_names << 'panic_debug'