From cc9828b4814f4d2bc7094d83d4b5388f636343e5 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 16 Apr 2020 16:30:19 +0300 Subject: [PATCH] checker: fix building of shared .so libs --- cmd/v/v.v | 4 +++- vlib/v/checker/checker.v | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/v/v.v b/cmd/v/v.v index 2455904fea..695e502204 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -126,7 +126,9 @@ fn parse_args(args []string) (&pref.Preferences, string) { match arg { '-v' { res.is_verbose = true } '-cg' { res.is_debug = true } - '-live' { res.is_solive = true } + '-live' { res.is_live = true } + '-solive' { res.is_solive = true res.is_so = true } + '-shared' { res.is_so = true } '-autofree' { res.autofree = true } '-compress' { res.compress = true } '-freestanding' { res.is_bare = true } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index fecb8ebc28..1366b4b7b1 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -60,25 +60,29 @@ pub fn (c mut Checker) check2(ast_file ast.File) []scanner.Error { } pub fn (c mut Checker) check_files(ast_files []ast.File) { + mut all_mods := map[string]int for file in ast_files { c.check(file) + all_mods[ file.mod.name ] = all_mods[ file.mod.name ] + 1 } // Make sure fn main is defined in non lib builds if c.pref.build_mode == .build_module || c.pref.is_test { return } - if ast_files.len > 1 && ast_files[0].mod.name == 'builtin' { - // TODO hack to fix vv tests + if c.pref.is_so { + // shared libs do not need to have a main return } - for i, f in c.table.fns { - if f.name == 'main' { - return + // check that a main program has a `fn main(){}` function: + if all_mods['main'] > 0 { + for i, f in c.table.fns { + if f.name == 'main' { + return + } } + c.error('function `main` is undeclared in the main module', token.Position{}) + exit(1) } - eprintln('function `main` is undeclared in the main module') - // eprintln(ast_files[0].mod.name) - exit(1) } pub fn (c mut Checker) struct_decl(decl ast.StructDecl) {