@@ -34,30 +34,61 @@ fn main() {
3434 mut executables := []string {}
3535 mut failed_commands := []string {}
3636 mut project_folders := map [string ]bool {}
37+ mut skipped_files := []string {}
3738 for idx, example in files {
3839 folder_of_example := os.dir (example)
3940 if os.is_file (os.join_path_single (folder_of_example, '.skip_should_compile_all' )) {
4041 log.info ('>>> skipping file: ${example }, because a `.skip_should_compile_all` file is present next to it.' )
42+ skipped_files << example
4143 continue
4244 }
45+ // project folders usually contain many .v files, that are *all* part of the same program.
46+ // NOTE: => projects should be compiled with `v project/`.
47+ // To do that, just record the presence of such a folder for now, and try to compile it separately later.
4348 if project_folders[folder_of_example] {
49+ skipped_files << example
4450 continue
4551 }
4652 if os.is_file (os.join_path_single (folder_of_example, 'v.mod' )) {
4753 log.info ('>>> delaying compilation of entire project folder ${folder_of_example } ...' )
4854 project_folders[folder_of_example] = true
55+ skipped_files << example
4956 continue
5057 }
51- cmd := '${os .quoted_path (@VEXE )} ${os .quoted_path (example )}'
52- log.info ('> compiling ${idx + 1 :4 }/${files .len :- 4 }: ${cmd }' )
58+ //
59+ mut backend_options := '-b c'
60+ if example.ends_with ('.wasm.v' ) {
61+ backend_options = '-b wasm -os browser'
62+ }
63+ if example.ends_with ('.js.v' ) {
64+ backend_options = '-b js'
65+ }
66+ lines := os.read_lines (example)! #[..50 ].filter (it .starts_with ('module' ))
67+ if lines.len > 0 && lines[0 ] != 'module main' {
68+ log.info ('>>> skipping non main module file: ${example }' )
69+ skipped_files << example
70+ continue
71+ }
72+ cmd := '${os .quoted_path (@VEXE )} ${backend_options } ${os .quoted_path (example )}'
73+ log.info ('> compiling program ${idx + 1 :4 }/${files .len :- 4 }: ${cmd }' )
5374 if 0 != os.system (cmd) {
5475 failed_commands << cmd
5576 } else {
5677 executables << executable_name (example)
5778 }
5879 }
80+
81+ mut glsl_folders := map [string ]bool {}
5982 mut pfi := 0
6083 for pf, _ in project_folders {
84+ glsl_files := os.glob (os.join_path (pf, '*.glsl' ))!
85+ if glsl_files.len > 0 {
86+ if pf ! in glsl_folders {
87+ log.debug ('>>> found .glsl files in ${pf } ... running `v shader ${pf }` ...' )
88+ os.system ('${os .quoted_path (@VEXE )} shader ${os .quoted_path (pf )}' )
89+ glsl_folders[pf] = true
90+ }
91+ }
6192 exe_path := os.join_path (pf, os.file_name (pf) + exe_extension)
6293 cmd := '${os .quoted_path (@VEXE )} -o ${exe_path } ${pf }'
6394 log.info ('> compiling project ${pfi + 1 :4 }/${project_folders .len :- 4 }: ${cmd }' )
@@ -68,6 +99,7 @@ fn main() {
6899 }
69100 pfi++
70101 }
102+
71103 if should_clean {
72104 log.info ('Removing ${executables .len } successfully build executables...' )
73105 for f in executables {
@@ -81,7 +113,7 @@ fn main() {
81113 log.info ('Summary: ${failed_commands .len :4 }/${files .len :- 4 } file(s) failed to compile.' )
82114 exit (1 )
83115 }
84- log.info ('Summary: all ${files .len } file(s) compiled successfully.' )
116+ log.info ('Summary: all ${files .len } program file(s), and ${ project_folders . len } project(s) compiled successfully. Skipped files: ${ skipped_files . len } .' )
85117}
86118
87119const exe_extension = if os.user_os () == 'windows' {
0 commit comments