Skip to content

Commit 2269cbd

Browse files
committed
builder: fix cross compilation with shared argument fails (fixes #17608)
(cherry picked from commit e592c6ac5f299a255811cc63df0429b1fd0bf49c)
1 parent 0efdeaf commit 2269cbd

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

vlib/v/builder/cc.v

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,10 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
826826
}
827827
}
828828
if v.pref.os == .windows {
829-
ccoptions.post_args << v.get_subsystem_flag()
829+
subsystem_flag := v.get_subsystem_flag()
830+
if subsystem_flag != '' {
831+
ccoptions.post_args << subsystem_flag
832+
}
830833
}
831834
ccoptions.env_cflags = os.getenv('CFLAGS').replace('\n', ' ')
832835
ccoptions.env_ldflags = os.getenv('LDFLAGS').replace('\n', ' ')
@@ -1592,6 +1595,9 @@ fn (mut b Builder) ensure_freebsdroot_exists(sysroot string) {
15921595
}
15931596

15941597
fn (mut b Builder) get_subsystem_flag() string {
1598+
if b.pref.is_shared || b.pref.build_mode == .build_module || b.pref.is_o {
1599+
return ''
1600+
}
15951601
return match b.pref.subsystem {
15961602
.auto { '-municode' }
15971603
.console { '-municode -mconsole' }
@@ -1906,7 +1912,10 @@ fn (mut c Builder) cc_windows_cross() {
19061912
all_args << debug_options
19071913

19081914
all_args << args
1909-
all_args << c.get_subsystem_flag()
1915+
subsystem_flag := c.get_subsystem_flag()
1916+
if subsystem_flag != '' {
1917+
all_args << subsystem_flag
1918+
}
19101919
all_args << c.pref.ldflags
19111920
c.dump_c_options(all_args)
19121921
mut cmd := cross_compiler_name_path + ' ' + all_args.join(' ')

vlib/v/builder/cc_test.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ fn test_live_windows_shared_linker_args_include_host_import_lib() {
314314
assert linker_args.contains(live_windows_import_lib_path(hot_reload_graph_example()))
315315
}
316316

317+
fn test_shared_windows_builds_do_not_add_subsystem_flags() {
318+
mut builder := new_test_builder(['-os', 'windows', '-shared', hello_world_example()])
319+
assert builder.get_subsystem_flag() == ''
320+
compile_args := builder.get_compile_args().join(' ')
321+
assert !compile_args.contains('-municode')
322+
assert !compile_args.contains('-mwindows')
323+
assert !compile_args.contains('-mconsole')
324+
}
325+
317326
fn test_should_use_rsp_for_linux_by_default() {
318327
builder := new_test_builder([hello_world_example()])
319328
assert builder.should_use_rsp(['-o', builder.out_name_c])

0 commit comments

Comments
 (0)