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 0000000000..d1d239a0b4 Binary files /dev/null and b/vlib/json/json_test.exp differ diff --git a/vlib/json/json_test.lib b/vlib/json/json_test.lib new file mode 100644 index 0000000000..9e569ec1e1 Binary files /dev/null and b/vlib/json/json_test.lib differ