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:
parent
093d8a2b00
commit
9a2b8a0814
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -85,14 +85,14 @@ jobs:
|
|||||||
# with:
|
# with:
|
||||||
# node-version: 12.x
|
# node-version: 12.x
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
#env:
|
||||||
VFLAGS: -os msvc
|
# VFLAGS: -cc msvc
|
||||||
run: |
|
run: |
|
||||||
git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries.git thirdparty/freetype/
|
git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries.git thirdparty/freetype/
|
||||||
.\make.bat -msvc
|
.\make.bat -msvc
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
#env:
|
||||||
VFLAGS: -os msvc
|
# VFLAGS: -cc msvc
|
||||||
run: |
|
run: |
|
||||||
.\v.exe test v
|
.\v.exe test v
|
||||||
## v.js dosent work on windows
|
## v.js dosent work on windows
|
||||||
|
@ -45,12 +45,11 @@ script:
|
|||||||
if [[ "${TRAVIS_JOB_NAME}" == "windows_gcc" ]]; then
|
if [[ "${TRAVIS_JOB_NAME}" == "windows_gcc" ]]; then
|
||||||
gcc --version
|
gcc --version
|
||||||
echo "Building V with GCC"
|
echo "Building V with GCC"
|
||||||
export VFLAGS="-os windows"
|
|
||||||
./make.bat -gcc
|
./make.bat -gcc
|
||||||
fi
|
fi
|
||||||
if [[ "${TRAVIS_JOB_NAME}" == "windows_msvc" ]]; then
|
if [[ "${TRAVIS_JOB_NAME}" == "windows_msvc" ]]; then
|
||||||
echo "Building V with MSVC"
|
echo "Building V with MSVC"
|
||||||
export VFLAGS="-os msvc"
|
#export VFLAGS="-cc msvc"
|
||||||
./make.bat -msvc
|
./make.bat -msvc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
BIN
examples/hot_reload/glfw3.dll
Normal file
BIN
examples/hot_reload/glfw3.dll
Normal file
Binary file not shown.
4
make.bat
4
make.bat
@ -69,8 +69,8 @@ if %ERRORLEVEL% NEQ 0 (
|
|||||||
)
|
)
|
||||||
|
|
||||||
echo rebuild from source (twice, in case of C definitions changes)
|
echo rebuild from source (twice, in case of C definitions changes)
|
||||||
v2.exe -os msvc -o v3.exe v.v
|
v2.exe -o v3.exe v.v
|
||||||
v3.exe -os msvc -o v.exe -prod v.v
|
v3.exe -cc msvc -o v.exe -prod v.v
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
echo V failed to build itself
|
echo V failed to build itself
|
||||||
goto :compileerror
|
goto :compileerror
|
||||||
|
@ -48,7 +48,7 @@ fn (v mut V) cc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$if windows {
|
$if windows {
|
||||||
if v.os == .msvc {
|
if v.pref.ccompiler == 'msvc' {
|
||||||
v.cc_msvc()
|
v.cc_msvc()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ fn (v mut V) cc() {
|
|||||||
a << ' -rdynamic ' // needed for nicer symbolic backtraces
|
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'
|
a << '-Werror=implicit-function-declaration'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +314,11 @@ fn (c mut V) cc_windows_cross() {
|
|||||||
mut args := '-o $c.out_name -w -L. '
|
mut args := '-o $c.out_name -w -L. '
|
||||||
cflags := c.get_os_cflags()
|
cflags := c.get_os_cflags()
|
||||||
// -I flags
|
// -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 := ''
|
mut libs := ''
|
||||||
if c.pref.build_mode == .default_mode {
|
if c.pref.build_mode == .default_mode {
|
||||||
libs = '"$v_modules_path/vlib/builtin.o"'
|
libs = '"$v_modules_path/vlib/builtin.o"'
|
||||||
@ -327,7 +331,11 @@ fn (c mut V) cc_windows_cross() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args += ' $c.out_name_c '
|
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...')
|
println('Cross compiling for Windows...')
|
||||||
winroot := '$v_modules_path/winroot'
|
winroot := '$v_modules_path/winroot'
|
||||||
if !os.dir_exists(winroot) {
|
if !os.dir_exists(winroot) {
|
||||||
@ -372,7 +380,7 @@ fn (c &V) build_thirdparty_obj_files() {
|
|||||||
for flag in c.get_os_cflags() {
|
for flag in c.get_os_cflags() {
|
||||||
if flag.value.ends_with('.o') {
|
if flag.value.ends_with('.o') {
|
||||||
rest_of_module_flags := c.get_rest_of_module_cflags( flag )
|
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)
|
build_thirdparty_obj_file_with_msvc(flag.value, rest_of_module_flags)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -26,7 +26,7 @@ fn (v &V) get_os_cflags() []CFlag {
|
|||||||
|| (flag.os == 'linux' && v.os == .linux)
|
|| (flag.os == 'linux' && v.os == .linux)
|
||||||
|| (flag.os == 'darwin' && v.os == .mac)
|
|| (flag.os == 'darwin' && v.os == .mac)
|
||||||
|| (flag.os == 'freebsd' && v.os == .freebsd)
|
|| (flag.os == 'freebsd' && v.os == .freebsd)
|
||||||
|| (flag.os == 'windows' && (v.os == .windows || v.os == .msvc)) {
|
|| (flag.os == 'windows' && v.os == .windows) {
|
||||||
flags << flag
|
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 ...
|
//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 {
|
fn (cflags []CFlag) c_options_before_target() string {
|
||||||
$if msvc {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
// -I flags, optimization flags and so on
|
// -I flags, optimization flags and so on
|
||||||
mut args:=[]string
|
mut args:=[]string
|
||||||
for flag in cflags {
|
for flag in cflags {
|
||||||
@ -155,9 +155,6 @@ fn (cflags []CFlag) c_options_before_target() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (cflags []CFlag) c_options_after_target() string {
|
fn (cflags []CFlag) c_options_after_target() string {
|
||||||
$if msvc {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
// -l flags (libs)
|
// -l flags (libs)
|
||||||
mut args:=[]string
|
mut args:=[]string
|
||||||
for flag in cflags {
|
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)
|
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) '
|
'__declspec(dllexport) '
|
||||||
} else if p.attr == 'inline' {
|
} else if p.attr == 'inline' {
|
||||||
'static 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
|
// Create thread object
|
||||||
tmp_nr := p.get_tmp_counter()
|
tmp_nr := p.get_tmp_counter()
|
||||||
thread_name = '_thread$tmp_nr'
|
thread_name = '_thread$tmp_nr'
|
||||||
if p.os != .windows && p.os != .msvc {
|
if p.os != .windows {
|
||||||
p.genln('pthread_t $thread_name;')
|
p.genln('pthread_t $thread_name;')
|
||||||
}
|
}
|
||||||
tmp2 := p.get_tmp()
|
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'
|
parg = ' $tmp_struct'
|
||||||
}
|
}
|
||||||
// Call the wrapper
|
// Call the wrapper
|
||||||
if p.os == .windows || p.os == .msvc {
|
if p.os == .windows {
|
||||||
p.genln(' CreateThread(0,0, $wrapper_name, $parg, 0,0);')
|
p.genln(' CreateThread(0,0, $wrapper_name, $parg, 0,0);')
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
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) '
|
'__declspec(dllexport) '
|
||||||
} else if p.attr == 'inline' {
|
} else if p.attr == 'inline' {
|
||||||
'static inline '
|
'static inline '
|
||||||
|
@ -19,7 +19,7 @@ fn (v &V) generate_hotcode_reloading_compiler_flags() []string {
|
|||||||
|
|
||||||
fn (v &V) generate_hotcode_reloading_declarations() {
|
fn (v &V) generate_hotcode_reloading_declarations() {
|
||||||
mut cgen := v.cgen
|
mut cgen := v.cgen
|
||||||
if v.os != .windows && v.os != .msvc {
|
if v.os != .windows {
|
||||||
if v.pref.is_so {
|
if v.pref.is_so {
|
||||||
cgen.genln('pthread_mutex_t live_fn_mutex;')
|
cgen.genln('pthread_mutex_t live_fn_mutex;')
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ fn (v &V) generate_hotcode_reloading_main_caller() {
|
|||||||
mut cgen := v.cgen
|
mut cgen := v.cgen
|
||||||
cgen.genln('')
|
cgen.genln('')
|
||||||
file_base := os.filename(v.dir).replace('.v', '')
|
file_base := os.filename(v.dir).replace('.v', '')
|
||||||
if !(v.os == .windows || v.os == .msvc) {
|
if v.os != .windows {
|
||||||
// unix:
|
// unix:
|
||||||
so_name := file_base + '.so'
|
so_name := file_base + '.so'
|
||||||
cgen.genln(' char *live_library_name = "$so_name";')
|
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);')
|
cgen.genln(' pthread_create(&_thread_so , NULL, &reload_so, live_library_name);')
|
||||||
} else {
|
} else {
|
||||||
// windows:
|
// 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(' char *live_library_name = "$so_name";')
|
||||||
cgen.genln(' live_fn_mutex = CreateMutexA(0, 0, 0);')
|
cgen.genln(' live_fn_mutex = CreateMutexA(0, 0, 0);')
|
||||||
cgen.genln(' load_so(live_library_name);')
|
cgen.genln(' load_so(live_library_name);')
|
||||||
@ -78,8 +78,8 @@ fn (v &V) generate_hot_reload_code() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mut msvc := ''
|
mut msvc := ''
|
||||||
if v.os == .msvc {
|
if v.pref.ccompiler == 'msvc' {
|
||||||
msvc = '-os msvc'
|
msvc = '-cc msvc'
|
||||||
}
|
}
|
||||||
|
|
||||||
so_debug_flag := if v.pref.is_debug { '-g' } else { '' }
|
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('
|
cgen.genln('
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
void* live_lib=0;
|
void* live_lib=0;
|
||||||
|
@ -396,8 +396,8 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
|
|||||||
|
|
||||||
//println('cfiles: $cfiles')
|
//println('cfiles: $cfiles')
|
||||||
|
|
||||||
btarget := moduleflags.c_options_before_target()
|
btarget := moduleflags.c_options_before_target_msvc()
|
||||||
atarget := moduleflags.c_options_after_target()
|
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""'
|
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.
|
//NB: the quotes above ARE balanced.
|
||||||
println('thirdparty cmd line: $cmd')
|
println('thirdparty cmd line: $cmd')
|
||||||
|
@ -26,7 +26,7 @@ const (
|
|||||||
you don\'t have to repeat them.
|
you don\'t have to repeat them.
|
||||||
|
|
||||||
You can set it like this: `export VFLAGS="-cc clang -debug"` on *nix,
|
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:
|
Options/commands:
|
||||||
-h, help Display this information.
|
-h, help Display this information.
|
||||||
|
@ -600,9 +600,6 @@ pub fn user_os() string {
|
|||||||
$if dragonfly {
|
$if dragonfly {
|
||||||
return 'dragonfly'
|
return 'dragonfly'
|
||||||
}
|
}
|
||||||
$if msvc {
|
|
||||||
return 'windows'
|
|
||||||
}
|
|
||||||
$if android{
|
$if android{
|
||||||
return 'android'
|
return 'android'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user