From d373b331faf914f06a50a5cf8af3e2af0689db7d Mon Sep 17 00:00:00 2001 From: Emily Hudson Date: Sun, 18 Aug 2019 15:25:33 +0100 Subject: [PATCH] ompiler: MSVC related fixes and `v test v` for windows testing * MSVC related fixes and v test v for windows testing * If second stage crashes on windows goto error * use os.exec instead of system so that the error can be printed * use -debug for osx vid * Fix some whitespace to trigger a rebuild --- .travis.yml | 2 +- compiler/main.v | 162 ++++++++++++++++++++++------------------ compiler/msvc.v | 2 + make_msvc.bat | 10 ++- make_tests.bat | 25 +++---- vlib/json/json_test.exp | Bin 0 -> 10713 bytes vlib/json/json_test.lib | Bin 0 -> 18400 bytes 7 files changed, 109 insertions(+), 92 deletions(-) create mode 100644 vlib/json/json_test.exp create mode 100644 vlib/json/json_test.lib diff --git a/.travis.yml b/.travis.yml index ab3980600a..0b10873ec0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,5 +52,5 @@ script: - | if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then git clone https://github.com/vlang/vid - cd vid && ../v . + cd vid && ../v -debug -o vid . fi diff --git a/compiler/main.v b/compiler/main.v index d2253b4258..e49686bc0c 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -95,9 +95,9 @@ mut: is_debug bool // keep compiled C files no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers) cflags string // Additional options which will be passed to the C compiler. - // For example, passing -cflags -Os will cause the C compiler to optimize the generated binaries for size. - // You could pass several -cflags XXX arguments. They will be merged with each other. - // You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'. + // For example, passing -cflags -Os will cause the C compiler to optimize the generated binaries for size. + // You could pass several -cflags XXX arguments. They will be merged with each other. + // You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'. } @@ -427,9 +427,14 @@ void init_consts();') } // vlib can't have `init_consts()` cgen.genln('void init_consts() { -#ifdef _WIN32\n _setmode(_fileno(stdout), _O_U8TEXT); +#ifdef _WIN32 +#ifndef _BOOTSTRAP_NO_UNICODE_STREAM +_setmode(_fileno(stdout), _O_U8TEXT); SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_PROCESSED_OUTPUT | 0x0004); -// ENABLE_VIRTUAL_TERMINAL_PROCESSING\n#endif\n g_str_buf=malloc(1000); +// ENABLE_VIRTUAL_TERMINAL_PROCESSING +#endif +#endif +g_str_buf=malloc(1000); $consts_init_body }') // _STR function can't be defined in vlib @@ -684,71 +689,70 @@ fn (v V) run_compiled_executable_and_exit() { } fn (c mut V) cc_windows_cross() { - if !c.out_name.ends_with('.exe') { - c.out_name = c.out_name + '.exe' - } - mut args := '-o $c.out_name -w -L. ' - // -I flags - for flag in c.table.flags { - if !flag.starts_with('-l') { - args += flag - args += ' ' - } - } - mut libs := '' - if c.pref.build_mode == .default_mode { - libs = '"$ModPath/vlib/builtin.o"' - if !os.file_exists(libs) { - println('`builtin.o` not found') - exit(1) - } - for imp in c.table.imports { - libs += ' "$ModPath/vlib/${imp}.o"' - } - } - args += ' $c.out_name_c ' - // -l flags (libs) - for flag in c.table.flags { - if flag.starts_with('-l') { - args += flag - args += ' ' - } - } - println('Cross compiling for Windows...') - winroot := '$ModPath/winroot' + if !c.out_name.ends_with('.exe') { + c.out_name = c.out_name + '.exe' + } + mut args := '-o $c.out_name -w -L. ' + // -I flags + for flag in c.table.flags { + if !flag.starts_with('-l') { + args += flag + args += ' ' + } + } + mut libs := '' + if c.pref.build_mode == .default_mode { + libs = '"$ModPath/vlib/builtin.o"' + if !os.file_exists(libs) { + println('`builtin.o` not found') + exit(1) + } + for imp in c.table.imports { + libs += ' "$ModPath/vlib/${imp}.o"' + } + } + args += ' $c.out_name_c ' + // -l flags (libs) + for flag in c.table.flags { + if flag.starts_with('-l') { + args += flag + args += ' ' + } + } + println('Cross compiling for Windows...') + winroot := '$ModPath/winroot' if !os.dir_exists(winroot) { winroot_url := 'https://github.com/vlang/v/releases/download/v0.1.10/winroot.zip' println('"$winroot" not found. Download it from $winroot_url and save in $ModPath') + exit(1) + } + mut obj_name := c.out_name + obj_name = obj_name.replace('.exe', '') + obj_name = obj_name.replace('.o.o', '.o') + include := '-I $winroot/include ' + cmd := 'clang -o $obj_name -w $include -DUNICODE -D_UNICODE -m32 -c -target x86_64-win32 $ModPath/$c.out_name_c' + if c.pref.show_c_cmd { + println(cmd) + } + if os.system(cmd) != 0 { + println('Cross compilation for Windows failed. Make sure you have clang installed.') exit(1) - -} - mut obj_name := c.out_name - obj_name = obj_name.replace('.exe', '') - obj_name = obj_name.replace('.o.o', '.o') - include := '-I $winroot/include ' - cmd := 'clang -o $obj_name -w $include -DUNICODE -D_UNICODE -m32 -c -target x86_64-win32 $ModPath/$c.out_name_c' - if c.pref.show_c_cmd { - println(cmd) - } - if os.system(cmd) != 0 { - println('Cross compilation for Windows failed. Make sure you have clang installed.') - exit(1) - } - if c.pref.build_mode != .build { - link_cmd := 'lld-link $obj_name $winroot/lib/libcmt.lib ' + - '$winroot/lib/libucrt.lib $winroot/lib/kernel32.lib $winroot/lib/libvcruntime.lib ' + - '$winroot/lib/uuid.lib' - if c.pref.show_c_cmd { - println(link_cmd) + } + if c.pref.build_mode != .build { + link_cmd := 'lld-link $obj_name $winroot/lib/libcmt.lib ' + + '$winroot/lib/libucrt.lib $winroot/lib/kernel32.lib $winroot/lib/libvcruntime.lib ' + + '$winroot/lib/uuid.lib' + if c.pref.show_c_cmd { + println(link_cmd) } - if os.system(link_cmd) != 0 { + if os.system(link_cmd) != 0 { println('Cross compilation for Windows failed. Make sure you have lld linker installed.') - exit(1) -} - // os.rm(obj_name) - } - println('Done!') + exit(1) + } + // os.rm(obj_name) + } + println('Done!') } fn (v mut V) cc() { @@ -1414,13 +1418,13 @@ fn env_vflags_and_os_args() []string { mut args := []string vflags := os.getenv('VFLAGS') if '' != vflags { - args << os.args[0] - args << vflags.split(' ') - if os.args.len > 1 { - args << os.args.right(1) - } + args << os.args[0] + args << vflags.split(' ') + if os.args.len > 1 { + args << os.args.right(1) + } }else{ - args << os.args + args << os.args } return args } @@ -1448,11 +1452,20 @@ fn update_v() { fn test_v() { vexe := os.args[0] + // Emily: pass args from the invocation to the test + // e.g. `v -g -os msvc test v` -> `$vexe -g -os msvc $file` + mut joined_args := os.args.right(1).join(' ') + joined_args = joined_args.left(joined_args.last_index('test')) + println('$joined_args') + test_files := os.walk_ext('.', '_test.v') for file in test_files { print(file + ' ') - if os.system('$vexe $file') != 0 { - println('failed') + r := os.exec('$vexe $joined_args -debug $file') or { + panic('failed on $file') + } + if r.exit_code != 0 { + println('failed `$file` (\n$r.output\n)') exit(1) } else { println('OK') @@ -1462,8 +1475,11 @@ fn test_v() { examples := os.walk_ext('examples', '.v') for file in examples { print(file + ' ') - if os.system('$vexe $file') != 0 { - println('failed') + r := os.exec('$vexe $joined_args -debug $file') or { + panic('failed on $file') + } + if r.exit_code != 0 { + println('failed `$file` (\n$r.output\n)') exit(1) } else { println('OK') diff --git a/compiler/msvc.v b/compiler/msvc.v index 943f497d27..a7e9f69e49 100644 --- a/compiler/msvc.v +++ b/compiler/msvc.v @@ -345,6 +345,8 @@ pub fn (v mut V) cc_msvc() { if !v.pref.is_prod { a << '/DEBUG:FULL' + } else { + a << '/DEBUG:NONE' } args := a.join(' ') diff --git a/make_msvc.bat b/make_msvc.bat index 3fa2b65c14..b02d7964f5 100644 --- a/make_msvc.bat +++ b/make_msvc.bat @@ -20,19 +20,25 @@ echo fetch v_win.c curl -O https://raw.githubusercontent.com/vlang/vc/master/v_win.c echo build v_win.c with msvc -cl.exe /w /volatile:ms /D_UNICODE /DUNICODE /Fo.v_win.c.obj /O2 /MD v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /NOLOGO /OUT:v2.exe /INCREMENTAL:NO +cl.exe /w /volatile:ms /D_UNICODE /DUNICODE /D_BOOTSTRAP_NO_UNICODE_STREAM /Fo.v_win.c.obj /O2 /MD v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /DEBUG:NONE /NOLOGO /OUT:v2.exe /INCREMENTAL:NO if %ERRORLEVEL% GEQ 1 ( goto :compileerror ) echo rebuild from source -v2.exe -o v.exe compiler +v2.exe -os msvc -o v.exe compiler + +if %ERRORLEVEL% GEQ 1 ( + goto :compileerror +) del .v_win.c.obj del v_win.c del v2.exe +echo Success + exit :nomsvc diff --git a/make_tests.bat b/make_tests.bat index 7d4b63c5ae..f5f6201082 100644 --- a/make_tests.bat +++ b/make_tests.bat @@ -36,27 +36,20 @@ if %ERRORLEVEL% NEQ 0 goto :fail setlocal EnableDelayedExpansion echo testing v -for /r . %%x in (*_test.v) do ( - v -o test.exe -debug %%x - if !ERRORLEVEL! NEQ 0 goto :fail -) +v test v +if %ERRORLEVEL% NEQ 0 goto :fail + echo testing v.msvc -for /r . %%x in (*_test.v) do ( - v.msvc.exe -o test.exe -debug %%x - if !ERRORLEVEL! NEQ 0 goto :fail -) +v.msvc.exe test v +if %ERRORLEVEL% NEQ 0 goto :fail echo testing v -os msvc -for /r . %%x in (*_test.v) do ( - v -os msvc -o test.exe -debug %%x - if !ERRORLEVEL! NEQ 0 goto :fail -) +v -os msvc test v +if %ERRORLEVEL% NEQ 0 goto :fail echo testing v.msvc -os msvc -for /r . %%x in (*_test.v) do ( - v.msvc.exe -os msvc -o test.exe -debug %%x - if !ERRORLEVEL! NEQ 0 goto :fail -) +v.msvc.exe -os msvc test v +if %ERRORLEVEL% NEQ 0 goto :fail goto :done diff --git a/vlib/json/json_test.exp b/vlib/json/json_test.exp new file mode 100644 index 0000000000000000000000000000000000000000..d1d239a0b4df579d5b12a1d3157e1e182dab7124 GIT binary patch literal 10713 zcmeI2U2GiH6~|AqAs^%e8v=1c04FivKw@^+>-9Pb;KYvOg~Ty&Ftptg*4}ZlWW8&4 zXY)bR5-1;ONlQwhgaQ((P{jjnBS90xk&2h6l#9t7`jMxHEK-zG>$BX&VO0n#FRegr_ znNo2Qb0*l|=BaDPM`EF|;(bP`t<`F!I_m3oP){9Nv|@ubJ1$gG7h*hL3dejnUu)C~ z4k24E`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ane%vc@634%z9DDTnZCuQ%1#GY)yfA!i)&sYB#@ zpP*^g@eF;U~iklAG8>s(bf$c@b+=6ffXH*ePXDmZw* zq-sWA37OwlM?I1G)65mkM|I=o+o5RVrpIdBb$xl`Mvfcw8@?Y>`}*aNyvB*5^FJey dA3>e}8A0#^1!peV?@843(eFppp8GR`{{nA>Obq}4 literal 0 HcmV?d00001 diff --git a/vlib/json/json_test.lib b/vlib/json/json_test.lib new file mode 100644 index 0000000000000000000000000000000000000000..9e569ec1e1e1546fe14911992e64a2ef7e87d01c GIT binary patch literal 18400 zcmd5@4UAOP6+VloxFVn;Dxl8txBtts>sNvlNY0 zqlvM`*rr;vNhPSU4K_8_Hr8rmXlgJOtW;67Dr%u9{-jlbSZbx`y!+mpbKbo(%s5NZ zNzT4^&pqdU_n!N6?mhQyNn-u5RvA#&lw%T+ApGdWL zE2=NUdLhllvWaRs6xE)@e5AVFHX%kGQuTU8^P&Jm^Pf;O?;xg;s`n|Xor3yEb9X4J zc^1n>n%|(P>`efo@=lwuz2!)ySO!tqwTc!T10V|AtjIqWfG9vb%8M!TW4=Wv@QKv8 zMbYvn0f^cb+4K}Xk(O5|YCwIWDlChr8TmvN0Yz1}As?x9qoO$|Lsap&qN-xdN2=Ur zlMkOrb8b=8UV-BVX+_E=lwDEW-ydAvy{4zHzioMMYfrGdZ%t4Crer+Up9&{a(BI#6 zb!Vq80=K#{N}_M&)m^Ll+nW2DQ75u_xPPFdcTHFS+HfKniN`>uxI{1(Nv({>Z%EoQ z=`@$>4keOdTSC2Sx!;MTHm(^?IptVVE>B1&BC(WHmi4aXUL6~XCpL#tsqi2d!usU%jmk%a`u`Qu!#2E(Zw3KQOMcwfkOsbTW=u5bG z!K9Ut`7QBy)UJFmX(eQS*GM#-Zza6>n>U1=<_D8qBUVz%s8+ftc2de%gUA(8DJh{k z#uc%XQl=;LJy(FhcR?HW;Z3L*-o)}4{(lNBD1s-)U2)8wh7hJC0Kfy z!m>)%U|p4wwoN*%m&p4;$?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