Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows support for Travis CI #784

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bazel-bin/cmd/jsonnetfmt

### Cmake

Linux/OSX:

```
cmake . -Bbuild
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test_suite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 12 additions & 0 deletions travis/build-windows.bat
Original file line number Diff line number Diff line change
@@ -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%