From 50015e91b6c48025a19dc3fcde9e4692efc8ec09 Mon Sep 17 00:00:00 2001 From: mckunda Date: Tue, 17 Mar 2020 07:07:56 +0300 Subject: [PATCH 1/4] Add Windows Cmake target using clang compiler --- CMakeLists.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 385ea829c..806bfdf00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,17 +33,23 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) # Compiler flags. -if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR +if ((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + AND + (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux" + OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")) set(OPT "-O3") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -std=c99 -O3 ${OPT}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -std=c99 ${OPT}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++11 -fPIC ${OPT}") + set(CMAKE_CXX_STANDARD 11) +elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows" AND ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -std=c99 ${OPT}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -std=c++14 ${OPT}") + set(CMAKE_CXX_STANDARD 14) else() - # TODO: Windows support. message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported") endif() -set(CMAKE_CXX_STANDARD 11) # Include external googletest project. This runs a CMake sub-script From 29b8c218208de90d884900f7f75ebd7b2cacee8b Mon Sep 17 00:00:00 2001 From: mckunda Date: Tue, 17 Mar 2020 07:09:19 +0300 Subject: [PATCH 2/4] Fix CMakeLists to support Windows builds --- stdlib/CMakeLists.txt | 5 +++-- test_suite/CMakeLists.txt | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt index a481d9fa4..c02279569 100644 --- a/stdlib/CMakeLists.txt +++ b/stdlib/CMakeLists.txt @@ -5,10 +5,11 @@ add_executable(to_c_array to_c_array.cpp) # Custom command that will only build stdlib when it changes. add_custom_command( OUTPUT ${PROJECT_SOURCE_DIR}/core/std.jsonnet.h - COMMAND ${GLOBAL_OUTPUT_PATH}/to_c_array + COMMAND to_c_array ${PROJECT_SOURCE_DIR}/stdlib/std.jsonnet ${PROJECT_SOURCE_DIR}/core/std.jsonnet.h - DEPENDS to_c_array std.jsonnet) + DEPENDS to_c_array std.jsonnet + WORKING_DIRECTORY ${GLOBAL_OUTPUT_PATH}) # Standard library build target that libjsonnet can depend on. add_custom_target(stdlib ALL diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index fbc90320e..a028eda24 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -1,6 +1,8 @@ find_program(BASH bash) if (BASH STREQUAL "BASH-NOTFOUND") message(WARNING "Bash not found, can't run regression tests.") +elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows") + message(WARNING "Regression tests for Windows are not supported.") else() # Note: this test relies on the JSONNET_BIN variable, which # is set in the root CMakeLists.txt. From fbee5d3060340c92492544c93ec96c90c099e806 Mon Sep 17 00:00:00 2001 From: mckunda Date: Tue, 17 Mar 2020 07:41:40 +0300 Subject: [PATCH 3/4] Update Travis CI scripts to support Windows --- .travis.yml | 17 ++++++++++++----- travis/build-windows.bat | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 travis/build-windows.bat diff --git a/.travis.yml b/.travis.yml index 7efe09fdd..ab5978daf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: - g++-4.9 sources: &sources - llvm-toolchain-precise-3.8 - - ubuntu-toolchain-r-test + - ubuntu-toolchain-r-test - os: linux env: COMPILER_NAME=clang CXX=clang++-3.8 CC=clang-3.8 COMMON_OS_NAME=${TRAVIS_OS_NAME} addons: @@ -24,6 +24,11 @@ matrix: - os: osx osx_image: xcode11.3 env: CC=clang && CXX=clang++ COMMON_OS_NAME=darwin + - os: windows + language: cpp + env: CC=clang CXX=clang++ COMMON_OS_NAME=${TRAVIS_OS_NAME} GENERATOR="Unix Makefiles" + install: choco install make -y + script: ./travis/build-windows.bat before_install: - echo $LANG @@ -40,24 +45,26 @@ script: - cmake . -Bbuild && cmake --build build --target run_tests # make a tarfile for the binaries and rename for os and tag - make dist - - mv jsonnet-bin.tar.gz jsonnet-bin-${TRAVIS_TAG}-${COMMON_OS_NAME}.tar.gz + - mkdir upload + - mv jsonnet-bin.tar.gz upload/jsonnet-bin-${TRAVIS_TAG}-${COMMON_OS_NAME}.tar.gz deploy: provider: releases api_key: $JSONNET_GITHUB_TOKEN - file: jsonnet-bin-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz + file_glob: true + file: upload/* skip_cleanup: true on: tags: true # no point deploying the images built with both compilers - condition: $CC =~ gcc + condition: $CC =~ gcc && $COMMON_OS_NAME =~ ^(linux|darwin)$ branches: only: - master # the branch name is the tag name, so having only master means you can't # trigger a build by just push a tag - so add in a regex to match tags that - # should trigger. + # should trigger. - /^v.*$/ notifications: diff --git a/travis/build-windows.bat b/travis/build-windows.bat new file mode 100644 index 000000000..8259fb0a5 --- /dev/null +++ b/travis/build-windows.bat @@ -0,0 +1,12 @@ +call RefreshEnv.cmd +cmake . -B build -DCMAKE_C_COMPILER="%CC%" -DCMAKE_CXX_COMPILER="%CXX%" -G "%GENERATOR%" +if %errorlevel% NEQ 0 exit /b %errorlevel% +cmake --build build --target jsonnetfmt +if %errorlevel% NEQ 0 exit /b %errorlevel% +cmake --build build --target jsonnet +if %errorlevel% NEQ 0 exit /b %errorlevel% +cmake --build build --target run_tests +if %errorlevel% NEQ 0 exit /b %errorlevel% +mkdir upload +7z -tzip a .\upload\jsonnet-bin-"%TRAVIS_TAG%"-"%COMMON_OS_NAME%".zip .\build\jsonnet*.exe +if %errorlevel% NEQ 0 exit /b %errorlevel% \ No newline at end of file From 8989df91fd9896b47413d789c4c114b2862b524d Mon Sep 17 00:00:00 2001 From: mckunda Date: Tue, 17 Mar 2020 07:52:26 +0300 Subject: [PATCH 4/4] Update `README.md` with build instrctions for Windows using CMake --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index d425483c9..4b27564de 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ bazel-bin/cmd/jsonnetfmt ### Cmake +Linux/OSX: ``` cmake . -Bbuild @@ -108,6 +109,43 @@ cmake . -Bbuild cmake --build build --target run_tests ``` +Windows: + +In order to build under Windows using cmake, you need to install: + +- chocolatey +- llvm + +Only `Unix Makefiles` generator is currently supported, so we also need `make`: + +``` +choco install make +``` + +Finally, we can build Jsonnet: + +``` +cmake . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -G "Unix MakeFiles" +``` + +`jsonnet.exe`: + +``` +cmake --build build --target jsonnet +``` + +`jsonnetfmt.exe`: + +``` +cmake --build build --target jsonnetfmt +``` + +Tests: + +``` +cmake --build build --target run_tests +``` + ## Contributing See the [contributing page](http://jsonnet.org/contributing.html) on our website.