mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
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
This commit is contained in:
parent
0066afe7fc
commit
d373b331fa
@ -52,5 +52,5 @@ script:
|
|||||||
- |
|
- |
|
||||||
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
|
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
|
||||||
git clone https://github.com/vlang/vid
|
git clone https://github.com/vlang/vid
|
||||||
cd vid && ../v .
|
cd vid && ../v -debug -o vid .
|
||||||
fi
|
fi
|
||||||
|
162
compiler/main.v
162
compiler/main.v
@ -95,9 +95,9 @@ mut:
|
|||||||
is_debug bool // keep compiled C files
|
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)
|
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.
|
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.
|
// 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 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'.
|
// 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()`
|
// vlib can't have `init_consts()`
|
||||||
cgen.genln('void 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);
|
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
|
$consts_init_body
|
||||||
}')
|
}')
|
||||||
// _STR function can't be defined in vlib
|
// _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() {
|
fn (c mut V) cc_windows_cross() {
|
||||||
if !c.out_name.ends_with('.exe') {
|
if !c.out_name.ends_with('.exe') {
|
||||||
c.out_name = c.out_name + '.exe'
|
c.out_name = c.out_name + '.exe'
|
||||||
}
|
}
|
||||||
mut args := '-o $c.out_name -w -L. '
|
mut args := '-o $c.out_name -w -L. '
|
||||||
// -I flags
|
// -I flags
|
||||||
for flag in c.table.flags {
|
for flag in c.table.flags {
|
||||||
if !flag.starts_with('-l') {
|
if !flag.starts_with('-l') {
|
||||||
args += flag
|
args += flag
|
||||||
args += ' '
|
args += ' '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut libs := ''
|
mut libs := ''
|
||||||
if c.pref.build_mode == .default_mode {
|
if c.pref.build_mode == .default_mode {
|
||||||
libs = '"$ModPath/vlib/builtin.o"'
|
libs = '"$ModPath/vlib/builtin.o"'
|
||||||
if !os.file_exists(libs) {
|
if !os.file_exists(libs) {
|
||||||
println('`builtin.o` not found')
|
println('`builtin.o` not found')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
for imp in c.table.imports {
|
for imp in c.table.imports {
|
||||||
libs += ' "$ModPath/vlib/${imp}.o"'
|
libs += ' "$ModPath/vlib/${imp}.o"'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args += ' $c.out_name_c '
|
args += ' $c.out_name_c '
|
||||||
// -l flags (libs)
|
// -l flags (libs)
|
||||||
for flag in c.table.flags {
|
for flag in c.table.flags {
|
||||||
if flag.starts_with('-l') {
|
if flag.starts_with('-l') {
|
||||||
args += flag
|
args += flag
|
||||||
args += ' '
|
args += ' '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println('Cross compiling for Windows...')
|
println('Cross compiling for Windows...')
|
||||||
winroot := '$ModPath/winroot'
|
winroot := '$ModPath/winroot'
|
||||||
if !os.dir_exists(winroot) {
|
if !os.dir_exists(winroot) {
|
||||||
winroot_url := 'https://github.com/vlang/v/releases/download/v0.1.10/winroot.zip'
|
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')
|
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)
|
exit(1)
|
||||||
|
}
|
||||||
}
|
if c.pref.build_mode != .build {
|
||||||
mut obj_name := c.out_name
|
link_cmd := 'lld-link $obj_name $winroot/lib/libcmt.lib ' +
|
||||||
obj_name = obj_name.replace('.exe', '')
|
'$winroot/lib/libucrt.lib $winroot/lib/kernel32.lib $winroot/lib/libvcruntime.lib ' +
|
||||||
obj_name = obj_name.replace('.o.o', '.o')
|
'$winroot/lib/uuid.lib'
|
||||||
include := '-I $winroot/include '
|
if c.pref.show_c_cmd {
|
||||||
cmd := 'clang -o $obj_name -w $include -DUNICODE -D_UNICODE -m32 -c -target x86_64-win32 $ModPath/$c.out_name_c'
|
println(link_cmd)
|
||||||
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 os.system(link_cmd) != 0 {
|
if os.system(link_cmd) != 0 {
|
||||||
println('Cross compilation for Windows failed. Make sure you have lld linker installed.')
|
println('Cross compilation for Windows failed. Make sure you have lld linker installed.')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
// os.rm(obj_name)
|
// os.rm(obj_name)
|
||||||
}
|
}
|
||||||
println('Done!')
|
println('Done!')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (v mut V) cc() {
|
fn (v mut V) cc() {
|
||||||
@ -1414,13 +1418,13 @@ fn env_vflags_and_os_args() []string {
|
|||||||
mut args := []string
|
mut args := []string
|
||||||
vflags := os.getenv('VFLAGS')
|
vflags := os.getenv('VFLAGS')
|
||||||
if '' != vflags {
|
if '' != vflags {
|
||||||
args << os.args[0]
|
args << os.args[0]
|
||||||
args << vflags.split(' ')
|
args << vflags.split(' ')
|
||||||
if os.args.len > 1 {
|
if os.args.len > 1 {
|
||||||
args << os.args.right(1)
|
args << os.args.right(1)
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
args << os.args
|
args << os.args
|
||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
@ -1448,11 +1452,20 @@ fn update_v() {
|
|||||||
|
|
||||||
fn test_v() {
|
fn test_v() {
|
||||||
vexe := os.args[0]
|
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')
|
test_files := os.walk_ext('.', '_test.v')
|
||||||
for file in test_files {
|
for file in test_files {
|
||||||
print(file + ' ')
|
print(file + ' ')
|
||||||
if os.system('$vexe $file') != 0 {
|
r := os.exec('$vexe $joined_args -debug $file') or {
|
||||||
println('failed')
|
panic('failed on $file')
|
||||||
|
}
|
||||||
|
if r.exit_code != 0 {
|
||||||
|
println('failed `$file` (\n$r.output\n)')
|
||||||
exit(1)
|
exit(1)
|
||||||
} else {
|
} else {
|
||||||
println('OK')
|
println('OK')
|
||||||
@ -1462,8 +1475,11 @@ fn test_v() {
|
|||||||
examples := os.walk_ext('examples', '.v')
|
examples := os.walk_ext('examples', '.v')
|
||||||
for file in examples {
|
for file in examples {
|
||||||
print(file + ' ')
|
print(file + ' ')
|
||||||
if os.system('$vexe $file') != 0 {
|
r := os.exec('$vexe $joined_args -debug $file') or {
|
||||||
println('failed')
|
panic('failed on $file')
|
||||||
|
}
|
||||||
|
if r.exit_code != 0 {
|
||||||
|
println('failed `$file` (\n$r.output\n)')
|
||||||
exit(1)
|
exit(1)
|
||||||
} else {
|
} else {
|
||||||
println('OK')
|
println('OK')
|
||||||
|
@ -345,6 +345,8 @@ pub fn (v mut V) cc_msvc() {
|
|||||||
|
|
||||||
if !v.pref.is_prod {
|
if !v.pref.is_prod {
|
||||||
a << '/DEBUG:FULL'
|
a << '/DEBUG:FULL'
|
||||||
|
} else {
|
||||||
|
a << '/DEBUG:NONE'
|
||||||
}
|
}
|
||||||
|
|
||||||
args := a.join(' ')
|
args := a.join(' ')
|
||||||
|
@ -20,19 +20,25 @@ echo fetch v_win.c
|
|||||||
curl -O https://raw.githubusercontent.com/vlang/vc/master/v_win.c
|
curl -O https://raw.githubusercontent.com/vlang/vc/master/v_win.c
|
||||||
|
|
||||||
echo build v_win.c with msvc
|
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 (
|
if %ERRORLEVEL% GEQ 1 (
|
||||||
goto :compileerror
|
goto :compileerror
|
||||||
)
|
)
|
||||||
|
|
||||||
echo rebuild from source
|
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.obj
|
||||||
del v_win.c
|
del v_win.c
|
||||||
del v2.exe
|
del v2.exe
|
||||||
|
|
||||||
|
echo Success
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
||||||
:nomsvc
|
:nomsvc
|
||||||
|
@ -36,27 +36,20 @@ if %ERRORLEVEL% NEQ 0 goto :fail
|
|||||||
|
|
||||||
setlocal EnableDelayedExpansion
|
setlocal EnableDelayedExpansion
|
||||||
echo testing v
|
echo testing v
|
||||||
for /r . %%x in (*_test.v) do (
|
v test v
|
||||||
v -o test.exe -debug %%x
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
if !ERRORLEVEL! NEQ 0 goto :fail
|
|
||||||
)
|
|
||||||
echo testing v.msvc
|
echo testing v.msvc
|
||||||
for /r . %%x in (*_test.v) do (
|
v.msvc.exe test v
|
||||||
v.msvc.exe -o test.exe -debug %%x
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
if !ERRORLEVEL! NEQ 0 goto :fail
|
|
||||||
)
|
|
||||||
|
|
||||||
echo testing v -os msvc
|
echo testing v -os msvc
|
||||||
for /r . %%x in (*_test.v) do (
|
v -os msvc test v
|
||||||
v -os msvc -o test.exe -debug %%x
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
if !ERRORLEVEL! NEQ 0 goto :fail
|
|
||||||
)
|
|
||||||
|
|
||||||
echo testing v.msvc -os msvc
|
echo testing v.msvc -os msvc
|
||||||
for /r . %%x in (*_test.v) do (
|
v.msvc.exe -os msvc test v
|
||||||
v.msvc.exe -os msvc -o test.exe -debug %%x
|
if %ERRORLEVEL% NEQ 0 goto :fail
|
||||||
if !ERRORLEVEL! NEQ 0 goto :fail
|
|
||||||
)
|
|
||||||
|
|
||||||
goto :done
|
goto :done
|
||||||
|
|
||||||
|
BIN
vlib/json/json_test.exp
Normal file
BIN
vlib/json/json_test.exp
Normal file
Binary file not shown.
BIN
vlib/json/json_test.lib
Normal file
BIN
vlib/json/json_test.lib
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user