From be30820023e45a3e3654e85e06c849e15b694349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= <nicolas@uucidl.com> Date: Sun, 9 Aug 2015 15:20:43 +0200 Subject: [PATCH] windows build: Add build scripts + appveyor.yml In order to guarantee that Hammer can build on Windows, an appveyor.yml and associated build scripts will build hammer and its examples. The idea is that as soon as the appveyor.yml exists in the repository, pull requests that would impede Windows portability would be immediately detected. The scripts expect CL.EXE to be in the path, and will produce their results in build/ The highest level of warning is enabled on CL.EXE, minus warnings that bring CL.EXE to a level that ressembles C99. The only notable warning that was disabled is the one that tells you about implicit truncating conversions. Hammer's source code has quite a few implicit conversions say from a 64bit unsigned integer to a integer of a lesser size (signed or otherwise) --- appveyor.yml | 18 ++++++++++ tools/windows/README.md | 1 + tools/windows/build.bat | 47 ++++++++++++++++++++++++++ tools/windows/build_examples.bat | 56 +++++++++++++++++++++++++++++++ tools/windows/clvars.bat | 37 ++++++++++++++++++++ tools/windows/env.bat | 16 +++++++++ tools/windows/hammer_lib_src_list | 48 ++++++++++++++++++++++++++ tools/windows/status.bat | 1 + 8 files changed, 224 insertions(+) create mode 100644 appveyor.yml create mode 100644 tools/windows/README.md create mode 100644 tools/windows/build.bat create mode 100644 tools/windows/build_examples.bat create mode 100644 tools/windows/clvars.bat create mode 100644 tools/windows/env.bat create mode 100644 tools/windows/hammer_lib_src_list create mode 100644 tools/windows/status.bat diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..b0d87a79 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +platform: +- x86 +- x64 +version: 1.0.{build} +os: Visual Studio 2015 +build_script: +- '@echo off' +- setlocal +- ps: >- + If ($env:Platform -Match "x86") { + $env:VCVARS_PLATFORM="x86" + } Else { + $env:VCVARS_PLATFORM="amd64" + } +- call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %VCVARS_PLATFORM% +- call tools\windows\build.bat +- call tools\windows\build_examples.bat +- exit /b 0 diff --git a/tools/windows/README.md b/tools/windows/README.md new file mode 100644 index 00000000..3b28eea4 --- /dev/null +++ b/tools/windows/README.md @@ -0,0 +1 @@ +Support tools for the Windows (win32/win64) port. \ No newline at end of file diff --git a/tools/windows/build.bat b/tools/windows/build.bat new file mode 100644 index 00000000..20f878ac --- /dev/null +++ b/tools/windows/build.bat @@ -0,0 +1,47 @@ +@echo off +setlocal + +REM This script must be run after vcvarsall.bat has been run, +REM so that cl.exe is in your path. +where cl.exe || goto vsmissing_err + +REM HEREPATH is <drive_letter>:<script_directory> +set HEREPATH=%~d0%~p0 + +REM Set up SRC, BUILD and CLFLAGS +call %HEREPATH%\env.bat +call %HEREPATH%\clvars.bat + +echo SRC=%SRC%, BUILD=%BUILD% +echo Building with flags: %CLFLAGS% + +pushd %SRC% +mkdir %BUILD%\obj +del /Q %BUILD%\obj\ + +cl.exe -nologo -FC -EHsc -Z7 -Oi -GR- -Gm- %CLFLAGS% -c ^ + @%HEREPATH%\hammer_lib_src_list ^ + -Fo%BUILD%\obj\ +if %errorlevel% neq 0 goto err + +lib.exe %BUILD%\obj\*.obj -OUT:%BUILD%\hammer.lib +echo STATIC_LIBRARY %BUILD%\hammer.lib +if %errorlevel% neq 0 goto err +popd + +REM TODO(uucidl): how to build and run the tests? They are written with glib.h +REM which might be a challenge on windows. On the other hand the API of glib.h +REM does not seem too hard to reimplement. + +echo SUCCESS: Successfully built +endlocal +exit /b 0 + +:vsmissing_err +echo ERROR: CL.EXE missing. Have you run vcvarsall.bat? +exit /b 1 + +:err +endlocal +echo ERROR: Failed to build +exit /b %errorlevel% diff --git a/tools/windows/build_examples.bat b/tools/windows/build_examples.bat new file mode 100644 index 00000000..3bbcccb0 --- /dev/null +++ b/tools/windows/build_examples.bat @@ -0,0 +1,56 @@ +@echo off +setlocal + +REM This script must be run after vcvarsall.bat has been run, +REM so that cl.exe is in your path. +where cl.exe || goto vsmissing_err + +REM HEREPATH is <drive_letter>:<script_directory> +set HEREPATH=%~d0%~p0 + +REM Set up SRC, BUILD and CLFLAGS +call %HEREPATH%\env.bat +call %HEREPATH%\clvars.bat + +REM type conversion of a return value +set CLFLAGS=%CLFLAGS% -wd4242 + +echo SRC=%SRC%, BUILD=%BUILD% +echo CLFLAGS=%CLFLAGS% + +set HAMMERLIB=%BUILD%\hammer.lib + +REM Now let's build some example programs + +cl.exe -nologo %CLFLAGS% examples\base64.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64.exe +cl.exe -nologo %CLFLAGS% examples\base64_sem1.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64_sem1.exe +cl.exe -nologo %CLFLAGS% examples\base64_sem2.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\base64_sem2.exe + +REM FIXME(windows) TODO(uucidl): dns.c only works on posix +REM cl.exe -nologo %CLFLAGS% examples\dns.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +REM if %errorlevel% neq 0 goto err +REM echo PROGRAM build\dns.exe + +REM FIXME(windows) TODO(uucidl): grammar.c needs to be fixed +cl.exe -nologo %CLFLAGS% examples\ties.c examples\grammar.c %HAMMERLIB% -Fo%BUILD%\ -Fe%BUILD%\ +if %errorlevel% neq 0 goto err +echo PROGRAM build\ties.exe + +echo SUCCESS: Successfully built +endlocal +exit /b 0 + +:vsmissing_err +echo ERROR: CL.EXE missing. Have you run vcvarsall.bat? +exit /b 1 + +:err +echo ERROR: Failed to build +endlocal +exit /b %errorlevel% diff --git a/tools/windows/clvars.bat b/tools/windows/clvars.bat new file mode 100644 index 00000000..c08ed173 --- /dev/null +++ b/tools/windows/clvars.bat @@ -0,0 +1,37 @@ +REM Don't call me directly +REM Exports CLFLAGS + +REM Start with the most strict warning level +set WARNINGS=-W4 -Wall -WX + +REM We disable implicit casting warnings (c4244), as they occur too often here. +REM Its gcc/clang counterpart is Wconversion which does not seem to +REM be enabled by default. +REM See: [[https://gcc.gnu.org/wiki/NewWconversion#Frequently_Asked_Questions]] +set WARNINGS=%WARNINGS% -wd4244 + +REM c4100 (unreferenced formal parameter) is equivalent to -Wno-unused-parameter +set WARNINGS=%WARNINGS% -wd4100 + +REM c4200 (zero-sized array) is a C idiom supported by C99 +set WARNINGS=%WARNINGS% -wd4200 + +REM c4204 (non-constant aggregate initializers) ressembles C99 support +set WARNINGS=%WARNINGS% -wd4204 + +REM c4820 (warnings about padding) is not useful +set WARNINGS=%WARNINGS% -wd4820 + +REM c4710 (inlining could not be performed) is not useful +set WARNINGS=%WARNINGS% -wd4710 + +REM c4255 ( () vs (void) ambiguity) is not useful +set WARNINGS=%WARNINGS% -wd4255 + +REM c4996 (deprecated functions) +set WARNINGS=%WARNINGS% -wd4996 + +REM we use sprintf +set DEFINES=-D_CRT_SECURE_NO_WARNINGS + +set CLFLAGS=%DEFINES% %WARNINGS% diff --git a/tools/windows/env.bat b/tools/windows/env.bat new file mode 100644 index 00000000..4037578c --- /dev/null +++ b/tools/windows/env.bat @@ -0,0 +1,16 @@ +REM Don't call me directly. +REM +REM Expects HEREPATH (this directory) +REM Exports SRC (hammer's src directory) +REM Exports BUILD (hammer's build directory) + +set TOP=%HEREPATH%..\.. + +REM Get canonical path for TOP +pushd . +cd %TOP% +set TOP=%CD% +popd + +set SRC=%TOP%\src +set BUILD=%TOP%\build diff --git a/tools/windows/hammer_lib_src_list b/tools/windows/hammer_lib_src_list new file mode 100644 index 00000000..342b6345 --- /dev/null +++ b/tools/windows/hammer_lib_src_list @@ -0,0 +1,48 @@ +asprintf.c +platform_win32.c +allocator.c +benchmark.c +bitreader.c +bitwriter.c +cfgrammar.c +datastructures.c +desugar.c +glue.c +hammer.c +pprint.c +registry.c +system_allocator.c +parsers/action.c +parsers/and.c +parsers/attr_bool.c +parsers/bind.c +parsers/bits.c +parsers/butnot.c +parsers/ch.c +parsers/charset.c +parsers/difference.c +parsers/end.c +parsers/endianness.c +parsers/epsilon.c +parsers/ignore.c +parsers/ignoreseq.c +parsers/indirect.c +parsers/int_range.c +parsers/many.c +parsers/not.c +parsers/nothing.c +parsers/optional.c +parsers/permutation.c +parsers/sequence.c +parsers/token.c +parsers/unimplemented.c +parsers/whitespace.c +parsers/xor.c +parsers/value.c +backends/packrat.c +backends/llk.c +backends/regex.c +backends/glr.c +backends/lalr.c +backends/lr.c +backends/lr0.c diff --git a/tools/windows/status.bat b/tools/windows/status.bat new file mode 100644 index 00000000..4f8bd11f --- /dev/null +++ b/tools/windows/status.bat @@ -0,0 +1 @@ +git grep "FIXME(windows)" -- GitLab