compiler: move msvc compiler to -cc flag instead of -os (#2338)

* move msvc to -cc flag instead of -os

* undo unrelated change

* do first build without msvc

* remvove flags temp

* fix comment
pull/2339/head
joe-conigliaro 2019-10-14 16:41:46 +11:00 committed by GitHub
parent 093d8a2b00
commit 9a2b8a0814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 37 additions and 36 deletions

View File

@ -85,14 +85,14 @@ jobs:
# with:
# node-version: 12.x
- name: Build
env:
VFLAGS: -os msvc
#env:
# VFLAGS: -cc msvc
run: |
git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries.git thirdparty/freetype/
.\make.bat -msvc
- name: Test
env:
VFLAGS: -os msvc
#env:
# VFLAGS: -cc msvc
run: |
.\v.exe test v
## v.js dosent work on windows

View File

@ -45,12 +45,11 @@ script:
if [[ "${TRAVIS_JOB_NAME}" == "windows_gcc" ]]; then
gcc --version
echo "Building V with GCC"
export VFLAGS="-os windows"
./make.bat -gcc
fi
if [[ "${TRAVIS_JOB_NAME}" == "windows_msvc" ]]; then
echo "Building V with MSVC"
export VFLAGS="-os msvc"
#export VFLAGS="-cc msvc"
./make.bat -msvc
fi

Binary file not shown.

View File

@ -69,8 +69,8 @@ if %ERRORLEVEL% NEQ 0 (
)
echo rebuild from source (twice, in case of C definitions changes)
v2.exe -os msvc -o v3.exe v.v
v3.exe -os msvc -o v.exe -prod v.v
v2.exe -o v3.exe v.v
v3.exe -cc msvc -o v.exe -prod v.v
if %ERRORLEVEL% NEQ 0 (
echo V failed to build itself
goto :compileerror

View File

@ -48,7 +48,7 @@ fn (v mut V) cc() {
}
}
$if windows {
if v.os == .msvc {
if v.pref.ccompiler == 'msvc' {
v.cc_msvc()
return
}
@ -119,7 +119,7 @@ fn (v mut V) cc() {
a << ' -rdynamic ' // needed for nicer symbolic backtraces
}
if v.os != .msvc && v.os != .freebsd {
if v.pref.ccompiler != 'msvc' && v.os != .freebsd {
a << '-Werror=implicit-function-declaration'
}
@ -314,7 +314,11 @@ fn (c mut V) cc_windows_cross() {
mut args := '-o $c.out_name -w -L. '
cflags := c.get_os_cflags()
// -I flags
args += cflags.c_options_before_target()
args += if c.pref.ccompiler == 'msvc' {
cflags.c_options_before_target_msvc()
} else {
cflags.c_options_before_target()
}
mut libs := ''
if c.pref.build_mode == .default_mode {
libs = '"$v_modules_path/vlib/builtin.o"'
@ -327,7 +331,11 @@ fn (c mut V) cc_windows_cross() {
}
}
args += ' $c.out_name_c '
args += cflags.c_options_after_target()
args += if c.pref.ccompiler == 'msvc' {
cflags.c_options_after_target_msvc()
} else {
cflags.c_options_after_target()
}
println('Cross compiling for Windows...')
winroot := '$v_modules_path/winroot'
if !os.dir_exists(winroot) {
@ -372,7 +380,7 @@ fn (c &V) build_thirdparty_obj_files() {
for flag in c.get_os_cflags() {
if flag.value.ends_with('.o') {
rest_of_module_flags := c.get_rest_of_module_cflags( flag )
if c.os == .msvc {
if c.pref.ccompiler == 'msvc' {
build_thirdparty_obj_file_with_msvc(flag.value, rest_of_module_flags)
}
else {

View File

@ -26,7 +26,7 @@ fn (v &V) get_os_cflags() []CFlag {
|| (flag.os == 'linux' && v.os == .linux)
|| (flag.os == 'darwin' && v.os == .mac)
|| (flag.os == 'freebsd' && v.os == .freebsd)
|| (flag.os == 'windows' && (v.os == .windows || v.os == .msvc)) {
|| (flag.os == 'windows' && v.os == .windows) {
flags << flag
}
}
@ -140,10 +140,10 @@ fn (table mut Table) parse_cflag(cflag string, mod string) {
}
//TODO: implement msvc specific c_options_before_target and c_options_after_target ...
fn (cflags []CFlag) c_options_before_target_msvc() string { return '' }
fn (cflags []CFlag) c_options_after_target_msvc() string { return '' }
fn (cflags []CFlag) c_options_before_target() string {
$if msvc {
return ''
}
// -I flags, optimization flags and so on
mut args:=[]string
for flag in cflags {
@ -155,9 +155,6 @@ fn (cflags []CFlag) c_options_before_target() string {
}
fn (cflags []CFlag) c_options_after_target() string {
$if msvc {
return ''
}
// -l flags (libs)
mut args:=[]string
for flag in cflags {

View File

@ -326,7 +326,7 @@ fn (p mut Parser) fn_decl() {
p.error_with_token_index('fn main must have no arguments and no return values', f.fn_name_token_idx)
}
}
dll_export_linkage := if p.os == .msvc && p.attr == 'live' && p.pref.is_so {
dll_export_linkage := if p.pref.ccompiler == 'msvc' && p.attr == 'live' && p.pref.is_so {
'__declspec(dllexport) '
} else if p.attr == 'inline' {
'static inline '
@ -590,7 +590,7 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
// Create thread object
tmp_nr := p.get_tmp_counter()
thread_name = '_thread$tmp_nr'
if p.os != .windows && p.os != .msvc {
if p.os != .windows {
p.genln('pthread_t $thread_name;')
}
tmp2 := p.get_tmp()
@ -599,7 +599,7 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
parg = ' $tmp_struct'
}
// Call the wrapper
if p.os == .windows || p.os == .msvc {
if p.os == .windows {
p.genln(' CreateThread(0,0, $wrapper_name, $parg, 0,0);')
}
else {

View File

@ -75,7 +75,7 @@ fn (p mut Parser) gen_var_decl(name string, is_static bool) string {
}
fn (p mut Parser) gen_fn_decl(f Fn, typ, str_args string) {
dll_export_linkage := if p.os == .msvc && p.attr == 'live' && p.pref.is_so {
dll_export_linkage := if p.pref.ccompiler == 'msvc' && p.attr == 'live' && p.pref.is_so {
'__declspec(dllexport) '
} else if p.attr == 'inline' {
'static inline '

View File

@ -19,7 +19,7 @@ fn (v &V) generate_hotcode_reloading_compiler_flags() []string {
fn (v &V) generate_hotcode_reloading_declarations() {
mut cgen := v.cgen
if v.os != .windows && v.os != .msvc {
if v.os != .windows {
if v.pref.is_so {
cgen.genln('pthread_mutex_t live_fn_mutex;')
}
@ -42,7 +42,7 @@ fn (v &V) generate_hotcode_reloading_main_caller() {
mut cgen := v.cgen
cgen.genln('')
file_base := os.filename(v.dir).replace('.v', '')
if !(v.os == .windows || v.os == .msvc) {
if v.os != .windows {
// unix:
so_name := file_base + '.so'
cgen.genln(' char *live_library_name = "$so_name";')
@ -51,7 +51,7 @@ fn (v &V) generate_hotcode_reloading_main_caller() {
cgen.genln(' pthread_create(&_thread_so , NULL, &reload_so, live_library_name);')
} else {
// windows:
so_name := file_base + if v.os == .msvc {'.dll'} else {'.so'}
so_name := file_base + if v.pref.ccompiler == 'msvc' {'.dll'} else {'.so'}
cgen.genln(' char *live_library_name = "$so_name";')
cgen.genln(' live_fn_mutex = CreateMutexA(0, 0, 0);')
cgen.genln(' load_so(live_library_name);')
@ -78,8 +78,8 @@ fn (v &V) generate_hot_reload_code() {
}
mut msvc := ''
if v.os == .msvc {
msvc = '-os msvc'
if v.pref.ccompiler == 'msvc' {
msvc = '-cc msvc'
}
so_debug_flag := if v.pref.is_debug { '-g' } else { '' }
@ -104,7 +104,7 @@ void lfnmutex_print(char *s){
}
')
if v.os != .windows && v.os != .msvc {
if v.os != .windows {
cgen.genln('
#include <dlfcn.h>
void* live_lib=0;

View File

@ -396,8 +396,8 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
//println('cfiles: $cfiles')
btarget := moduleflags.c_options_before_target()
atarget := moduleflags.c_options_after_target()
btarget := moduleflags.c_options_before_target_msvc()
atarget := moduleflags.c_options_after_target_msvc()
cmd := '""$msvc.full_cl_exe_path" /volatile:ms /Zi /DNDEBUG $include_string /c $btarget $cfiles $atarget /Fo"$obj_path""'
//NB: the quotes above ARE balanced.
println('thirdparty cmd line: $cmd')

View File

@ -26,7 +26,7 @@ const (
you don\'t have to repeat them.
You can set it like this: `export VFLAGS="-cc clang -debug"` on *nix,
`set VFLAGS=-os msvc` on Windows.
`set VFLAGS=-cc msvc` on Windows.
Options/commands:
-h, help Display this information.

View File

@ -600,9 +600,6 @@ pub fn user_os() string {
$if dragonfly {
return 'dragonfly'
}
$if msvc {
return 'windows'
}
$if android{
return 'android'
}