checker: fix building of shared .so libs

pull/4447/head
Delyan Angelov 2020-04-16 16:30:19 +03:00
parent e05f103c41
commit cc9828b481
2 changed files with 15 additions and 9 deletions

View File

@ -126,7 +126,9 @@ fn parse_args(args []string) (&pref.Preferences, string) {
match arg { match arg {
'-v' { res.is_verbose = true } '-v' { res.is_verbose = true }
'-cg' { res.is_debug = 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 } '-autofree' { res.autofree = true }
'-compress' { res.compress = true } '-compress' { res.compress = true }
'-freestanding' { res.is_bare = true } '-freestanding' { res.is_bare = true }

View File

@ -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) { pub fn (c mut Checker) check_files(ast_files []ast.File) {
mut all_mods := map[string]int
for file in ast_files { for file in ast_files {
c.check(file) c.check(file)
all_mods[ file.mod.name ] = all_mods[ file.mod.name ] + 1
} }
// Make sure fn main is defined in non lib builds // Make sure fn main is defined in non lib builds
if c.pref.build_mode == .build_module || c.pref.is_test { if c.pref.build_mode == .build_module || c.pref.is_test {
return return
} }
if ast_files.len > 1 && ast_files[0].mod.name == 'builtin' { if c.pref.is_so {
// TODO hack to fix vv tests // shared libs do not need to have a main
return return
} }
for i, f in c.table.fns { // check that a main program has a `fn main(){}` function:
if f.name == 'main' { if all_mods['main'] > 0 {
return 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) { pub fn (c mut Checker) struct_decl(decl ast.StructDecl) {