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 {
'-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 }

View File

@ -60,26 +60,30 @@ 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
}
// 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
}
}
eprintln('function `main` is undeclared in the main module')
// eprintln(ast_files[0].mod.name)
c.error('function `main` is undeclared in the main module', token.Position{})
exit(1)
}
}
pub fn (c mut Checker) struct_decl(decl ast.StructDecl) {
splitted_full_name := decl.name.split('.')