From 3b9651d8c92764a36c7963ca9f2bafae32277f7f Mon Sep 17 00:00:00 2001 From: Stanislav Ershov Date: Tue, 1 Oct 2024 18:30:22 +0500 Subject: [PATCH] v.builder: fix build using msvc with multiple C sources (for example programs using `#flag file.c`) (#22377) --- vlib/v/builder/msvc_windows.v | 6 +----- .../c/testdata/building_multiple_c_sources.out | 4 ++++ .../c/testdata/building_multiple_c_sources.vv | 5 +++++ .../v/gen/c/testdata/multiple_c_cources/common.h | 3 +++ vlib/v/gen/c/testdata/multiple_c_cources/file1.c | 1 + vlib/v/gen/c/testdata/multiple_c_cources/file2.c | 1 + .../gen/c/testdata/multiple_c_cources/sources.v | 16 ++++++++++++++++ vlib/v/gen/c/testdata/multiple_c_cources/v.mod | 0 8 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 vlib/v/gen/c/testdata/building_multiple_c_sources.out create mode 100644 vlib/v/gen/c/testdata/building_multiple_c_sources.vv create mode 100644 vlib/v/gen/c/testdata/multiple_c_cources/common.h create mode 100644 vlib/v/gen/c/testdata/multiple_c_cources/file1.c create mode 100644 vlib/v/gen/c/testdata/multiple_c_cources/file2.c create mode 100644 vlib/v/gen/c/testdata/multiple_c_cources/sources.v create mode 100644 vlib/v/gen/c/testdata/multiple_c_cources/v.mod diff --git a/vlib/v/builder/msvc_windows.v b/vlib/v/builder/msvc_windows.v index ad4e2b2a5..fb75c4716 100644 --- a/vlib/v/builder/msvc_windows.v +++ b/vlib/v/builder/msvc_windows.v @@ -254,7 +254,6 @@ pub fn (mut v Builder) cc_msvc() { if r.valid == false { verror('cannot find MSVC on this OS') } - out_name_obj := os.real_path(v.out_name_c + '.obj') out_name_pdb := os.real_path(v.out_name_c + '.pdb') out_name_cmd_line := os.real_path(v.out_name_c + '.rsp') mut a := []string{} @@ -269,9 +268,8 @@ pub fn (mut v Builder) cc_msvc() { // `-w` no warnings // `/we4013` 2 unicode defines, see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013?redirectedfrom=MSDN&view=msvc-170 // `/volatile:ms` enables atomic volatile (gcc _Atomic) - // `/Fo` sets the object file name - needed so we can clean up after ourselves properly // `/F 16777216` changes the stack size to 16MB, see https://docs.microsoft.com/en-us/cpp/build/reference/f-set-stack-size?view=msvc-170 - a << ['-w', '/we4013', '/volatile:ms', '/Fo"${out_name_obj}"', '/F 16777216'] + a << ['-w', '/we4013', '/volatile:ms', '/F 16777216'] if v.pref.is_prod { a << '/O2' } @@ -383,8 +381,6 @@ pub fn (mut v Builder) cc_msvc() { } // println(res) // println('C OUTPUT:') - // Always remove the object file - it is completely unnecessary - os.rm(out_name_obj) or {} } fn (mut v Builder) build_thirdparty_obj_file_with_msvc(mod string, path string, moduleflags []cflag.CFlag) { diff --git a/vlib/v/gen/c/testdata/building_multiple_c_sources.out b/vlib/v/gen/c/testdata/building_multiple_c_sources.out new file mode 100644 index 000000000..60fb47224 --- /dev/null +++ b/vlib/v/gen/c/testdata/building_multiple_c_sources.out @@ -0,0 +1,4 @@ +start +123 +456 +done diff --git a/vlib/v/gen/c/testdata/building_multiple_c_sources.vv b/vlib/v/gen/c/testdata/building_multiple_c_sources.vv new file mode 100644 index 000000000..5e81381b2 --- /dev/null +++ b/vlib/v/gen/c/testdata/building_multiple_c_sources.vv @@ -0,0 +1,5 @@ +import multiple_c_cources + +fn main() { + multiple_c_cources.call_c_functions() +} diff --git a/vlib/v/gen/c/testdata/multiple_c_cources/common.h b/vlib/v/gen/c/testdata/multiple_c_cources/common.h new file mode 100644 index 000000000..b10e60690 --- /dev/null +++ b/vlib/v/gen/c/testdata/multiple_c_cources/common.h @@ -0,0 +1,3 @@ + +int f1(); +int f2(); diff --git a/vlib/v/gen/c/testdata/multiple_c_cources/file1.c b/vlib/v/gen/c/testdata/multiple_c_cources/file1.c new file mode 100644 index 000000000..d9ae838bd --- /dev/null +++ b/vlib/v/gen/c/testdata/multiple_c_cources/file1.c @@ -0,0 +1 @@ +int f1() { return 123; } diff --git a/vlib/v/gen/c/testdata/multiple_c_cources/file2.c b/vlib/v/gen/c/testdata/multiple_c_cources/file2.c new file mode 100644 index 000000000..cccf95ab6 --- /dev/null +++ b/vlib/v/gen/c/testdata/multiple_c_cources/file2.c @@ -0,0 +1 @@ +int f2() { return 456; } diff --git a/vlib/v/gen/c/testdata/multiple_c_cources/sources.v b/vlib/v/gen/c/testdata/multiple_c_cources/sources.v new file mode 100644 index 000000000..64cdc84fc --- /dev/null +++ b/vlib/v/gen/c/testdata/multiple_c_cources/sources.v @@ -0,0 +1,16 @@ +module multiple_c_cources + +#flag @VMODROOT/file1.c +#flag @VMODROOT/file2.c + +#include "@VMODROOT/common.h" + +fn C.f1() int +fn C.f2() int + +pub fn call_c_functions() { + println('start') + println(C.f1()) + println(C.f2()) + println('done') +} diff --git a/vlib/v/gen/c/testdata/multiple_c_cources/v.mod b/vlib/v/gen/c/testdata/multiple_c_cources/v.mod new file mode 100644 index 000000000..e69de29bb -- 2.39.5