checker: allow for module no_main programs, that can redefine their own main function, or not define any of their own as well

This commit is contained in:
Delyan Angelov 2025-02-12 00:49:52 +02:00
parent 126f5c24e4
commit a4101f4ed8
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -324,6 +324,7 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
// println('check_files')
// c.files = ast_files
mut has_main_mod_file := false
mut has_no_main_mod_file := false
mut has_main_fn := false
unsafe {
mut files_from_main_module := []&ast.File{}
@ -331,6 +332,9 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
mut file := ast_files[i]
c.timers.start('checker_check ${file.path}')
c.check(mut file)
if file.mod.name == 'no_main' {
has_no_main_mod_file = true
}
if file.mod.name == 'main' {
files_from_main_module << file
has_main_mod_file = true
@ -446,6 +450,9 @@ pub fn (mut c Checker) check_files(ast_files []&ast.File) {
// This is useful for compiling linux kernel modules for example.
return
}
if has_no_main_mod_file {
return
}
if !has_main_mod_file {
c.error('project must include a `main` module or be a shared library (compile with `v -shared`)',
token.Pos{})