mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
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
This commit is contained in:
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 '
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user