| 1 | module builder |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | fn execute_without_vflags(cmd string) os.Result { |
| 6 | old_vflags := os.getenv_opt('VFLAGS') |
| 7 | os.unsetenv('VFLAGS') |
| 8 | res := os.execute(cmd) |
| 9 | if vflags := old_vflags { |
| 10 | os.setenv('VFLAGS', vflags, true) |
| 11 | } else { |
| 12 | os.unsetenv('VFLAGS') |
| 13 | } |
| 14 | return res |
| 15 | } |
| 16 | |
| 17 | fn test_macos_tcc_boehm_uses_bundled_libgc() { |
| 18 | $if !macos { |
| 19 | return |
| 20 | } |
| 21 | $if arm64 { |
| 22 | // TCC on macOS arm64 cannot link the i386/asm path that this test exercises. |
| 23 | return |
| 24 | } |
| 25 | exe_path := os.join_path(os.vtmp_dir(), 'builder_gc_flags_test') |
| 26 | source_path := os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 27 | cmd := '${os.quoted_path(@VEXE)} -showcc -cc tcc -no-retry-compilation -o ${os.quoted_path(exe_path)} ${os.quoted_path(source_path)}' |
| 28 | res := execute_without_vflags(cmd) |
| 29 | defer { |
| 30 | os.rm(exe_path) or {} |
| 31 | } |
| 32 | assert res.exit_code == 0 |
| 33 | // macOS amd64 tccbin only ships libgc.a (no .dylib). |
| 34 | assert res.output.contains('thirdparty/tcc/lib/libgc.a') |
| 35 | assert !res.output.contains(' -lgc') |
| 36 | } |
| 37 | |
| 38 | fn test_linux_musl_tcc_boehm_uses_system_libgc() { |
| 39 | $if !linux { |
| 40 | return |
| 41 | } |
| 42 | source_path := os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 43 | cmd := '${os.quoted_path(@VEXE)} -dump-c-flags - -cc tcc -musl ${os.quoted_path(source_path)}' |
| 44 | res := execute_without_vflags(cmd) |
| 45 | assert res.exit_code == 0, res.output |
| 46 | assert res.output.contains('-lgc') |
| 47 | assert !res.output.contains('thirdparty/tcc/lib/libgc.a') |
| 48 | } |
| 49 | |
| 50 | fn test_no_gc_thread_local_alloc_uses_source_libgc_without_tla_define() { |
| 51 | source_path := os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 52 | cmd := '${os.quoted_path(@VEXE)} -dump-c-flags - -d no_gc_thread_local_alloc ${os.quoted_path(source_path)}' |
| 53 | res := execute_without_vflags(cmd) |
| 54 | assert res.exit_code == 0, res.output |
| 55 | normalized := res.output.replace('\\', '/') |
| 56 | assert !normalized.contains('thirdparty/tcc/lib/libgc') |
| 57 | assert !normalized.contains('\n-lgc\n') |
| 58 | assert normalized.contains('-D GC_THREADS=1') |
| 59 | assert !normalized.contains('THREAD_LOCAL_ALLOC') |
| 60 | } |
| 61 | |