tcc_win: fix tests

pull/5423/head
spaceface777 2020-06-19 12:54:56 +02:00 committed by GitHub
parent e8b21b4242
commit 624005bbd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 243 additions and 88 deletions

View File

@ -222,7 +222,7 @@ jobs:
- name: Build
run: |
gcc --version
.\make.bat -gcc
.\make.bat -gcc -skip-path
- name: Test new v.c
run: .\v.exe -o v.c cmd/v && gcc -municode -w v.c
- name: Install dependencies
@ -256,7 +256,7 @@ jobs:
run: |
echo %VFLAGS%
echo $VFLAGS
.\make.bat -msvc
.\make.bat -msvc -skip-path
- name: Install dependencies
run: |
.\v.exe setup-freetype
@ -274,6 +274,44 @@ jobs:
# - name: Test v binaries
# run: ./v -silent build-vbinaries
windows-tcc:
runs-on: windows-2019
# We are simulating a user with no cc installed.
# This way, v's cc detection on Windows is also tested.
# env:
# VFLAGS: -cc tcc
steps:
- uses: actions/checkout@v2
#- uses: actions/setup-node@v1
# with:
# node-version: 12.x
- name: Build
# We need to move gcc and msvc, so that V doesn't find a C compiler
run: |
'for /f "usebackq tokens=*" %i in (`where gcc.exe`) do move /Y "%i" "%i.old"' | cmd
'for /f "usebackq tokens=*" %i in (`where vswhere.exe`) do move /Y "%i" "%i.old"' | cmd
move "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe.old"
.\make.bat -skip-path
- name: Test new v.c
run: .\v.exe -o v.c cmd/v && .\thirdparty\tcc\tcc.exe -w -ladvapi32 -bt10 v.c
- name: Install dependencies
run: |
.\v.exe setup-freetype
.\.github\workflows\windows-install-sdl.bat
- name: Fixed tests
run: |
.\v.exe test-fixed
# - name: Test
# run: |
# .\v.exe -silent test-compiler
## v.js dosent work on windows
#.\v.exe -o hi.js examples/hello_v_js.v
#node hi.js
# - name: Test v binaries
# run: ./v -silent build-vbinaries
# - name: v2 self compilation
# run: .\v.exe -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
docs-line-len-check:
runs-on: ubuntu-18.04
steps:

1
.gitignore vendored
View File

