From d02eaf28353db02fd0583e809352c99611032042 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 23 Apr 2026 19:45:46 +0300 Subject: [PATCH] pref: fix invalid option -- '-bt25' (fixes #18199) --- vlib/v/builder/cc_test.v | 16 ++++++++++++++++ vlib/v/builder/cc_windows.v | 1 + vlib/v/pref/default.v | 6 +++--- vlib/v/pref/pref_test.v | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/vlib/v/builder/cc_test.v b/vlib/v/builder/cc_test.v index c319a894b..2c1bb7cfb 100644 --- a/vlib/v/builder/cc_test.v +++ b/vlib/v/builder/cc_test.v @@ -429,6 +429,22 @@ fn test_shared_windows_builds_do_not_add_subsystem_flags() { assert !compile_args.contains('-mconsole') } +fn test_shared_tcc_compile_args_skip_bt25_after_late_compiler_resolution() { + mut full_args := [''] + full_args << ['-shared', hello_world_example()] + mut prefs, _ := pref.parse_args_and_show_errors([], full_args, false) + prefs.ccompiler = 'tcc' + prefs.ccompiler_type = .tinyc + prefs.normalize_gc_defaults_for_resolved_ccompiler() + assert 'no_backtrace' in prefs.compile_defines_all + + mut builder := new_builder(prefs) + builder.out_name_c = os.join_path(os.vtmp_dir(), 'builder_cc_test.tmp.c') + builder.setup_ccompiler_options(prefs.ccompiler) + + assert !builder.get_compile_args().contains('-bt25') +} + fn test_should_use_rsp_for_linux_by_default() { builder := new_test_builder([hello_world_example()]) assert builder.should_use_rsp(['-o', builder.out_name_c]) diff --git a/vlib/v/builder/cc_windows.v b/vlib/v/builder/cc_windows.v index 9984aa984..f31a09bf4 100644 --- a/vlib/v/builder/cc_windows.v +++ b/vlib/v/builder/cc_windows.v @@ -40,6 +40,7 @@ pub fn (mut v Builder) find_win_cc() ! { } v.pref.ccompiler = thirdparty_tcc v.pref.ccompiler_type = .tinyc + v.pref.normalize_gc_defaults_for_resolved_ccompiler() return } v.cached_msvc = msvc diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 57db5e087..1717e90d0 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -246,7 +246,6 @@ pub fn (mut p Preferences) fill_with_defaults() { } p.ccompiler_type = cc_from_string(p.ccompiler) p.normalize_gc_defaults_for_resolved_ccompiler() - p.disable_tcc_shared_backtraces() p.is_test = p.path.ends_with('_test.v') || p.path.ends_with('_test.vv') || p.path.all_before_last('.v').all_before_last('.').ends_with('_test') p.is_vsh = p.path.ends_with('.vsh') || p.raw_vsh_tmp_prefix != '' @@ -302,9 +301,10 @@ pub fn (mut p Preferences) fill_with_defaults() { } } -// normalize_gc_defaults_for_resolved_ccompiler clears stale default GC state -// after the effective C compiler has been resolved. +// normalize_gc_defaults_for_resolved_ccompiler clears stale compiler-dependent +// defaults after the effective C compiler has been resolved. pub fn (mut p Preferences) normalize_gc_defaults_for_resolved_ccompiler() { + p.disable_tcc_shared_backtraces() if p.os != .windows || p.ccompiler_type != .msvc || p.gc_set_by_flag { return } diff --git a/vlib/v/pref/pref_test.v b/vlib/v/pref/pref_test.v index 50adee0f2..f72249429 100644 --- a/vlib/v/pref/pref_test.v +++ b/vlib/v/pref/pref_test.v @@ -539,3 +539,19 @@ fn test_tcc_shared_builds_disable_backtraces() { regular_prefs.fill_with_defaults() assert 'no_backtrace' !in regular_prefs.compile_defines_all } + +fn test_late_resolved_tcc_shared_builds_disable_backtraces() { + mut shared_prefs := &pref.Preferences{ + path: 'libfoo.v' + is_shared: true + ccompiler: 'gcc' + } + shared_prefs.fill_with_defaults() + assert 'no_backtrace' !in shared_prefs.compile_defines_all + + shared_prefs.ccompiler_type = .tinyc + shared_prefs.normalize_gc_defaults_for_resolved_ccompiler() + + assert 'no_backtrace' in shared_prefs.compile_defines_all + assert shared_prefs.build_options.contains('-d no_backtrace') +} -- 2.39.5