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