build.bat 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. where /Q cl.exe || (
  4. set __VSCMD_ARG_NO_LOGO=1
  5. for /f "tokens=*" %%i in ('"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set VS=%%i
  6. if "!VS!" equ "" (
  7. echo ERROR: MSVC installation not found
  8. exit /b 1
  9. )
  10. call "!VS!\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 || exit /b 1
  11. )
  12. if "%VSCMD_ARG_TGT_ARCH%" neq "x64" (
  13. if "%ODIN_IGNORE_MSVC_CHECK%" == "" (
  14. echo ERROR: please run this from MSVC x64 native tools command prompt, 32-bit target is not supported!
  15. exit /b 1
  16. )
  17. )
  18. where /Q git.exe || goto skip_git_hash
  19. if not exist .git\ goto skip_git_hash
  20. for /f "tokens=1,2" %%i IN ('git show "--pretty=%%cd %%h" "--date=format:%%Y-%%m-%%d" --no-patch --no-notes HEAD') do (
  21. set CURR_DATE_TIME=%%i
  22. set GIT_SHA=%%j
  23. )
  24. if %ERRORLEVEL% equ 0 (
  25. goto have_git_hash_and_date
  26. )
  27. :skip_git_hash
  28. pushd misc
  29. cl /nologo get-date.c
  30. for /f %%i in ('get-date') do (
  31. set CURR_DATE_TIME=%%i
  32. rem Don't set GIT_SHA
  33. )
  34. popd
  35. :have_git_hash_and_date
  36. set curr_year=%CURR_DATE_TIME:~0,4%
  37. set curr_month=%CURR_DATE_TIME:~5,2%
  38. set curr_day=%CURR_DATE_TIME:~8,2%
  39. :: Make sure this is a decent name and not generic
  40. set exe_name=odin.exe
  41. :: Debug = 0, Release = 1
  42. if "%1" == "1" (
  43. set release_mode=1
  44. ) else if "%1" == "release" (
  45. set release_mode=1
  46. ) else (
  47. set release_mode=0
  48. )
  49. :: Normal = 0, CI Nightly = 1
  50. if "%2" == "1" (
  51. set nightly=1
  52. ) else (
  53. set nightly=0
  54. )
  55. if %release_mode% equ 0 (
  56. set V1=%curr_year%
  57. set V2=%curr_month%
  58. set V3=%curr_day%
  59. ) else (
  60. set V1=%curr_year%
  61. set V2=%curr_month%
  62. set V3=0
  63. )
  64. set V4=0
  65. set odin_version_full="%V1%.%V2%.%V3%.%V4%"
  66. set odin_version_raw="dev-%V1%-%V2%"
  67. set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
  68. rem Parse source code as utf-8 even on shift-jis and other codepages
  69. rem See https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
  70. set compiler_flags= %compiler_flags% /utf-8
  71. set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\" -DGIT_SHA=\"%GIT_SHA%\"
  72. rem fileversion is defined as {Major,Minor,Build,Private: u16} so a bit limited
  73. set rc_flags="-DGIT_SHA=%GIT_SHA% -DVP=dev-%V1%-%V2%:%GIT_SHA% nologo -DV1=%V1% -DV2=%V2% -DV3=%V3% -DV4=%V4% -DVF=%odin_version_full% -DNIGHTLY=%nightly%"
  74. if %nightly% equ 1 set compiler_defines=%compiler_defines% -DNIGHTLY
  75. if %release_mode% EQU 0 ( rem Debug
  76. set compiler_flags=%compiler_flags% -Od -MDd -Z7
  77. set rc_flags=%rc_flags% -D_DEBUG
  78. ) else ( rem Release
  79. set compiler_flags=%compiler_flags% -O2 -MT -Z7
  80. set compiler_defines=%compiler_defines% -DNO_ARRAY_BOUNDS_CHECK
  81. )
  82. set compiler_warnings= ^
  83. -W4 -WX ^
  84. -wd4100 -wd4101 -wd4127 -wd4146 ^
  85. -wd4505 ^
  86. -wd4456 -wd4457
  87. set compiler_includes= ^
  88. /Isrc\
  89. set libs= ^
  90. kernel32.lib ^
  91. Synchronization.lib ^
  92. bin\llvm\windows\LLVM-C.lib
  93. set odin_res=misc\odin.res
  94. set odin_rc=misc\odin.rc
  95. rem DO NOT TOUCH!
  96. rem THIS TILDE STUFF IS FOR DEVELOPMENT ONLY!
  97. set tilde_backend=0
  98. if %tilde_backend% EQU 1 (
  99. set libs=%libs% src\tilde\tb.lib
  100. set compiler_defines=%compiler_defines% -DODIN_TILDE_BACKEND
  101. )
  102. rem DO NOT TOUCH!
  103. set linker_flags= -incremental:no -opt:ref -subsystem:console -MANIFEST:EMBED
  104. if %release_mode% EQU 0 ( rem Debug
  105. set linker_flags=%linker_flags% -debug /NATVIS:src\odin_compiler.natvis
  106. ) else ( rem Release
  107. set linker_flags=%linker_flags% -debug
  108. )
  109. set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings% %compiler_defines%
  110. set linker_settings=%libs% %odin_res% %linker_flags%
  111. del *.pdb > NUL 2> NUL
  112. del *.ilk > NUL 2> NUL
  113. rc %rc_flags% %odin_rc%
  114. cl %compiler_settings% "src\main.cpp" "src\libtommath.cpp" /link %linker_settings% -OUT:%exe_name%
  115. if %errorlevel% neq 0 goto end_of_build
  116. mt -nologo -inputresource:%exe_name%;#1 -manifest misc\odin.manifest -outputresource:%exe_name%;#1 -validate_manifest -identity:"odin, processorArchitecture=amd64, version=%odin_version_full%, type=win32"
  117. if %errorlevel% neq 0 goto end_of_build
  118. call build_vendor.bat
  119. if %errorlevel% neq 0 goto end_of_build
  120. rem If the demo doesn't run for you and your CPU is more than a decade old, try -microarch:native
  121. if %release_mode% EQU 0 odin run examples/demo -vet -strict-style -resource:examples/demo/demo.rc -- Hellope World
  122. rem Many non-compiler devs seem to run debug build but don't realize.
  123. if %release_mode% EQU 0 echo: & echo Debug compiler built. Note: run "build.bat release" if you want a faster, release mode compiler.
  124. del *.obj > NUL 2> NUL
  125. :end_of_build