1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: always define _UNICODE and UNICODE on Windows

This commit is contained in:
vitalyster 2019-09-17 14:56:32 +03:00 committed by Alexander Medvednikov
parent 79a98d7bcf
commit 52c5f0172e
6 changed files with 12 additions and 16 deletions

View File

@ -12,7 +12,7 @@ all:
rm -rf vc/ rm -rf vc/
git clone --depth 1 --quiet https://github.com/vlang/vc git clone --depth 1 --quiet https://github.com/vlang/vc
ifdef WIN32 ifdef WIN32
$(CC) -std=gnu11 -DUNICODE -D_UNICODE -w -o v0.exe vc/v_win.c $(CC) -std=gnu11 -w -o v0.exe vc/v_win.c
./v0.exe -o v.exe compiler ./v0.exe -o v.exe compiler
else else
$(CC) -std=gnu11 -o v vc/v.c -lm $(CC) -std=gnu11 -o v vc/v.c -lm

View File

@ -173,9 +173,6 @@ fn (v mut V) cc() {
a << '-lm' a << '-lm'
} }
if v.os == .windows {
a << '-DUNICODE -D_UNICODE'
}
args := a.join(' ') args := a.join(' ')
cmd := '${v.pref.ccompiler} $args' cmd := '${v.pref.ccompiler} $args'
// Run // Run
@ -292,7 +289,7 @@ fn (c mut V) cc_windows_cross() {
obj_name = obj_name.replace('.exe', '') obj_name = obj_name.replace('.exe', '')
obj_name = obj_name.replace('.o.o', '.o') obj_name = obj_name.replace('.o.o', '.o')
include := '-I $winroot/include ' 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' cmd := 'clang -o $obj_name -w $include -m32 -c -target x86_64-win32 $ModPath/$c.out_name_c'
if c.pref.show_c_cmd { if c.pref.show_c_cmd {
println(cmd) println(cmd)
} }

View File

@ -49,6 +49,8 @@ CommonCHeaders = '
#ifdef _WIN32 #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define _UNICODE
#define UNICODE
#include <windows.h> #include <windows.h>
// must be included after <windows.h> // must be included after <windows.h>

View File

@ -333,12 +333,10 @@ fn (v mut V) generate_main() {
// vlib can't have `init_consts()` // vlib can't have `init_consts()`
cgen.genln('void init_consts() { cgen.genln('void init_consts() {
#ifdef _WIN32 #ifdef _WIN32
#ifndef _BOOTSTRAP_NO_UNICODE_STREAM
_setmode(_fileno(stdout), _O_U8TEXT); _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 // ENABLE_VIRTUAL_TERMINAL_PROCESSING
#endif #endif
#endif
g_str_buf=malloc(1000); g_str_buf=malloc(1000);
$consts_init_body $consts_init_body
}') }')

View File

@ -225,7 +225,7 @@ pub fn (v mut V) cc_msvc() {
// -w: no warnings // -w: no warnings
// 2 unicode defines // 2 unicode defines
// /Fo sets the object file name - needed so we can clean up after ourselves properly // /Fo sets the object file name - needed so we can clean up after ourselves properly
mut a := ['-w', '/we4013', '/volatile:ms', '/D_UNICODE', '/DUNICODE', '/Fo"$out_name_obj"'] mut a := ['-w', '/we4013', '/volatile:ms', '/Fo"$out_name_obj"']
if v.pref.is_prod { if v.pref.is_prod {
a << '/O2' a << '/O2'
@ -430,7 +430,7 @@ fn build_thirdparty_obj_file_with_msvc(path string) {
//println('cfiles: $cfiles') //println('cfiles: $cfiles')
cmd := '""$msvc.full_cl_exe_path" /volatile:ms /Z7 $include_string /c $cfiles /Fo"$obj_path" /D_UNICODE /DUNICODE"' cmd := '""$msvc.full_cl_exe_path" /volatile:ms /Z7 $include_string /c $cfiles /Fo"$obj_path""'
//NB: the quotes above ARE balanced. //NB: the quotes above ARE balanced.
println('thirdparty cmd line: $cmd') println('thirdparty cmd line: $cmd')
res := os.exec(cmd) or { res := os.exec(cmd) or {

View File

@ -28,15 +28,15 @@ if not exist "%gccpath%" (
goto:msvcstrap goto:msvcstrap
) )
gcc -std=gnu11 -DUNICODE -D_UNICODE -w -o v2.exe vc\v_win.c gcc -DUNICODE -D_UNICODE -std=gnu11 -w -o v2.exe vc\v_win.c
if %ERRORLEVEL% GEQ 1 ( if %ERRORLEVEL% NEQ 0 (
echo gcc failed to compile - Create an issue at 'https://github.com/vlang' echo gcc failed to compile - Create an issue at 'https://github.com/vlang'
exit /b 1 exit /b 1
) )
echo Building v.v... echo Building v.v...
v2.exe -o v.exe compiler v2.exe -o v.exe compiler
if %ERRORLEVEL% GEQ 1 ( if %ERRORLEVEL% NEQ 0 (
echo v.exe failed to compile itself - Create an issue at 'https://github.com/vlang' echo v.exe failed to compile itself - Create an issue at 'https://github.com/vlang'
exit /b 1 exit /b 1
) )
@ -60,16 +60,15 @@ if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
goto :nocompiler goto :nocompiler
) )
cl.exe /nologo /w /volatile:ms /D_UNICODE /DUNICODE /Fo.v.c.obj /O2 /MD vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /NOLOGO /OUT:v2.exe /INCREMENTAL:NO cl.exe -DUNICODE -D_UNICODE /nologo /w /volatile:ms /Fo.v.c.obj /O2 /MD vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /NOLOGO /OUT:v2.exe /INCREMENTAL:NO
if %ERRORLEVEL% NEQ 0 (
if %ERRORLEVEL% GEQ 1 (
echo cl.exe failed to build V echo cl.exe failed to build V
goto :compileerror goto :compileerror
) )
echo rebuild from source echo rebuild from source
v2.exe -os msvc -o v.exe compiler v2.exe -os msvc -o v.exe compiler
if %ERRORLEVEL% GEQ 1 ( if %ERRORLEVEL% NEQ 0 (
echo V failed to build itself echo V failed to build itself
goto :compileerror goto :compileerror
) )