| 1 | // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | module builder |
| 5 | |
| 6 | import os |
| 7 | import v.pref |
| 8 | |
| 9 | pub fn (mut v Builder) find_win_cc() ! { |
| 10 | $if !windows { |
| 11 | return |
| 12 | } |
| 13 | if v.pref.ccompiler_set_by_flag && v.pref.ccompiler != 'msvc' { |
| 14 | if !ccompiler_is_available(v.pref.ccompiler) { |
| 15 | return error('C compiler `${v.pref.ccompiler}` was requested with `-cc`, but was not found.') |
| 16 | } |
| 17 | v.pref.ccompiler_type = pref.cc_from_string(v.pref.ccompiler) |
| 18 | v.pref.normalize_gc_defaults_for_resolved_ccompiler() |
| 19 | return |
| 20 | } |
| 21 | cmd_version := '${v.quote_compiler_name(v.pref.ccompiler)} -v' |
| 22 | ccompiler_version_res := os.execute(cmd_version) |
| 23 | if ccompiler_version_res.exit_code != 0 { |
| 24 | if v.pref.is_verbose { |
| 25 | println('failed command: `${cmd_version}`') |
| 26 | println('${v.pref.ccompiler} not found, looking for msvc...') |
| 27 | } |
| 28 | if !v.cached_msvc.valid { |
| 29 | msvc := find_msvc(v.pref.m64) or { |
| 30 | if v.pref.is_verbose { |
| 31 | println('msvc not found, looking for thirdparty/tcc...') |
| 32 | } |
| 33 | thirdparty_tcc := os.join_path(v.pref.vroot, 'thirdparty', 'tcc', 'tcc.exe') |
| 34 | tcc_version_res := os.execute('${os.quoted_path(thirdparty_tcc)} -v') |
| 35 | if tcc_version_res.exit_code != 0 { |
| 36 | if v.pref.is_verbose { |
| 37 | println('tcc not found') |
| 38 | } |
| 39 | return error('tcc not found') |
| 40 | } |
| 41 | v.pref.ccompiler = thirdparty_tcc |
| 42 | v.pref.ccompiler_type = .tinyc |
| 43 | v.pref.normalize_gc_defaults_for_resolved_ccompiler() |
| 44 | return |
| 45 | } |
| 46 | v.cached_msvc = msvc |
| 47 | } |
| 48 | v.pref.ccompiler = 'msvc' |
| 49 | v.pref.ccompiler_type = .msvc |
| 50 | v.pref.normalize_gc_defaults_for_resolved_ccompiler() |
| 51 | return |
| 52 | } |
| 53 | v.pref.ccompiler_type = pref.cc_from_string(v.pref.ccompiler) |
| 54 | v.pref.normalize_gc_defaults_for_resolved_ccompiler() |
| 55 | } |
| 56 | |