diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index bf15896bd1..408920d192 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -18,6 +18,8 @@ const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool() const hw_native_no_builtin_size_limit = 300 +const l2w_crosscc = os.find_abs_path_of_executable('x86_64-w64-mingw32-gcc-win32') or { '' } + fn main() { mut commands := get_all_commands() // summary @@ -86,6 +88,17 @@ fn get_all_commands() []Command { okmsg: 'V can compile hello world.' rmfile: 'examples/hello_world' } + $if linux { + if l2w_crosscc != '' { + res << Command{ + line: '${vexe} -os windows examples/hello_world.v' + okmsg: 'V cross compiles hello_world.v on linux, to a windows .exe file' + rmfile: 'examples/hello_world.exe' + } + } else { + eprintln('Testing cross compilation from linux to windows needs x86_64-w64-mingw32-gcc-win32. Skipping hello_world.exe test.') + } + } res << Command{ line: '${vexe} -o hhww.c examples/hello_world.v' okmsg: 'V can output a .c file, without compiling further.' @@ -270,6 +283,36 @@ fn get_all_commands() []Command { rmfile: 'str_array' } } + //////////////////////////////////////////////////////////////////////// + // Test compilation of a shared library (.so, .dll. .dylib) with -shared: + common_shared_flags := '-shared -skip-unused -d no_backtrace -o library examples/dynamic_library_loader/modules/library/library.v' + $if macos { + res << Command{ + line: '${vexe} ${common_shared_flags}' + okmsg: 'V compiles library.v with -shared on macos' + rmfile: 'library.dylib' + } + } + $if linux { + res << Command{ + line: '${vexe} ${common_shared_flags}' + okmsg: 'V compiles library.v with -shared on linux' + rmfile: 'library.so' + } + } + // Test cross compilation to windows with -shared: + $if linux { + if l2w_crosscc != '' { + res << Command{ + line: '${vexe} -os windows ${common_shared_flags}' + okmsg: 'V cross compiles library.v with -shared on linux, to a windows library.dll file' + rmfile: 'library.dll' + } + } else { + eprintln('Testing cross compilation from linux to windows needs x86_64-w64-mingw32-gcc-win32. Skipping library.dll test.') + } + } + //////////////////////////////////////////////////////////////////////// res << Command{ line: '${vexe} ${vargs} -progress test-cleancode' okmsg: 'All .v files are invariant when processed with `v fmt`' diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 22252b85ed..0a4578e73b 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -247,9 +247,6 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { // if ccoptions.debug_mode { ccoptions.args << debug_options - // $if macos { - // args << '-ferror-limit=5000' - // } } if v.pref.is_prod { // don't warn for vlib tests @@ -273,9 +270,10 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { } // ccoptions.shared_postfix = '.so' - $if macos { + if v.pref.os == .macos { ccoptions.shared_postfix = '.dylib' - } $else $if windows { + } + if v.pref.os == .windows { ccoptions.shared_postfix = '.dll' } if v.pref.is_shared { @@ -817,9 +815,6 @@ fn (mut c Builder) cc_windows_cross() { c.setup_ccompiler_options(c.pref.ccompiler) c.build_thirdparty_obj_files() c.setup_output_name() - if !c.pref.out_name.to_lower().ends_with('.exe') { - c.pref.out_name += '.exe' - } mut args := []string{} args << '${c.pref.cflags}' args << '-o ${os.quoted_path(c.pref.out_name)}' @@ -869,12 +864,14 @@ fn (mut c Builder) cc_windows_cross() { } // mut all_args := []string{} + all_args << '-std=gnu11' all_args << optimization_options all_args << debug_options - all_args << '-std=gnu11' // all_args << args + // all_args << '-municode' + all_args << c.ccoptions.linker_flags all_args << '${c.pref.ldflags}' c.dump_c_options(all_args) mut cmd := cross_compiler_name_path + ' ' + all_args.join(' ') @@ -988,7 +985,7 @@ fn missing_compiler_info() string { $if macos { return 'Install command line XCode tools with `xcode-select --install`' } - return '' + return 'Install a C compiler, like gcc or clang' } fn error_context_lines(text string, keyword string, before int, after int) []string {