@ -68,5 +68,6 @@ cachegrind.out.*
._*
thumbs.db
/.symlink/*
/.bin/*
_docs

View File

@ -2,10 +2,17 @@ import os
import v.pref
const (
hkey_local_machine = voidptr(0x80000002)
hkey_current_user = voidptr(0x80000001)
hwnd_broadcast = voidptr(0xffff)
)
$if windows {
$if tinyc {
#flag -lAdvapi32
#flag -lUser32
}
}
fn main(){
$if windows {
setup_symlink_on_windows()
@ -45,16 +52,16 @@ fn setup_symlink_on_windows(){
// make.bat being global, which is NOT what we want.
//
// Instead, we create a small launcher v.bat, in a new local
// folder .symlink/ . That .symlink/ folder can then be put
// in PATH without poluting it with anything else - just a
// `v` command will be available, similar to unix.
// folder .bin/ . That .bin/ folder can then be put in PATH
// without poluting it with anything else - just a `v`
// command will be available, similar to unix.
//
// Creating a real NTFS symlink to the real executable was also
// tried, but then os.real_path( os.executable() ) returns the
// path to the symlink, unfortunately, unlike on posix systems
// ¯\_(ツ)_/¯
vdir := os.real_path(os.dir(vexe))
vsymlinkdir := os.join_path(vdir, '.symlink')
vsymlinkdir := os.join_path(vdir, '.bin')
vsymlinkbat := os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlinkbat) {
print('Batch script $vsymlinkbat already exists, checking system %PATH%...')
@ -128,9 +135,9 @@ fn warn_and_exit(err string) {
fn get_reg_sys_env_handle() ?voidptr {
$if windows {
// open the registry key
reg_key_path := 'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment'
reg_key_path := 'Environment'
reg_env_key := voidptr(0) // or HKEY (HANDLE)
if C.RegOpenKeyEx(hkey_local_machine, reg_key_path.to_wide(), 0, 1 | 2, &reg_env_key) != 0 {
if C.RegOpenKeyEx(hkey_current_user, reg_key_path.to_wide(), 0, 1 | 2, &reg_env_key) != 0 {
return error('Could not open "$reg_key_path" in the registry')
}
@ -146,7 +153,7 @@ fn get_reg_value(reg_env_key voidptr, key string) ?string {
reg_value_size := 4095 // this is the max length (not for the registry, but for the system %PATH%)
mut reg_value := &u16(malloc(reg_value_size))
if C.RegQueryValueEx(reg_env_key, key.to_wide(), 0, 0, reg_value, &reg_value_size) != 0 {
return error('Unable to get registry value for "$key", are you running as an Administrator?')
return error('Unable to get registry value for "$key", try rerunning as an Administrator')
}
return string_from_wide(reg_value)

164
make.bat
View File

@ -2,6 +2,7 @@
echo Building V
set tcc_path=%~dp0thirdparty\tcc\
pushd %~dp0
if "%~1"=="-local" goto :compile
@ -18,41 +19,39 @@ if exist "vc" (
)
:compile
REM option to force msvc or gcc
if "%~1"=="-gcc" goto :gcc_strap
if "%~2"=="-gcc" goto :gcc_strap
if "%~1"=="-msvc" goto :msvc_strap
if "%~2"=="-msvc" goto :msvc_strap
REM option to disable adding V to PATH
if "%~1"=="-skip-path" set skip_path=1
if "%~2"=="-skip-path" set skip_path=1
REM option to force msvc, gcc or tcc
if "%~1"=="-gcc" set force_gcc=1 & goto :gcc_strap
if "%~2"=="-gcc" set force_gcc=1 & goto :gcc_strap
if "%~1"=="-msvc" set force_msvc=1 & goto :msvc_strap
if "%~2"=="-msvc" set force_msvc=1 & goto :msvc_strap
if "%~1"=="-tcc" set force_tcc=1 & goto :tcc_strap
if "%~2"=="-tcc" set force_tcc=1 & goto :tcc_strap
:gcc_strap
echo.
echo Attempting to build v.c with GCC...
for /f "usebackq tokens=*" %%i in (`where gcc`) do (
set gcc_path=%%i
)
if not exist "%gcc_path%" (
where /q gcc
if %ERRORLEVEL% NEQ 0 (
echo ^> GCC not found
if "%force_gcc%" NEQ "" goto :error
goto :msvc_strap
)
gcc -std=c99 -municode -w -o v.exe vc\v_win.c
if %ERRORLEVEL% NEQ 0 (
echo gcc failed to compile - Create an issue at 'https://github.com/vlang'
rd /s /q vc
goto :error
)
if %ERRORLEVEL% NEQ 0 goto :compile_error
v.exe self
if %ERRORLEVEL% NEQ 0 (
echo v.exe failed to compile itself - Create an issue at 'https://github.com/vlang'
goto :error
)
del v_old.exe
v.exe self > NUL
if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success
:msvc_strap
echo Attempting to build v.c with MSVC...
echo.
echo Attempting to build v.c with MSVC...
set VsWhereDir=%ProgramFiles(x86)%
set HostArch=x64
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
@ -60,58 +59,123 @@ if "%PROCESSOR_ARCHITECTURE%" == "x86" (
set VsWhereDir=%ProgramFiles%
set HostArch=x86
)
if not exist "%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" (
echo ^> MSVC not found
if "%force_msvc%" NEQ "" goto :error
goto :tcc_strap
)
for /f "usebackq tokens=*" %%i in (`"%VsWhereDir%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set InstallDir=%%i
)
if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
call "%InstallDir%\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo
call "%InstallDir%\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo > NUL
) else if exist "%VsWhereDir%\Microsoft Visual Studio 14.0\Common7\Tools\vsdevcmd.bat" (
call "%VsWhereDir%\Microsoft Visual Studio 14.0\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo
) else (
goto :no_compiler
call "%VsWhereDir%\Microsoft Visual Studio 14.0\Common7\Tools\vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo > NUL
)
set ObjFile=.v.c.obj
cl.exe /nologo /w /volatile:ms /Fo%ObjFile% /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /NOLOGO /OUT:v.exe /INCREMENTAL:NO
if %ERRORLEVEL% NEQ 0 (
echo cl.exe failed to build V
goto :compile_error
)
cl.exe /nologo /w /volatile:ms /Fo%ObjFile% /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /NOLOGO /OUT:v.exe /INCREMENTAL:NO > NUL
if %ERRORLEVEL% NEQ 0 goto :compile_error
v.exe -cc msvc self
if %ERRORLEVEL% NEQ 0 (
echo V failed to build itself with error %ERRORLEVEL%
del %ObjFile%
goto :compile_error
)
del v_old.exe
del %ObjFile%
if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success
:no_compiler
echo You do not appear to have a GCC installation on your PATH and also do not have an MSVC installation
echo - this means that you cannot bootstrap a V installation at this time...
:clone_tcc
git clone --depth 1 --quiet https://github.com/vlang/tccbin_win %tcc_path%
set cloned_tcc=1
goto :tcc_strap
:tcc_strap
echo.
echo Head to 'https://github.com/vlang/v/releases/download/v0.1.10/mingw-w64-install.exe' to download and install GCC
echo or head to 'https://visualstudio.microsoft.com/downloads/' to download and install MSVC
echo (look for the Build Tools if you don't want to install the Visual Studio IDE)
echo.
goto :error
echo Attempting to build v.c with TCC...
where /q tcc
if %ERRORLEVEL% NEQ 0 (
if exist "%tcc_path%" (
set tcc_exe=%tcc_path%tcc.exe
) else if "%cloned_tcc%"=="" (
echo ^> TCC not found
echo ^> Downloading TCC from https://github.com/vlang/tccbin_win
goto :clone_tcc
) else (
echo ^> TCC not found, even after cloning
goto :error
)
) else (
for /f "delims=" %%i in ('where tcc') do set tcc_exe=%%i
)
if exist "%tcc_path%" (
if "%cloned_tcc%"=="" (
echo ^> Updating prebuilt TCC...
pushd "%tcc_path%"
git pull -q > NUL
popd
)
)
call "%tcc_exe%" -std=c99 -municode -lws2_32 -lshell32 -ladvapi32 -bt10 -w -o v.exe vc\v_win.c
if %ERRORLEVEL% NEQ 0 goto :compile_error
REM TODO: delete this when the tcc bootstrapping logic is merged to master
v.exe -o vtcc.c cmd\v
call "%tcc_exe%" -std=c99 -municode -lws2_32 -lshell32 -ladvapi32 -bt10 -w -o v.exe vtcc.c
if %ERRORLEVEL% NEQ 0 goto :compile_error
del vtcc.c
v.exe -cc "%tcc_exe%" self > NUL
if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success
:compile_error
echo Failed to compile - Create an issue at 'https://github.com/vlang' and tag '@emily33901'!
echo Failed to compile - Create an issue at 'https://github.com/vlang'
goto :error
:error
echo.
echo Exiting from error
popd
exit /b 1
:success
echo V build OK!
echo ^> V built successfully!
del v_old.exe
:path
if "%skip_path%" NEQ "" goto :version
echo.
echo Adding V to PATH...
v.exe symlink > NUL
if %ERRORLEVEL% NEQ 0 (
echo ^> Could not add V to %%PATH%%, try rebuilding as admin.
goto :error
)
echo ^> V added to %%PATH%%
if "%cloned_tcc%" NEQ "" (
echo @echo off> "%~dp0.bin\tcc.bat"
echo %tcc_path%tcc %%^*>> "%~dp0.bin\tcc.bat"
echo ^> TCC added to %%PATH%%
)
echo ^> Restart your shell/IDE to reload it
:version
echo.
echo | set /p="V version: "
v.exe version
if "%cloned_tcc%" NEQ "" (
echo.
echo WARNING: No C compiler was detected in your PATH. `tcc` was used temporarily
echo to build V, but it may have some bugs and may not work in all cases.
echo A more advanced C compiler like GCC or MSVC is recommended.
echo https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows
echo.
)
popd

View File

@ -6,4 +6,5 @@ sdl2/
SDL2_image/
SDL2_mixer/
SDL2_ttf/
pg/
pg/
tcc/

View File

@ -2961,7 +2961,7 @@ _SOKOL_PRIVATE const _sapp_gl_fbconfig* _sapp_gl_choose_fbconfig(const _sapp_gl_
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#pragma comment (lib, "Shell32.lib")
#pragma comment (lib, "Shell32")
#if defined(SOKOL_D3D11)
#ifndef D3D11_NO_HELPERS

View File

@ -279,7 +279,7 @@ static INT connect_to_server(TlsContext *tls_ctx, LPWSTR host, INT port_number)
WCHAR service_name[10];
int res = wsprintf(service_name, L"%d", port_number);
if(WSAConnectByName(Socket,connect_name, service_name, &local_address_length,
if(WSAConnectByNameA(Socket,connect_name, service_name, &local_address_length,
&local_address, &remote_address_length, &remote_address, &tv, NULL) == SOCKET_ERROR) {
wprintf(L"Error %d connecting to \"%s\" (%s)\n",
WSAGetLastError(),

View File

@ -2,6 +2,8 @@ module clipboard
import time
#flag -lUser32
struct WndClassEx {
cb_size u32
style u32

View File

@ -5,6 +5,12 @@ module math
#include <math.h>
$if windows {
$if tinyc {
#flag @VROOT/thirdparty/tcc/lib/openlibm.o
}
}
fn C.acos(x f64) f64
fn C.asin(x f64) f64
fn C.atan(x f64) f64

View File

@ -46,8 +46,8 @@ fn test_gamma() {
assert gamma(1) == 1
assert gamma(5) == 24
sval := '2.453737'
assert tst_res(log_gamma(4.5).str(), sval)
assert tst_res(log(gamma(4.5)).str(), sval)
assert tst_res(log_gamma(4.5).str(), sval)
assert tst_res(log(gamma(4.5)).str(), sval)
//assert log_gamma(4.5).str() == sval
//assert log(gamma(4.5)).str() == sval
assert abs( log_gamma(4.5) - log(gamma(4.5)) ) < 0.000001

View File

@ -5,7 +5,7 @@
module http
#flag windows -I @VROOT/thirdparty/vschannel
#flag -l ws2_32 -l crypt32 -l secur32
#flag -l ws2_32 -l crypt32 -l secur32 -l user32
#include "vschannel.c"

View File

@ -139,9 +139,13 @@ pub fn (mut f File) flush() {
pub fn file_size(path string) int {
mut s := C.stat{}
$if windows {
C._wstat(path.to_wide(), voidptr(&s))
$if tinyc {
C.stat(charptr(path.str), voidptr(&s))
} $else {
C._wstat(path.to_wide(), voidptr(&s))
}
} $else {
C.stat(charptr(path.str), &s)
C.stat(charptr(path.str), voidptr(&s))
}
return s.st_size
}

View File

@ -52,6 +52,9 @@ pub fn (mut b Builder) compile_c() {
println('all .v files before:')
// println(files)
}
$if windows {
b.pref.ccompiler = b.find_win_cc() or { panic(no_compiler_error) }
}
// v1 compiler files
// v.add_v_files_to_compile()
// v.files << v.dir

View File

@ -19,7 +19,21 @@ If you were not working with C interop, please raise an issue on GitHub:
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
')
'
no_compiler_error = '
==================
Error: no C compiler detected.
You can find instructions on how to install one in the V wiki:
https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows
If you think you have one installed, make sure it is in your PATH.
If you do have one in your PATH, please raise an issue on GitHub:
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
'
)
const (
mingw_cc = 'x86_64-w64-mingw32-gcc'
@ -29,16 +43,30 @@ const (
fn todo() {
}
fn (v &Builder) no_cc_installed() bool {
$if windows {
os.exec('$v.pref.ccompiler -v') or {
if v.pref.is_verbose {
println('C compiler not found, trying to build with msvc...')
}
return true
fn (v &Builder) find_win_cc() ?string {
$if !windows { return none }
os.exec('$v.pref.ccompiler -v') or {
if v.pref.is_verbose {
println('$v.pref.ccompiler not found, looking for msvc...')
}
find_msvc() or {
if v.pref.is_verbose {
println('msvc not found, looking for thirdparty/tcc...')
}
vpath := os.dir(os.getenv('VEXE'))
thirdparty_tcc := os.join_path(vpath, 'thirdparty', 'tcc', 'tcc.exe')
os.exec('$thirdparty_tcc -v') or {
if v.pref.is_verbose {
println('No C compiler found')
}
return none
}
return thirdparty_tcc
}
return 'msvc'
}
return false
return v.pref.ccompiler
}
fn (mut v Builder) cc() {
@ -95,8 +123,9 @@ fn (mut v Builder) cc() {
return
}
}
mut ccompiler := v.pref.ccompiler
$if windows {
if v.pref.ccompiler == 'msvc' || v.no_cc_installed() {
if ccompiler == 'msvc' {
v.cc_msvc()
return
}
@ -191,9 +220,9 @@ fn (mut v Builder) cc() {
}
}
//
is_cc_clang := v.pref.ccompiler.contains('clang') || guessed_compiler == 'clang'
is_cc_tcc := v.pref.ccompiler.contains('tcc') || guessed_compiler == 'tcc'
is_cc_gcc := v.pref.ccompiler.contains('gcc') || guessed_compiler == 'gcc'
is_cc_tcc := ccompiler.contains('tcc') || guessed_compiler == 'tcc'
is_cc_clang := !is_cc_tcc && (ccompiler.contains('clang') || guessed_compiler == 'clang')
is_cc_gcc := !is_cc_tcc && !is_cc_clang && (ccompiler.contains('gcc') || guessed_compiler == 'gcc')
// is_cc_msvc := v.pref.ccompiler.contains('msvc') || guessed_compiler == 'msvc'
//
if is_cc_clang {
@ -227,7 +256,7 @@ fn (mut v Builder) cc() {
if debug_mode && os.user_os() != 'windows' {
linker_flags << ' -rdynamic ' // needed for nicer symbolic backtraces
}
if v.pref.ccompiler != 'msvc' && v.pref.os != .freebsd {
if ccompiler != 'msvc' && v.pref.os != .freebsd {
a << '-Werror=implicit-function-declaration'
}
if v.pref.is_liveshared || v.pref.is_livemain {
@ -365,7 +394,7 @@ fn (mut v Builder) cc() {
start:
todo()
// TODO remove
cmd := '${v.pref.ccompiler} $args'
cmd := '${ccompiler} $args'
// Run
if v.pref.is_verbose || v.pref.show_cc {
println('\n==========')
@ -391,7 +420,7 @@ fn (mut v Builder) cc() {
if res.exit_code == 127 {
$if linux {
// TCC problems on linux? Try GCC.
if v.pref.ccompiler.contains('tcc') {
if ccompiler.contains('tcc') {
v.pref.ccompiler = 'cc'
goto start
}
@ -424,7 +453,7 @@ fn (mut v Builder) cc() {
diff := time.ticks() - ticks
// Print the C command
if v.pref.is_verbose {
println('${v.pref.ccompiler} took $diff ms')
println('${ccompiler} took $diff ms')
println('=========\n')
}
// Link it if we are cross compiling and need an executable
@ -624,7 +653,7 @@ fn (c &Builder) 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.pref.ccompiler == 'msvc' || c.no_cc_installed() {
if c.pref.ccompiler == 'msvc' {
build_thirdparty_obj_file_with_msvc(flag.value, rest_of_module_flags)
} else {
c.build_thirdparty_obj_file(flag.value, rest_of_module_flags)
@ -661,7 +690,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
btarget := moduleflags.c_options_before_target()
atarget := moduleflags.c_options_after_target()
cppoptions := if v.pref.ccompiler.contains('++') { ' -fpermissive -w ' } else { '' }
cmd := '$v.pref.ccompiler $cppoptions $v.pref.third_party_option $btarget -c -o "$obj_path" $cfiles $atarget '
cmd := '$v.pref.ccompiler $cppoptions $v.pref.third_party_option $btarget -c -o "$obj_path" $cfiles $atarget'
res := os.exec(cmd) or {
println('failed thirdparty object build cmd: $cmd')
verror(err)

View File

@ -226,7 +226,7 @@ static inline bool _us64_ne(uint64_t a, int64_t b) { return a > INT64_MAX || (in
static inline bool _us64_le(uint64_t a, int64_t b) { return a <= INT64_MAX && (int64_t)a <= b; }
static inline bool _us64_lt(uint64_t a, int64_t b) { return a < INT64_MAX && (int64_t)a < b; }
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(__MINGW32__) || defined(__MINGW64__) || (defined(_WIN32) && defined(__TINYC__))
#undef PRId64
#undef PRIi64
#undef PRIo64